aboutsummaryrefslogtreecommitdiff
path: root/controllers/moderation.go
diff options
context:
space:
mode:
authorvulonkaaz <7442677+vulonkaaz@users.noreply.github.com>2024-07-09 17:38:23 +0200
committervulonkaaz <7442677+vulonkaaz@users.noreply.github.com>2024-07-09 17:38:23 +0200
commitce0a2b123603edcde4e17eacc02bafeec85f74ab (patch)
tree8bb4c20776fec63f7235772f8f698c76d74eee86 /controllers/moderation.go
parent80a73aeee4d2677961d9377c6f5b597ea2b8f473 (diff)
delete api for moderation
Diffstat (limited to 'controllers/moderation.go')
-rw-r--r--controllers/moderation.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/controllers/moderation.go b/controllers/moderation.go
new file mode 100644
index 0000000..0313798
--- /dev/null
+++ b/controllers/moderation.go
@@ -0,0 +1,51 @@
+package controllers
+
+import (
+ "log"
+ "os"
+ "paperchan.club/database"
+ "github.com/gofiber/fiber/v2"
+ "golang.org/x/crypto/bcrypt"
+ "strconv"
+)
+
+// data received by DELETE /api/post
+type DeleteApi struct {
+ Id string `json:"id" xml:"id" form:"id"`
+ Pass string `json:"pass" xml:"pass" form:"pass"` //moderation password defined in .env
+}
+func Delete(c *fiber.Ctx) error {
+ d := new(DeleteApi)
+ if err := c.BodyParser(d); err != nil {
+ log.Println(err)
+ return c.JSON(fiber.Map{
+ "status": "error",
+ })
+ }
+ id, err := strconv.ParseInt(d.Id, 10, 32)
+ if err != nil {
+ log.Println(err)
+ return c.JSON(fiber.Map{
+ "status": "error",
+ })
+ }
+ if bcrypt.CompareHashAndPassword([]byte(os.Getenv("MODPASS")),[]byte(d.Pass)) != nil {
+ log.Println(os.Getenv("MODPASS"))
+ log.Println(err)
+ return c.JSON(fiber.Map{
+ "status": "forbidden",
+ })
+ } else {
+ db := database.DB
+ if _, err := db.Exec("DELETE FROM \"post\" WHERE id = $1", id); err == nil {
+ return c.JSON(fiber.Map{
+ "status": "ok",
+ })
+ } else {
+ log.Println(err)
+ return c.JSON(fiber.Map{
+ "status": "database error",
+ })
+ }
+ }
+}