From 304561b20efb99b891ea84c60ceeaab16ca94164 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 22 May 2022 17:14:27 -0700 Subject: added mark sensitive --- route/routes/boardmgmt.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go index 4f3f815..ba20a23 100644 --- a/route/routes/boardmgmt.go +++ b/route/routes/boardmgmt.go @@ -104,7 +104,66 @@ func BoardDeleteAttach(ctx *fiber.Ctx) error { } func BoardMarkSensitive(ctx *fiber.Ctx) error { - return ctx.SendString("board mark sensitive") + var err error + + postID := ctx.Query("id") + board := ctx.Query("board") + + _, auth := util.GetPasswordFromSession(ctx) + + if postID == "" || auth == "" { + ctx.Response().Header.SetStatusCode(http.StatusBadRequest) + + _, err := ctx.Write([]byte("id or auth empty")) + return util.MakeError(err, "BoardDelete") + } + + var col activitypub.Collection + activity := activitypub.Activity{Id: postID} + + if col, err = activity.GetCollection(); err != nil { + return util.MakeError(err, "BoardDelete") + } + + var OP string + var actor activitypub.Actor + + if len(col.OrderedItems) == 0 { + actor, err = activitypub.GetActorByNameFromDB(board) + + if err != nil { + return util.MakeError(err, "BoardDelete") + } + } else { + if len(col.OrderedItems[0].InReplyTo) > 0 { + OP = col.OrderedItems[0].InReplyTo[0].Id + } + + actor.Id = col.OrderedItems[0].Actor + } + + 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: postID} + + if err = obj.MarkSensitive(true); err != nil { + return util.MakeError(err, "BoardDelete") + } + + if isOP, _ := obj.CheckIfOP(); !isOP && OP != "" { + if local, _ := obj.IsLocal(); !local { + return ctx.Redirect("/"+board+"/"+util.RemoteShort(OP), http.StatusSeeOther) + } + + return ctx.Redirect(OP, http.StatusSeeOther) + } + + return ctx.Redirect("/"+board, http.StatusSeeOther) } func BoardRemove(ctx *fiber.Ctx) error { -- cgit v1.2.3