diff options
author | FChannel0 <77419041+FChannel0@users.noreply.github.com> | 2021-08-20 01:35:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-20 01:35:26 -0700 |
commit | 502558e0bdaf67ca4c012fc1983f42430b8854cd (patch) | |
tree | d66b015274b962fedb28c52c0efaaa068368f2b1 /main.go | |
parent | 21917eb2ea72fe40d70c2c991e821aace5430c23 (diff) | |
parent | a497499817cbf72b295253e1a2bb1011d121ba28 (diff) |
Merge pull request #52 from KushBlazingJudah/development
Themes
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 62 |
1 files changed, 40 insertions, 22 deletions
@@ -13,12 +13,14 @@ import ( "html/template" "io" "io/ioutil" + "log" "math/rand" "mime/multipart" "net/http" "net/url" "os" "os/exec" + "path" "regexp" "strconv" "strings" @@ -29,6 +31,7 @@ var Port = ":" + GetConfigValue("instanceport", "3000") var TP = GetConfigValue("instancetp", "") var Instance = GetConfigValue("instance", "") var Domain = TP + "" + Instance +var TorInstance = IsOnion(Instance) var authReq = []string{"captcha", "email", "passphrase"} @@ -51,6 +54,8 @@ var MediaHashs = make(map[string]string) var ActorCache = make(map[string]Actor) +var Themes []string + func main() { CreatedNeededDirectories() @@ -84,6 +89,22 @@ func main() { } } + // get list of themes + themes, err := ioutil.ReadDir("./static/css/themes") + if err != nil { + panic(err) + } + + for _, f := range themes { + if f.Name() == "default" { + continue + } + + if e := path.Ext(f.Name()); e == ".css" { + Themes = append(Themes, strings.TrimSuffix(f.Name(), e)) + } + } + // Allow access to public media folder fileServer := http.FileServer(http.Dir("./public")) http.Handle("/public/", http.StripPrefix("/public", neuter(fileServer))) @@ -610,7 +631,13 @@ func main() { adminData.AutoSubscribe = GetActorAutoSubscribeDB(db, actor.Id) - t.ExecuteTemplate(w, "layout", adminData) + adminData.Themes = &Themes + + err := t.ExecuteTemplate(w, "layout", adminData) + if err != nil { + // TODO: actual error handling + log.Printf("mod page: %s\n", err) + } } else if admin || actor.Id == Domain { t := template.Must(template.New("").Funcs(template.FuncMap{ @@ -645,7 +672,13 @@ func main() { adminData.PostBlacklist = GetRegexBlacklistDB(db) - t.ExecuteTemplate(w, "layout", adminData) + adminData.Themes = &Themes + + err := t.ExecuteTemplate(w, "layout", adminData) + if err != nil { + // TODO: actual error handling + log.Printf("mod page: %s\n", err) + } } }) @@ -960,9 +993,6 @@ func main() { http.Redirect(w, r, "/"+board, http.StatusSeeOther) return } - - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("")) }) http.HandleFunc("/deleteattach", func(w http.ResponseWriter, r *http.Request) { @@ -1034,9 +1064,6 @@ func main() { http.Redirect(w, r, OP, http.StatusSeeOther) return } - - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("")) }) http.HandleFunc("/marksensitive", func(w http.ResponseWriter, r *http.Request) { @@ -1091,9 +1118,6 @@ func main() { http.Redirect(w, r, OP, http.StatusSeeOther) return } - - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("")) }) http.HandleFunc("/remove", func(w http.ResponseWriter, r *http.Request) { @@ -1148,9 +1172,6 @@ func main() { http.Redirect(w, r, "/"+board, http.StatusSeeOther) return } - - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("")) }) http.HandleFunc("/removeattach", func(w http.ResponseWriter, r *http.Request) { @@ -1195,9 +1216,6 @@ func main() { http.Redirect(w, r, OP, http.StatusSeeOther) return } - - w.WriteHeader(http.StatusBadRequest) - w.Write([]byte("")) }) http.HandleFunc("/report", func(w http.ResponseWriter, r *http.Request) { @@ -1621,8 +1639,8 @@ func CreateObject(objType string) ObjectBase { var nObj ObjectBase nObj.Type = objType - nObj.Published = time.Now().UTC().Format(time.RFC3339) - nObj.Updated = time.Now().UTC().Format(time.RFC3339) + nObj.Published = time.Now().UTC() + nObj.Updated = time.Now().UTC() return nObj } @@ -1761,7 +1779,7 @@ func CreateAttachmentObject(file multipart.File, header *multipart.FileHeader) ( image.Href = Domain + "/" + tempFile.Name() image.MediaType = contentType image.Size = size - image.Published = time.Now().UTC().Format(time.RFC3339) + image.Published = time.Now().UTC() nAttachment = append(nAttachment, image) @@ -1793,7 +1811,7 @@ func ParseCommentForReplies(db *sql.DB, comment string, op string) []ObjectBase if isValid { var reply = new(ObjectBase) reply.Id = links[i] - reply.Published = time.Now().UTC().Format(time.RFC3339) + reply.Published = time.Now().UTC() validLinks = append(validLinks, *reply) } } @@ -2378,7 +2396,7 @@ func ResizeAttachmentToPreview(db *sql.DB) { var mediatype string var name string var size int - var published string + var published time.Time rows.Scan(&id, &href, &mediatype, &name, &size, &published) |