diff options
Diffstat (limited to 'route/routes/boardmgmt.go')
-rw-r--r-- | route/routes/boardmgmt.go | 81 |
1 files changed, 25 insertions, 56 deletions
diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go index fb577f3..4f3f815 100644 --- a/route/routes/boardmgmt.go +++ b/route/routes/boardmgmt.go @@ -14,85 +14,55 @@ func BoardBanMedia(ctx *fiber.Ctx) error { } func BoardDelete(ctx *fiber.Ctx) error { - id := ctx.Query("id") + var err error + + postID := ctx.Query("id") board := ctx.Query("board") _, auth := util.GetPasswordFromSession(ctx) - if id == "" || auth == "" { + if postID == "" || auth == "" { ctx.Response().Header.SetStatusCode(http.StatusBadRequest) _, err := ctx.Write([]byte("id or auth empty")) return util.MakeError(err, "BoardDelete") } - activity := activitypub.Activity{Id: id} - col, err := activity.GetCollection() + var col activitypub.Collection + activity := activitypub.Activity{Id: postID} - if err != nil { + if col, err = activity.GetCollection(); err != nil { return util.MakeError(err, "BoardDelete") } - if len(col.OrderedItems) < 1 { - actor, err := activitypub.GetActorByNameFromDB(board) - - if err != nil { - return util.MakeError(err, "BoardDelete") - } - - if has, _ := util.HasAuth(auth, actor.Id); !has { - ctx.Response().Header.SetStatusCode(http.StatusBadRequest) - - _, err := ctx.Write([]byte("does not have auth")) - return util.MakeError(err, "BoardDelete") - } - - obj := activitypub.ObjectBase{Id: id} - isOP, _ := obj.CheckIfOP() + var OP string + var actor activitypub.Actor - if !isOP { - if err := obj.Tombstone(); err != nil { - return util.MakeError(err, "BoardDelete") - } - } else { - if err := obj.TombstoneReplies(); err != nil { - return util.MakeError(err, "BoardDelete") - } - } + if len(col.OrderedItems) == 0 { + actor, err = activitypub.GetActorByNameFromDB(board) - if err := actor.UnArchiveLast(); err != nil { + if err != nil { return util.MakeError(err, "BoardDelete") } - - if ctx.Query("manage") == "t" { - return ctx.Redirect("/"+config.Key+"/"+board, http.StatusSeeOther) + } else { + if len(col.OrderedItems[0].InReplyTo) > 0 { + OP = col.OrderedItems[0].InReplyTo[0].Id } - return ctx.Redirect("/"+board, http.StatusSeeOther) + actor.Id = col.OrderedItems[0].Actor } - actorID := col.OrderedItems[0].Actor - - if has, _ := util.HasAuth(auth, actorID); !has { + if has, _ := util.HasAuth(auth, actor.Id); !has { ctx.Response().Header.SetStatusCode(http.StatusBadRequest) _, err := ctx.Write([]byte("does not have auth")) return util.MakeError(err, "BoardDelete") } - var obj activitypub.ObjectBase - obj.Id = id - obj.Actor = actorID - - isOP, _ := obj.CheckIfOP() - - var OP string - - if len(col.OrderedItems[0].InReplyTo) > 0 { - OP = col.OrderedItems[0].InReplyTo[0].Id - } + var isOP bool + obj := activitypub.ObjectBase{Id: postID} - if !isOP { + if isOP, _ = obj.CheckIfOP(); !isOP { if err := obj.Tombstone(); err != nil { return util.MakeError(err, "BoardDelete") } @@ -102,16 +72,15 @@ func BoardDelete(ctx *fiber.Ctx) error { } } - if local, _ := obj.IsLocal(); !local { + var local bool + + if local, _ = obj.IsLocal(); !local { if err := obj.DeleteRequest(); err != nil { return util.MakeError(err, "BoardDelete") } } - actor := activitypub.Actor{Id: actorID} - err = actor.UnArchiveLast() - - if err != nil { + if err := actor.UnArchiveLast(); err != nil { return util.MakeError(err, "BoardDelete") } @@ -120,7 +89,7 @@ func BoardDelete(ctx *fiber.Ctx) error { } if !isOP { - if local, _ := obj.IsLocal(); !local { + if !local { return ctx.Redirect("/"+board+"/"+util.RemoteShort(OP), http.StatusSeeOther) } else { return ctx.Redirect(OP, http.StatusSeeOther) |