diff --git a/app/router.go b/app/router.go
index d98e2a9..4da2f7d 100644
--- a/app/router.go
+++ b/app/router.go
@@ -13,22 +13,34 @@ const addr string = "0.0.0.0:3003"
// роутер
func Router() {
- // расшифровка эндпоинта из урл
- endpoint := func(url string) (string, string) {
- if CFG.Base_uri != "" {
- url = strings.Replace(url, CFG.Base_uri, "/", 1)
+ parsepath := func(path string) map[int]string {
+ parsedpath := make(map[int]string)
+ for x := 0; true; x++ {
+ slash := strings.Index(path, "/") + 1
+ content := path[:slash]
+ path = path[slash:]
+ if slash == 0 {
+ parsedpath[x] = path
+ break
+ }
+ parsedpath[x] = content[:slash-1]
}
+ return parsedpath
+ }
- end := strings.Index(url[1:], "/")
- if end == -1 {
- return url[1:], ""
+ next := func(path map[int]string, from int) (out string) {
+ for x, l := from, len(path)-1; x <= l; x++ {
+ out += path[x]
+ if x != l {
+ out += "/"
+ }
}
- return url[1 : end+1], url[end+2:]
+ return
}
// функция, что управляет всем
handle := func(w http.ResponseWriter, r *http.Request) {
- e, url := endpoint(r.URL.Path)
+ path := parsepath(r.URL.Path)
var wr = io.WriteString
open_n_send := func(name string) {
f, e := os.ReadFile(name)
@@ -50,14 +62,13 @@ func Router() {
skunky.Page = p
// пути
- switch e {
+ switch path[1] {
default:
skunky.ReturnHTTPError(404)
- case "/", "":
+ case "":
open_n_send("html/index.htm")
case "post":
- slash := strings.Index(url, "/")
- skunky.Deviation(url[:slash], url[slash+1:])
+ skunky.Deviation(path[2], path[3])
case "search":
skunky.Search()
case "dd":
@@ -66,12 +77,12 @@ func Router() {
skunky.GRUser()
case "media":
- skunky.Emojitar(url)
+ skunky.Emojitar(path[2])
case "about":
open_n_send("html/about.htm")
case "gui":
w.Header().Add("content-type", "text/css")
- open_n_send(url)
+ open_n_send(next(path, 2))
}
}
diff --git a/app/util.go b/app/util.go
index e4a1de2..cda0ffc 100644
--- a/app/util.go
+++ b/app/util.go
@@ -19,6 +19,15 @@ func (s skunkyart) ExecuteTemplate(file string, data any) {
wr(s.Writer, buf.String())
}
+func (s skunkyart) UrlBuilder(strs ...string) string {
+ var str strings.Builder
+ for _, x := range strs {
+ str.WriteString(x)
+ str.WriteString("/")
+ }
+ return str.String()
+}
+
func (s skunkyart) ReturnHTTPError(status int) {
s.Writer.WriteHeader(status)
@@ -142,6 +151,10 @@ func (s skunkyart) NavBase(c dlist) string {
list.WriteString("&q=")
list.WriteString(s.Query)
}
+ if f := s.Args.Get("folder"); f != "" {
+ list.WriteString("&folder=")
+ list.WriteString(f)
+ }
list.WriteString(`">`)
list.WriteString(msg)
list.WriteString(" ")
diff --git a/app/wraper.go b/app/wraper.go
index 2b733fd..f3f025d 100644
--- a/app/wraper.go
+++ b/app/wraper.go
@@ -1,7 +1,6 @@
package app
import (
- "fmt"
"io"
"net/http"
"net/url"
@@ -24,6 +23,8 @@ type skunkyart struct {
Templates struct {
GroupUser struct {
GR devianter.GRuser
+ Admins string
+ Group bool
CreationDate string
About struct {
@@ -37,8 +38,9 @@ type skunkyart struct {
}
Gallery struct {
- Pages int
- List string
+ Folders string
+ Pages int
+ List string
}
}
Search struct {
@@ -61,19 +63,22 @@ func (s skunkyart) GRUser() {
switch s.Type {
case 'a':
- if g := group.GR; !g.Owner.Group {
- for _, x := range g.Gruser.Page.Modules {
- switch x.Name {
- case "about":
- group.About.A = x.ModuleData.About
- var about = group.About.A
+ g := group.GR
+ for _, x := range g.Gruser.Page.Modules {
+ switch x.Name {
+ case "about", "group_about":
+ switch g.Owner.Group {
+ case true:
+ var about = &x.ModuleData.GroupAbout
+ group.Group = true
+ group.CreationDate = x.ModuleData.GroupAbout.FoundatedAt.UTC().String()
+ group.About.DescriptionFormatted = ParseDescription(about.Description)
+ case false:
+ group.About.A = x.ModuleData.About
+ var about = &group.About.A
+ group.CreationDate = time.Unix(time.Now().Unix()-x.ModuleData.About.RegDate, 0).UTC().String()
+
group.About.DescriptionFormatted = ParseDescription(about.Description)
- group.About.Comments = s.ParseComments(devianter.CommentsFunc(
- strconv.Itoa(group.GR.Gruser.ID),
- "",
- s.Page,
- 4,
- ))
for _, val := range x.ModuleData.About.SocialLinks {
var social strings.Builder
@@ -93,25 +98,76 @@ func (s skunkyart) GRUser() {
interest.WriteString("
")
group.About.Interests += interest.String()
}
-
- if rd := x.ModuleData.About.RegDate; rd != 0 {
- group.CreationDate = time.Unix(time.Now().Unix()-rd, 0).UTC().String()
- }
- case "cover_deviation":
- group.About.BGMeta = x.ModuleData.CoverDeviation.Deviation
- group.About.BG = devianter.UrlFromMedia(group.About.BGMeta.Media)
}
+ group.About.Comments = s.ParseComments(devianter.CommentsFunc(
+ strconv.Itoa(group.GR.Gruser.ID),
+ "",
+ s.Page,
+ 4,
+ ))
+
+ case "cover_deviation":
+ group.About.BGMeta = x.ModuleData.CoverDeviation.Deviation
+ group.About.BG = devianter.UrlFromMedia(group.About.BGMeta.Media)
+ case "group_admins":
+ var htm strings.Builder
+ for _, z := range x.ModuleData.GroupAdmins.Results {
+ htm.WriteString(`
`)
+ htm.WriteString(z.User.Username)
+ htm.WriteString(`
Watchers: {{.Templates.GroupUser.GR.Extra.Stats.Watchers}}; Pageviews: {{.Templates.GroupUser.GR.Extra.Stats.Pageviews}} + {{else}}
Favourites: {{.Templates.GroupUser.GR.Extra.Stats.Favourites}}; Deviations: {{.Templates.GroupUser.GR.Extra.Stats.Deviations}}; Watchers: {{.Templates.GroupUser.GR.Extra.Stats.Watchers}}
Watching: {{.Templates.GroupUser.GR.Extra.Stats.Watching}}; Pageviews: {{.Templates.GroupUser.GR.Extra.Stats.Pageviews}}; Comments Made: {{.Templates.GroupUser.GR.Extra.Stats.CommentsMade}}; Friends: {{.Templates.GroupUser.GR.Extra.Stats.Friends}}
- + {{end}} + + {{if ne .Templates.GroupUser.Admins ""}} +