diff options
author | FChannel <> | 2022-05-22 17:14:27 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | 304561b20efb99b891ea84c60ceeaab16ca94164 (patch) | |
tree | 548dc31c47675101f4f47e750d533803022365c8 | |
parent | 01d4433dab8b69ceed92c10f96e7dc574e3cedf0 (diff) |
added mark sensitive
-rw-r--r-- | route/routes/boardmgmt.go | 61 |
1 files changed, 60 insertions, 1 deletions
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 { |