✨ Instant upload
This commit is contained in:
@ -18,12 +18,16 @@ func readAttachment(c *fiber.Ctx) error {
|
||||
|
||||
func uploadAttachment(c *fiber.Ctx) error {
|
||||
user := c.Locals("principal").(models.Account)
|
||||
hashcode := c.FormValue("hashcode")
|
||||
if len(hashcode) != 64 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "please provide a SHA256 hashcode, length should be 64 characters")
|
||||
}
|
||||
file, err := c.FormFile("attachment")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
attachment, err := services.NewAttachment(user, file)
|
||||
attachment, err := services.NewAttachment(user, file, hashcode)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
@ -39,10 +43,10 @@ func uploadAttachment(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func deleteAttachment(c *fiber.Ctx) error {
|
||||
id := c.Params("fileId")
|
||||
id, _ := c.ParamsInt("id", 0)
|
||||
user := c.Locals("principal").(models.Account)
|
||||
|
||||
attachment, err := services.GetAttachmentByUUID(id)
|
||||
attachment, err := services.GetAttachmentByID(uint(id))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
} else if attachment.AuthorID != user.ID {
|
||||
|
@ -68,7 +68,7 @@ func NewServer() {
|
||||
CacheControl: true,
|
||||
}), readAttachment)
|
||||
api.Post("/attachments", authMiddleware, uploadAttachment)
|
||||
api.Delete("/attachments/:fileId", authMiddleware, deleteAttachment)
|
||||
api.Delete("/attachments/:id", authMiddleware, deleteAttachment)
|
||||
|
||||
api.Get("/feed", listFeed)
|
||||
|
||||
|
Reference in New Issue
Block a user