aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorFChannel0 <77419041+FChannel0@users.noreply.github.com>2021-07-03 16:16:22 -0700
committerGitHub <noreply@github.com>2021-07-03 16:16:22 -0700
commit875ee4c53d79918ac87d1ce3e208ad27db6c0a90 (patch)
treefef9e3a94b09f356711fce887a42d405338dffb8 /client.go
parent9bd4e03d926c045dc82ce844cb02b078843ce787 (diff)
parentfc8b4d6517213a371e26938ff2c0319d5e5f459a (diff)
Merge pull request #27 from knotteye/master
Home page improvements and news system
Diffstat (limited to 'client.go')
-rw-r--r--client.go78
1 files changed, 72 insertions, 6 deletions
diff --git a/client.go b/client.go
index 6e185cc..f71fb7d 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)
@@ -35,8 +36,7 @@ type Board struct{
type PageData struct {
Title string
- Message string
- MessageHTML template.HTML
+ PreferredUsername string
Board Board
Pages []int
CurrentPage int
@@ -48,6 +48,8 @@ type PageData struct {
Instance Actor
InstanceIndex []ObjectBase
ReturnTo string
+ NewsItems []NewsItem
+ BoardRemainer []int
}
type AdminPage struct {
@@ -74,15 +76,22 @@ 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 }, "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)
var data PageData
data.Title = "Welcome to " + actor.PreferredUsername
- data.Message = actor.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 https://github.com/FChannel0"
- data.MessageHTML = template.HTML(actor.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 <a href='https://github.com/FChannel0'>https://github.com/FChannel0</a>")
+
+ data.PreferredUsername = actor.PreferredUsername
data.Boards = Boards
data.Board.Name = ""
data.Key = *Key
@@ -91,11 +100,68 @@ 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
+ //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)
+
+ 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 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"))
- t.ExecuteTemplate(w, "layout", data)
+ 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){