From 638a03b458b71564b1db439e6386d7dbf2a5181c Mon Sep 17 00:00:00 2001 From: knotteye Date: Thu, 1 Jul 2021 14:39:44 -0500 Subject: linkify text and use imageboard name to identify it --- client.go | 5 ++--- static/index.html | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index 49c7d0c..dd40f3d 100644 --- a/client.go +++ b/client.go @@ -1,6 +1,5 @@ package main -import "fmt" import "net/http" import "html/template" import "database/sql" @@ -36,7 +35,7 @@ type Board struct{ type PageData struct { Title string - Message string + PreferredUsername string Board Board Pages []int CurrentPage int @@ -81,7 +80,7 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { var data PageData data.Title = "Welcome to " + actor.PreferredUsername - data.Message = fmt.Sprintf("%s is a federated image board based on activitypub. The current version of the code running the server is still a work in progress, expect a bumpy ride for the time being. Get the server code here https://github.com/FChannel0", Domain) + data.PreferredUsername = actor.PreferredUsername data.Boards = Boards data.Board.Name = "" data.Key = *Key diff --git a/static/index.html b/static/index.html index 502e527..19c5da2 100644 --- a/static/index.html +++ b/static/index.html @@ -1,6 +1,6 @@ {{ define "header" }} {{ .Title }} - + @@ -8,10 +8,10 @@ - + - + {{ end }} @@ -20,7 +20,7 @@ {{ define "content" }}

{{ .Title }}

-

{{.Message}}

+

{{ .PreferredUsername }} is a federated image board based on activitypub. The current version of the code running the server is still a work in progress, expect a bumpy ride for the time being. Get the server code here.

@@ -30,7 +30,7 @@ {{ range .InstanceIndex }} - + {{ end }}
{{ .Id }}{{ .Id }}
-- cgit v1.2.3 From 4e3848cadbb3fd89b94a7ef24838173939d198db Mon Sep 17 00:00:00 2001 From: knotteye Date: Thu, 1 Jul 2021 17:56:04 -0500 Subject: Add a list of local boards and server news --- client.go | 13 +++++++++++-- database.go | 42 ++++++++++++++++++++++++++++++++++++++++-- databaseschema.psql | 8 +++++++- main.go | 11 +++++++++++ static/index.html | 28 ++++++++++++++++++++++++++++ static/nadmin.html | 8 ++++++++ 6 files changed, 105 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index dd40f3d..fcb496b 100644 --- a/client.go +++ b/client.go @@ -47,6 +47,7 @@ type PageData struct { Instance Actor InstanceIndex []ObjectBase ReturnTo string + NewsItems []NewsItem } type AdminPage struct { @@ -73,8 +74,15 @@ type Removed struct { Board string } + +type NewsItem struct { + Title string + Content string + Time int +} + func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { - t := template.Must(template.ParseFiles("./static/main.html", "./static/index.html")) + t := template.Must(template.New("").Funcs(template.FuncMap{"mod": func(i, j int) bool { return i%j == 0 }}).ParseFiles("./static/main.html", "./static/index.html")) actor := GetActorFromDB(db, Domain) @@ -90,8 +98,9 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { data.Board.Post.Actor = actor.Id data.Board.Restricted = actor.Restricted data.InstanceIndex = GetCollectionFromReq("https://fchan.xyz/followers").Items + data.NewsItems = getNewsFromDB(db) - t.ExecuteTemplate(w, "layout", data) + t.ExecuteTemplate(w, "layout", data) } func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Collection){ diff --git a/database.go b/database.go index 9d5d721..5fcebf0 100644 --- a/database.go +++ b/database.go @@ -7,11 +7,12 @@ import "time" import "os" import "strings" import "sort" +import "container/list" func GetActorFromDB(db *sql.DB, id string) Actor { - var nActor Actor + var nActor Actor - query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where id=$1` + query :=`select type, id, name, preferedusername, inbox, outbox, following, followers, restricted, summary, publickeypem from actor where id=$1` rows, err := db.Query(query, id) @@ -1488,3 +1489,40 @@ func MarkObjectSensitive(db *sql.DB, id string, sensitive bool) { CheckError(err, "error updating sensitive object in cacheactivitystream") } + +func getNewsFromDB(db *sql.DB) []NewsItem { + news := list.New() + query :=`select title, content, time from newsItem order by time desc` + + rows, err := db.Query(query) + + if CheckError(err, "could not get news from db query") != nil { + return make([]NewsItem, 0) + } + + defer rows.Close() + for rows.Next() { + n := NewsItem{} + err = rows.Scan(&n.Title, &n.Content, &n.Time) + news.PushBack(n) + } + + anews := make([]NewsItem, news.Len()) + + i:=0 + for e := news.Front(); e != nil; e = e.Next() { + assert := e.Value.(NewsItem) + anews[i] = assert + i++ + } + + return anews +} + +func WriteNewsToDB(db *sql.DB, news NewsItem) { + query := `insert into newsItem (title, content, time) values ($1, $2, $3)` + + _, err := db.Exec(query, news.Title, news.Content, time.Now().Unix()) + + CheckError(err, "error writing news item") +} diff --git a/databaseschema.psql b/databaseschema.psql index e12813e..43767f3 100644 --- a/databaseschema.psql +++ b/databaseschema.psql @@ -216,7 +216,13 @@ owner varchar(100), file varchar(100) ); +CREATE TABLE IF NOT EXISTS newsItem( +title text, +content text, +time bigint +); + ALTER TABLE actor ADD COLUMN IF NOT EXISTS publicKeyPem varchar(100) default ''; ALTER TABLE activitystream ADD COLUMN IF NOT EXISTS sensitive boolean default false; -ALTER TABLE cacheactivitystream ADD COLUMN IF NOT EXISTS sensitive boolean default false; \ No newline at end of file +ALTER TABLE cacheactivitystream ADD COLUMN IF NOT EXISTS sensitive boolean default false; diff --git a/main.go b/main.go index 972e69e..037f240 100644 --- a/main.go +++ b/main.go @@ -598,6 +598,17 @@ func main() { MakeActivityRequestOutbox(db, newActorActivity) http.Redirect(w, r, "/" + *Key, http.StatusSeeOther) }) + + http.HandleFunc("/" + *Key + "/postnews", func(w http.ResponseWriter, r *http.Request) { + var newsitem NewsItem + + newsitem.Title = r.FormValue("title") + newsitem.Content = r.FormValue("summary") + + WriteNewsToDB(db, newsitem) + + http.Redirect(w, r, "/", http.StatusSeeOther) + }) http.HandleFunc("/verify", func(w http.ResponseWriter, r *http.Request){ if(r.Method == "POST") { diff --git a/static/index.html b/static/index.html index 19c5da2..de06c6c 100644 --- a/static/index.html +++ b/static/index.html @@ -22,6 +22,34 @@

{{ .Title }}

{{ .PreferredUsername }} is a federated image board based on activitypub. The current version of the code running the server is still a work in progress, expect a bumpy ride for the time being. Get the server code here.

+
+ + Local boards + + + {{ range .Boards }} + + + + {{ end }} +
+
{{.Name}} - {{.PrefName}}
+
+ +
+ + {{ .PreferredUsername }} news + + + {{ range .NewsItems }} + + + + {{ end }} +
+

{{.Time}} - {{.Title}}
{{.Content}}

+
+
- + {{ end }}
diff --git a/static/nadmin.html b/static/nadmin.html index 984eb76..877e1e5 100644 --- a/static/nadmin.html +++ b/static/nadmin.html @@ -17,6 +17,14 @@ + +

Post News

+
+
+
+
+
+
  • Subscribed
  • -- cgit v1.2.3 From 168225daa21fe494bcd74ab6c90d6498ecf9f1e3 Mon Sep 17 00:00:00 2001 From: knotteye Date: Thu, 1 Jul 2021 20:26:49 -0500 Subject: Make news list links to full page news articles --- client.go | 34 +++++++++++++++++++++++++++++++++- database.go | 24 ++++++++++++++++++++++++ main.go | 15 +++++++++++++++ static/index.html | 2 +- static/news.html | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 static/news.html diff --git a/client.go b/client.go index fcb496b..38f0d6f 100644 --- a/client.go +++ b/client.go @@ -8,6 +8,7 @@ import "strings" import "strconv" import "sort" import "regexp" +import "time" var Key *string = new(string) @@ -82,7 +83,7 @@ type NewsItem struct { } func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { - t := template.Must(template.New("").Funcs(template.FuncMap{"mod": func(i, j int) bool { return i%j == 0 }}).ParseFiles("./static/main.html", "./static/index.html")) + t := template.Must(template.New("").Funcs(template.FuncMap{"mod": func(i, j int) bool { return i%j == 0 }, "unixtoreadable": func(u int) string { return time.Unix(int64(u), 0).Format("Jan 02, 2006") }}).ParseFiles("./static/main.html", "./static/index.html")) actor := GetActorFromDB(db, Domain) @@ -103,6 +104,37 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { t.ExecuteTemplate(w, "layout", data) } +func NewsGet(w http.ResponseWriter, r *http.Request, db *sql.DB, timestamp int) { + t := template.Must(template.New("").Funcs(template.FuncMap{"unixtoreadable": func(u int) string { return time.Unix(int64(u), 0).Format("Jan 02, 2006") }}).ParseFiles("./static/main.html", "./static/news.html")) + + actor := GetActorFromDB(db, Domain) + + var data PageData + data.PreferredUsername = actor.PreferredUsername + data.Boards = Boards + data.Board.Name = "" + data.Key = *Key + data.Board.Domain = Domain + data.Board.ModCred, _ = GetPasswordFromSession(r) + data.Board.Actor = actor + data.Board.Post.Actor = actor.Id + data.Board.Restricted = actor.Restricted + data.NewsItems = []NewsItem{NewsItem{}} + + var err error + data.NewsItems[0], err = getNewsItemFromDB(db, timestamp) + + if err != nil { + w.WriteHeader(http.StatusForbidden) + w.Write([]byte("404 no path")) + return + } + + data.Title = actor.PreferredUsername + ": " + data.NewsItems[0].Title + + t.ExecuteTemplate(w, "layout", data) +} + func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Collection){ t := template.Must(template.ParseFiles("./static/main.html", "./static/nposts.html", "./static/top.html", "./static/bottom.html", "./static/posts.html")) diff --git a/database.go b/database.go index 5fcebf0..037fde2 100644 --- a/database.go +++ b/database.go @@ -1504,6 +1504,9 @@ func getNewsFromDB(db *sql.DB) []NewsItem { for rows.Next() { n := NewsItem{} err = rows.Scan(&n.Title, &n.Content, &n.Time) + if CheckError(err, "error scanning news from db") != nil { + return make([]NewsItem, 0) + } news.PushBack(n) } @@ -1519,6 +1522,27 @@ func getNewsFromDB(db *sql.DB) []NewsItem { return anews } +func getNewsItemFromDB(db *sql.DB, timestamp int) (NewsItem, error) { + var news NewsItem + query := `select title, content, time from newsItem where time=$1 limit 1` + + rows, err := db.Query(query, timestamp) + + if err != nil { + return news, err + } + + defer rows.Close() + rows.Next() + err = rows.Scan(&news.Title, &news.Content, &news.Time) + + if err != nil { + return news, err + } + + return news, nil +} + func WriteNewsToDB(db *sql.DB, news NewsItem) { query := `insert into newsItem (title, content, time) values ($1, $2, $3)` diff --git a/main.go b/main.go index 037f240..4f7f3e8 100644 --- a/main.go +++ b/main.go @@ -286,6 +286,21 @@ func main() { w.WriteHeader(http.StatusForbidden) w.Write([]byte("404 no path")) }) + + http.HandleFunc("/news/", func(w http.ResponseWriter, r *http.Request){ + timestamp := r.URL.Path[6:] + if timestamp[len(timestamp)-1:] == "/" { + timestamp = timestamp[:len(timestamp)-1] + } + + ts, err := strconv.Atoi(timestamp) + if err != nil { + w.WriteHeader(http.StatusForbidden) + w.Write([]byte("404 no path")) + } else { + NewsGet(w, r, db, ts) + } + }) http.HandleFunc("/post", func(w http.ResponseWriter, r *http.Request){ diff --git a/static/index.html b/static/index.html index de06c6c..05197c0 100644 --- a/static/index.html +++ b/static/index.html @@ -44,7 +44,7 @@ {{ range .NewsItems }}

{{.Time}} - {{.Title}}
{{.Content}}

{{unixtoreadable .Time}} - {{.Title}}
diff --git a/static/news.html b/static/news.html new file mode 100644 index 0000000..757c420 --- /dev/null +++ b/static/news.html @@ -0,0 +1,32 @@ +{{ define "header" }} +{{ .Title }} + + + + + + + + + + + + + + +{{ end }} + +{{ define "top" }}{{ end }} +{{ define "content" }} +
+ + {{ range .NewsItems }} +

{{unixtoreadable .Time}} - {{.Title}}


{{.Content}}

+ {{ end }} + +
+{{ end }} +{{ define "bottom" }}{{ end }} + +{{ define "script" }} +{{ end }} -- cgit v1.2.3 From d98441da108725a76d697e358d161c06783cb066 Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 2 Jul 2021 07:43:54 -0500 Subject: Display most recents news item and create a table for boards --- client.go | 2 ++ static/index.html | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index 38f0d6f..074b645 100644 --- a/client.go +++ b/client.go @@ -49,6 +49,7 @@ type PageData struct { InstanceIndex []ObjectBase ReturnTo string NewsItems []NewsItem + BoardRemainer []int } type AdminPage struct { @@ -98,6 +99,7 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { data.Board.Actor = actor data.Board.Post.Actor = actor.Id data.Board.Restricted = actor.Restricted + data.BoardRemainer = make([]int, (len(data.Boards) % 3)+1) data.InstanceIndex = GetCollectionFromReq("https://fchan.xyz/followers").Items data.NewsItems = getNewsFromDB(db) diff --git a/static/index.html b/static/index.html index 05197c0..518c012 100644 --- a/static/index.html +++ b/static/index.html @@ -23,17 +23,17 @@

{{ .PreferredUsername }} is a federated image board based on activitypub. The current version of the code running the server is still a work in progress, expect a bumpy ride for the time being. Get the server code here.

- - Local boards - +
+
Local boards
{{ range .Boards }} -
- - + {{ end }} -
-
{{.Name}} - {{.PrefName}}
+ {{ range .BoardRemainer }} +
+ {{ end }} +
+
@@ -42,9 +42,13 @@ {{ .PreferredUsername }} news - {{ range .NewsItems }} + {{ range $i, $e := .NewsItems }} - {{unixtoreadable .Time}} - {{.Title}} + {{unixtoreadable $e.Time}} - {{$e.Title}} + {{ if eq $i 0 }} +

{{$e.Content}}

+ {{ end }} + {{ end }} -- cgit v1.2.3 From ad5f4e9ff7e7ab0abab4a964cbf1626d0cdc3365 Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 2 Jul 2021 13:56:38 -0500 Subject: select a specific number of news items from the database --- database.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/database.go b/database.go index 037fde2..7dc7f5c 100644 --- a/database.go +++ b/database.go @@ -7,7 +7,6 @@ import "time" import "os" import "strings" import "sort" -import "container/list" func GetActorFromDB(db *sql.DB, id string) Actor { var nActor Actor @@ -1490,14 +1489,20 @@ func MarkObjectSensitive(db *sql.DB, id string, sensitive bool) { CheckError(err, "error updating sensitive object in cacheactivitystream") } -func getNewsFromDB(db *sql.DB) []NewsItem { - news := list.New() - query :=`select title, content, time from newsItem order by time desc` +//if limit less than 1 return all news items +func getNewsFromDB(db *sql.DB, limit int) []NewsItem { + news := []NewsItem + + if(limit > 0) { + query :=`select title, content, time from newsItem order by time desc limit $1` + } else { + query :=`select title, content, time from newsItem order by time desc` + } - rows, err := db.Query(query) + rows, err := db.Query(query, limit) if CheckError(err, "could not get news from db query") != nil { - return make([]NewsItem, 0) + return news } defer rows.Close() @@ -1505,21 +1510,12 @@ func getNewsFromDB(db *sql.DB) []NewsItem { n := NewsItem{} err = rows.Scan(&n.Title, &n.Content, &n.Time) if CheckError(err, "error scanning news from db") != nil { - return make([]NewsItem, 0) + return news } - news.PushBack(n) + append(news, n) } - anews := make([]NewsItem, news.Len()) - - i:=0 - for e := news.Front(); e != nil; e = e.Next() { - assert := e.Value.(NewsItem) - anews[i] = assert - i++ - } - - return anews + return news } func getNewsItemFromDB(db *sql.DB, timestamp int) (NewsItem, error) { -- cgit v1.2.3 From faae38726dd804e3246514d88f93794c23a0cdb2 Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 2 Jul 2021 14:20:16 -0500 Subject: show only the last 3 news items on index, link to a page with all news items --- client.go | 23 ++++++++++++++++++++++- database.go | 18 +++++++++++++----- main.go | 6 ++++++ static/anews.html | 44 ++++++++++++++++++++++++++++++++++++++++++++ static/index.html | 2 +- 5 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 static/anews.html diff --git a/client.go b/client.go index be79cdd..a5fb5bb 100644 --- a/client.go +++ b/client.go @@ -102,7 +102,7 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { data.Board.Restricted = actor.Restricted data.BoardRemainer = make([]int, (len(data.Boards) % 3)+1) data.InstanceIndex = GetCollectionFromReq("https://fchan.xyz/followers").Items - data.NewsItems = getNewsFromDB(db) + data.NewsItems = getNewsFromDB(db, 3) t.ExecuteTemplate(w, "layout", data) } @@ -138,6 +138,27 @@ func NewsGet(w http.ResponseWriter, r *http.Request, db *sql.DB, timestamp int) t.ExecuteTemplate(w, "layout", data) } +func AllNewsGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { + t := template.Must(template.New("").Funcs(template.FuncMap{"unixtoreadable": func(u int) string { return time.Unix(int64(u), 0).Format("Jan 02, 2006") }}).ParseFiles("./static/main.html", "./static/anews.html")) + + actor := GetActorFromDB(db, Domain) + + var data PageData + data.PreferredUsername = actor.PreferredUsername + data.Title = actor.PreferredUsername + " News" + data.Boards = Boards + data.Board.Name = "" + data.Key = *Key + data.Board.Domain = Domain + data.Board.ModCred, _ = GetPasswordFromSession(r) + data.Board.Actor = actor + data.Board.Post.Actor = actor.Id + data.Board.Restricted = actor.Restricted + data.NewsItems = getNewsFromDB(db, 0) + + t.ExecuteTemplate(w, "layout", data) +} + func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Collection){ t := template.Must(template.ParseFiles("./static/main.html", "./static/nposts.html", "./static/top.html", "./static/bottom.html", "./static/posts.html")) diff --git a/database.go b/database.go index 7dc7f5c..731f160 100644 --- a/database.go +++ b/database.go @@ -1491,15 +1491,23 @@ func MarkObjectSensitive(db *sql.DB, id string, sensitive bool) { //if limit less than 1 return all news items func getNewsFromDB(db *sql.DB, limit int) []NewsItem { - news := []NewsItem + var news []NewsItem + var query string if(limit > 0) { - query :=`select title, content, time from newsItem order by time desc limit $1` + query =`select title, content, time from newsItem order by time desc limit $1` } else { - query :=`select title, content, time from newsItem order by time desc` + query =`select title, content, time from newsItem order by time desc` } - rows, err := db.Query(query, limit) + var rows *sql.Rows + var err error + if(limit > 0) { + rows, err = db.Query(query, limit) + } else { + rows, err = db.Query(query) + } + if CheckError(err, "could not get news from db query") != nil { return news @@ -1512,7 +1520,7 @@ func getNewsFromDB(db *sql.DB, limit int) []NewsItem { if CheckError(err, "error scanning news from db") != nil { return news } - append(news, n) + news = append(news, n) } return news diff --git a/main.go b/main.go index 69e8902..3eb47c0 100644 --- a/main.go +++ b/main.go @@ -293,6 +293,12 @@ func main() { http.HandleFunc("/news/", func(w http.ResponseWriter, r *http.Request){ timestamp := r.URL.Path[6:] + + if(len(timestamp) < 2) { + AllNewsGet(w, r, db) + return + } + if timestamp[len(timestamp)-1:] == "/" { timestamp = timestamp[:len(timestamp)-1] } diff --git a/static/anews.html b/static/anews.html new file mode 100644 index 0000000..6527ce5 --- /dev/null +++ b/static/anews.html @@ -0,0 +1,44 @@ +{{ define "header" }} +{{ .Title }} + + + + + + + + + + + + + + +{{ end }} + +{{ define "top" }}{{ end }} +{{ define "content" }} +
+

{{ .Title }}

+ +
+ + + {{ range $i, $e := .NewsItems }} + + + + {{ end }} +
{{unixtoreadable $e.Time}} - {{$e.Title}} + {{ if eq $i 0 }} +

{{$e.Content}}

+ {{ end }} +
+
+ +
+{{ end }} +{{ define "bottom" }}{{ end }} + +{{ define "script" }} +{{ end }} diff --git a/static/index.html b/static/index.html index 518c012..106a6b3 100644 --- a/static/index.html +++ b/static/index.html @@ -39,7 +39,7 @@
{{ .PreferredUsername }} news + {{ .PreferredUsername }} news {{ range $i, $e := .NewsItems }} -- cgit v1.2.3 From fab8de7187571a4f3f8a30966057d661a858b645 Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 2 Jul 2021 15:10:49 -0500 Subject: add deletion of news items --- database.go | 5 +++++ main.go | 15 +++++++++++++++ static/anews.html | 4 +++- static/index.html | 3 ++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/database.go b/database.go index 731f160..6a871ba 100644 --- a/database.go +++ b/database.go @@ -1547,6 +1547,11 @@ func getNewsItemFromDB(db *sql.DB, timestamp int) (NewsItem, error) { return news, nil } +func deleteNewsItemFromDB(db *sql.DB, timestamp int) { + query := `delete from newsItem where time=$1` + db.Exec(query, timestamp) +} + func WriteNewsToDB(db *sql.DB, news NewsItem) { query := `insert into newsItem (title, content, time) values ($1, $2, $3)` diff --git a/main.go b/main.go index 3eb47c0..f98add9 100644 --- a/main.go +++ b/main.go @@ -634,6 +634,21 @@ func main() { http.Redirect(w, r, "/", http.StatusSeeOther) }) + + http.HandleFunc("/" + *Key + "/newsdelete/", func(w http.ResponseWriter, r *http.Request){ + timestamp := r.URL.Path[13+len(*Key):] + + tsint, err := strconv.Atoi(timestamp) + + if(err != nil){ + w.WriteHeader(http.StatusForbidden) + w.Write([]byte("404 no path")) + return + } else { + deleteNewsItemFromDB(db, tsint) + http.Redirect(w, r, "/news/", http.StatusSeeOther) + } + }) http.HandleFunc("/verify", func(w http.ResponseWriter, r *http.Request){ if(r.Method == "POST") { diff --git a/static/anews.html b/static/anews.html index 6527ce5..127760a 100644 --- a/static/anews.html +++ b/static/anews.html @@ -26,7 +26,9 @@ {{ range $i, $e := .NewsItems }} - -
-
{{unixtoreadable $e.Time}} - {{$e.Title}} + + {{ if $.Board.ModCred }}[Delete] {{end}} + {{unixtoreadable $e.Time}} - {{$e.Title}} {{ if eq $i 0 }}

{{$e.Content}}

{{ end }} diff --git a/static/index.html b/static/index.html index 106a6b3..61aeab8 100644 --- a/static/index.html +++ b/static/index.html @@ -44,7 +44,8 @@ {{ range $i, $e := .NewsItems }}
{{unixtoreadable $e.Time}} - {{$e.Title}} + {{ if $.Board.ModCred }}[Delete] {{end}} + {{unixtoreadable $e.Time}} - {{$e.Title}} {{ if eq $i 0 }}

{{$e.Content}}

{{ end }} -- cgit v1.2.3 From fc8b4d6517213a371e26938ff2c0319d5e5f459a Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 2 Jul 2021 15:22:00 -0500 Subject: fix board remainder calculation --- client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index a5fb5bb..f71fb7d 100644 --- a/client.go +++ b/client.go @@ -100,7 +100,12 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { data.Board.Actor = actor data.Board.Post.Actor = actor.Id data.Board.Restricted = actor.Restricted - data.BoardRemainer = make([]int, (len(data.Boards) % 3)+1) + //almost certainly there is a better algorithm for this but the old one was wrong + //and I suck at math. This works at least. + data.BoardRemainer = make([]int, 3-(len(data.Boards) % 3)) + if(len(data.BoardRemainer) == 3){ + data.BoardRemainer = make([]int, 0) + } data.InstanceIndex = GetCollectionFromReq("https://fchan.xyz/followers").Items data.NewsItems = getNewsFromDB(db, 3) -- cgit v1.2.3