diff options
author | FChannel0 <77419041+FChannel0@users.noreply.github.com> | 2021-07-03 16:16:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-03 16:16:22 -0700 |
commit | 875ee4c53d79918ac87d1ce3e208ad27db6c0a90 (patch) | |
tree | fef9e3a94b09f356711fce887a42d405338dffb8 /main.go | |
parent | 9bd4e03d926c045dc82ce844cb02b078843ce787 (diff) | |
parent | fc8b4d6517213a371e26938ff2c0319d5e5f459a (diff) |
Merge pull request #27 from knotteye/master
Home page improvements and news system
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -290,6 +290,27 @@ 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(len(timestamp) < 2) { + AllNewsGet(w, r, db) + return + } + + 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){ @@ -602,6 +623,32 @@ 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("/" + *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") { |