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