diff options
Diffstat (limited to 'route/routes/boardmgmt.go')
-rw-r--r-- | route/routes/boardmgmt.go | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go index 5f24cdd..7ecc885 100644 --- a/route/routes/boardmgmt.go +++ b/route/routes/boardmgmt.go @@ -563,3 +563,99 @@ func ReportGet(ctx *fiber.Ctx) error { return ctx.Render("report", fiber.Map{"page": data}, "layouts/main") } + +func Sticky(ctx *fiber.Ctx) error { + id := ctx.Query("id") + board := ctx.Query("board") + + actor, _ := activitypub.GetActorByNameFromDB(board) + + _, auth := util.GetPasswordFromSession(ctx) + + if id == "" || auth == "" { + return util.MakeError(errors.New("no auth"), "Sticky") + } + + var obj = activitypub.ObjectBase{Id: id} + col, _ := obj.GetCollectionFromPath() + + if len(col.OrderedItems) < 1 { + if has, _ := util.HasAuth(auth, actor.Id); !has { + return util.MakeError(errors.New("no auth"), "Sticky") + } + + obj.MarkSticky(actor.Id) + + return ctx.Redirect("/"+board, http.StatusSeeOther) + } + + actor.Id = col.OrderedItems[0].Actor + + var OP string + if len(col.OrderedItems[0].InReplyTo) > 0 && col.OrderedItems[0].InReplyTo[0].Id != "" { + OP = col.OrderedItems[0].InReplyTo[0].Id + } else { + OP = id + } + + if has, _ := util.HasAuth(auth, actor.Id); !has { + return util.MakeError(errors.New("no auth"), "Sticky") + } + + obj.MarkSticky(actor.Id) + + var op = activitypub.ObjectBase{Id: OP} + if local, _ := op.IsLocal(); !local { + return ctx.Redirect("/"+board+"/"+util.RemoteShort(OP), http.StatusSeeOther) + } else { + return ctx.Redirect(OP, http.StatusSeeOther) + } +} + +func Lock(ctx *fiber.Ctx) error { + id := ctx.Query("id") + board := ctx.Query("board") + + actor, _ := activitypub.GetActorByNameFromDB(board) + + _, auth := util.GetPasswordFromSession(ctx) + + if id == "" || auth == "" { + return util.MakeError(errors.New("no auth"), "Lock") + } + + var obj = activitypub.ObjectBase{Id: id} + col, _ := obj.GetCollectionFromPath() + + if len(col.OrderedItems) < 1 { + if has, _ := util.HasAuth(auth, actor.Id); !has { + return util.MakeError(errors.New("no auth"), "Lock") + } + + obj.MarkLocked(actor.Id) + + return ctx.Redirect("/"+board, http.StatusSeeOther) + } + + actor.Id = col.OrderedItems[0].Actor + + var OP string + if len(col.OrderedItems[0].InReplyTo) > 0 && col.OrderedItems[0].InReplyTo[0].Id != "" { + OP = col.OrderedItems[0].InReplyTo[0].Id + } else { + OP = id + } + + if has, _ := util.HasAuth(auth, actor.Id); !has { + return util.MakeError(errors.New("no auth"), "Lock") + } + + obj.MarkLocked(actor.Id) + + var op = activitypub.ObjectBase{Id: OP} + if local, _ := op.IsLocal(); !local { + return ctx.Redirect("/"+board+"/"+util.RemoteShort(OP), http.StatusSeeOther) + } else { + return ctx.Redirect(OP, http.StatusSeeOther) + } +} |