Real attachment deletion

This commit is contained in:
2024-03-24 18:31:36 +08:00
parent bdfd74eaf4
commit 93d959e7a6
4 changed files with 56 additions and 3 deletions

View File

@ -37,3 +37,21 @@ func uploadAttachment(c *fiber.Ctx) error {
"url": attachment.GetAccessPath(),
})
}
func deleteAttachment(c *fiber.Ctx) error {
id := c.Params("fileId")
user := c.Locals("principal").(models.Account)
attachment, err := services.GetAttachmentByUUID(id)
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
} else if attachment.AuthorID != user.ID {
return fiber.NewError(fiber.StatusNotFound, "record not created by you")
}
if err := services.DeleteAttachment(attachment); err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} else {
return c.SendStatus(fiber.StatusOK)
}
}

View File

@ -68,6 +68,7 @@ func NewServer() {
CacheControl: true,
}), readAttachment)
api.Post("/attachments", authMiddleware, uploadAttachment)
api.Delete("/attachments/:fileId", authMiddleware, deleteAttachment)
api.Get("/feed", listFeed)