🐛 I am dumb
This commit is contained in:
@ -5,7 +5,7 @@ import "gorm.io/datatypes"
|
||||
type Attachment struct {
|
||||
BaseModel
|
||||
|
||||
Uuid string `json:"uuid" gorm:"uniqueIndex"`
|
||||
Uuid string `json:"uuid"`
|
||||
Size int64 `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Alternative string `json:"alt"`
|
||||
|
@ -19,9 +19,9 @@ import (
|
||||
)
|
||||
|
||||
func openAttachment(c *fiber.Ctx) error {
|
||||
id := c.Params("id")
|
||||
id, _ := c.ParamsInt("id", 0)
|
||||
|
||||
metadata, err := services.GetAttachmentByUUID(id)
|
||||
metadata, err := services.GetAttachmentByID(uint(id))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound)
|
||||
}
|
||||
@ -58,9 +58,9 @@ func openAttachment(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func getAttachmentMeta(c *fiber.Ctx) error {
|
||||
id := c.Params("id")
|
||||
id, _ := c.ParamsInt("id")
|
||||
|
||||
metadata, err := services.GetAttachmentByUUID(id)
|
||||
metadata, err := services.GetAttachmentByID(uint(id))
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusNotFound)
|
||||
}
|
||||
@ -132,6 +132,7 @@ func createAttachment(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
func updateAttachmentMeta(c *fiber.Ctx) error {
|
||||
id, _ := c.ParamsInt("id", 0)
|
||||
user := c.Locals("principal").(models.Account)
|
||||
|
||||
var data struct {
|
||||
@ -147,9 +148,9 @@ func updateAttachmentMeta(c *fiber.Ctx) error {
|
||||
|
||||
var attachment models.Attachment
|
||||
if err := database.C.Where(models.Attachment{
|
||||
Uuid: c.Params("id"),
|
||||
BaseModel: models.BaseModel{ID: uint(id)},
|
||||
AccountID: user.ID,
|
||||
}).Error; err != nil {
|
||||
}).First(&attachment).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,11 @@ func NewAttachmentMetadata(tx *gorm.DB, user models.Account, file *multipart.Fil
|
||||
exists, pickupErr := GetAttachmentByHash(attachment.HashCode)
|
||||
if pickupErr == nil {
|
||||
linked = true
|
||||
exists.Alternative = attachment.Alternative
|
||||
exists.Usage = attachment.Usage
|
||||
exists.Metadata = attachment.Metadata
|
||||
attachment = exists
|
||||
attachment.ID = 0
|
||||
attachment.Uuid = uuid.NewString()
|
||||
attachment.AccountID = user.ID
|
||||
} else {
|
||||
// Upload the new file
|
||||
|
Reference in New Issue
Block a user