From caa24b5f43709f3201faf0eabf2ac7afcdee17f7 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 30 May 2021 21:40:04 -0700 Subject: more route redirection cleanup --- main.go | 58 +++++++++++++++++++++++++++++++++++++----------------- static/bottom.html | 2 +- static/manage.html | 2 +- static/posts.html | 8 ++++---- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/main.go b/main.go index 07c6c86..6fa1486 100644 --- a/main.go +++ b/main.go @@ -187,6 +187,7 @@ func main() { page, _ := strconv.Atoi(postNum) collection, valid := WantToServePage(db, actor.Name, page) + if valid { OutboxGet(w, r, db, collection) } @@ -710,6 +711,7 @@ func main() { http.HandleFunc("/delete", func(w http.ResponseWriter, r *http.Request){ id := r.URL.Query().Get("id") + manage := r.URL.Query().Get("manage") board := r.URL.Query().Get("board") col := GetCollectionFromID(id) actor := col.OrderedItems[0].Actor @@ -727,37 +729,43 @@ func main() { return } + var obj ObjectBase + obj.Id = id + obj.Actor = actor + + isOP := CheckIfObjectOP(db, obj.Id) + var OP string if len(col.OrderedItems[0].InReplyTo) > 0 { OP = col.OrderedItems[0].InReplyTo[0].Id } if !IsIDLocal(db, id) { - CreateLocalDeleteDB(db, id, "post") - CloseLocalReportDB(db, id, actor.Id) - - if(board != "") { - http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther) + if(!isOP) { + CloseLocalReportDB(db, id, board) + CreateLocalDeleteDB(db, id, "post") + } else { + + } + if(manage == "t") { + http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther) } else if(OP != ""){ - http.Redirect(w, r, OP, http.StatusSeeOther) + http.Redirect(w, r, "/" + board + "/" + remoteShort(OP), http.StatusSeeOther) } else { - http.Redirect(w, r, actor.Id, http.StatusSeeOther) + http.Redirect(w, r, "/" + board, http.StatusSeeOther) } return } - var obj ObjectBase - obj.Id = id - obj.Actor = actor - - isOP := CheckIfObjectOP(db, obj.Id) + if !isOP { + DeleteReportActivity(db, id) DeleteObjectRequest(db, id) DeleteObject(db, obj.Id) - if(board != ""){ + if(manage == "t"){ http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther) }else{ http.Redirect(w, r, OP, http.StatusSeeOther) @@ -765,12 +773,13 @@ func main() { return } else { + DeleteReportActivity(db, id) DeleteObjectAndRepliesRequest(db, id) DeleteObjectAndReplies(db, obj.Id) - if(board != ""){ + if(manage == "t"){ http.Redirect(w, r, "/" + *Key + "/" + board , http.StatusSeeOther) }else{ - http.Redirect(w, r, actor.Id, http.StatusSeeOther) + http.Redirect(w, r, "/" + board, http.StatusSeeOther) } return } @@ -782,6 +791,8 @@ func main() { http.HandleFunc("/deleteattach", func(w http.ResponseWriter, r *http.Request){ id := r.URL.Query().Get("id") + manage := r.URL.Query().Get("manage") + board := r.URL.Query().Get("board") col := GetCollectionFromID(id) actor := col.OrderedItems[0].Actor @@ -804,17 +815,28 @@ func main() { w.WriteHeader(http.StatusBadRequest) w.Write([]byte("")) return - } + } + + if !IsIDLocal(db, id) { CreateLocalDeleteDB(db, id, "attachment") - http.Redirect(w, r, OP, http.StatusSeeOther) + if(manage == "t") { + http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther) + } else { + http.Redirect(w, r, "/" + board + "/" + remoteShort(OP), http.StatusSeeOther) + } return } DeleteAttachmentFromFile(db, id) DeletePreviewFromFile(db, id) - http.Redirect(w, r, OP, http.StatusSeeOther) + + if(manage == "t") { + http.Redirect(w, r, "/" + *Key + "/" + board, http.StatusSeeOther) + } else { + http.Redirect(w, r, OP, http.StatusSeeOther) + } }) http.HandleFunc("/report", func(w http.ResponseWriter, r *http.Request){ diff --git a/static/bottom.html b/static/bottom.html index c058b14..8774419 100644 --- a/static/bottom.html +++ b/static/bottom.html @@ -29,7 +29,7 @@ - +