From 9e782ba01620997becc3118433e3d1961a88b2c3 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Wed, 18 Aug 2021 00:26:02 -0300 Subject: rudimentary theme switching --- main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index 6502cda..dd73510 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( "net/url" "os" "os/exec" + "path" "regexp" "strconv" "strings" @@ -51,6 +52,8 @@ var MediaHashs = make(map[string]string) var ActorCache = make(map[string]Actor) +var Themes []string + func main() { CreatedNeededDirectories() @@ -84,6 +87,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))) -- cgit v1.2.3 From 727b5701327a7e1c5f826f496b8e99c2004e471a Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Wed, 18 Aug 2021 17:34:12 -0300 Subject: experimental type change for times: string to time.Time idk what i was doing before this but i wanted to use time.Time to get something similar to how 4chan's timestamps work, it would've also been easier for scripts to interface with it, since we have data we can work with much easier than a string i am not sure what this means for federation yet, so i'll test it out before i do anything. --- main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index dd73510..6c3e9b7 100644 --- a/main.go +++ b/main.go @@ -1640,8 +1640,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 } @@ -1780,7 +1780,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) @@ -1812,7 +1812,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) } } @@ -2397,7 +2397,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) -- cgit v1.2.3 From 6f8744c1ad53b4056dc6245f8ac6b5fb903aef8f Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Thu, 19 Aug 2021 11:45:16 -0300 Subject: data-utc --- main.go | 1 + 1 file changed, 1 insertion(+) (limited to 'main.go') diff --git a/main.go b/main.go index 6c3e9b7..131211e 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,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"} -- cgit v1.2.3 From afa9e221d07ac0e246daadef33e911bc86fd74eb Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Thu, 19 Aug 2021 12:07:41 -0300 Subject: hack fix mod pages --- main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 131211e..9c7f429 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ import ( "strconv" "strings" "time" + "log" ) var Port = ":" + GetConfigValue("instanceport", "3000") @@ -630,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{ @@ -665,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) + } } }) -- cgit v1.2.3 From 149b885f10011c0cb9fd49bc162165d4ecff4331 Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Thu, 19 Aug 2021 13:19:11 -0300 Subject: go fmt, go vet --- main.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 9c7f429..abce30d 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "html/template" "io" "io/ioutil" + "log" "math/rand" "mime/multipart" "net/http" @@ -24,7 +25,6 @@ import ( "strconv" "strings" "time" - "log" ) var Port = ":" + GetConfigValue("instanceport", "3000") @@ -631,7 +631,7 @@ func main() { adminData.AutoSubscribe = GetActorAutoSubscribeDB(db, actor.Id) - adminData.Themes = &Themes; + adminData.Themes = &Themes err := t.ExecuteTemplate(w, "layout", adminData) if err != nil { @@ -993,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) { @@ -1067,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) { @@ -1124,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) { @@ -1181,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) { @@ -1228,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) { -- cgit v1.2.3