🐛 I am dumb
This commit is contained in:
parent
ff450ddd9d
commit
2b131982b8
3
.idea/workspace.xml
generated
3
.idea/workspace.xml
generated
@ -6,7 +6,10 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix uuid duplicate when link exists">
|
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix uuid duplicate when link exists">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/pkg/models/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/models/attachments.go" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/server/attachments_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/attachments_api.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/server/attachments_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/attachments_api.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/pkg/services/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/services/attachments.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/settings.toml" beforeDir="false" afterPath="$PROJECT_DIR$/settings.toml" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -5,7 +5,7 @@ import "gorm.io/datatypes"
|
|||||||
type Attachment struct {
|
type Attachment struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
|
|
||||||
Uuid string `json:"uuid" gorm:"uniqueIndex"`
|
Uuid string `json:"uuid"`
|
||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Alternative string `json:"alt"`
|
Alternative string `json:"alt"`
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func openAttachment(c *fiber.Ctx) error {
|
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 {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound)
|
return fiber.NewError(fiber.StatusNotFound)
|
||||||
}
|
}
|
||||||
@ -58,9 +58,9 @@ func openAttachment(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getAttachmentMeta(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 {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusNotFound)
|
return fiber.NewError(fiber.StatusNotFound)
|
||||||
}
|
}
|
||||||
@ -132,6 +132,7 @@ func createAttachment(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateAttachmentMeta(c *fiber.Ctx) error {
|
func updateAttachmentMeta(c *fiber.Ctx) error {
|
||||||
|
id, _ := c.ParamsInt("id", 0)
|
||||||
user := c.Locals("principal").(models.Account)
|
user := c.Locals("principal").(models.Account)
|
||||||
|
|
||||||
var data struct {
|
var data struct {
|
||||||
@ -147,9 +148,9 @@ func updateAttachmentMeta(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
var attachment models.Attachment
|
var attachment models.Attachment
|
||||||
if err := database.C.Where(models.Attachment{
|
if err := database.C.Where(models.Attachment{
|
||||||
Uuid: c.Params("id"),
|
BaseModel: models.BaseModel{ID: uint(id)},
|
||||||
AccountID: user.ID,
|
AccountID: user.ID,
|
||||||
}).Error; err != nil {
|
}).First(&attachment).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
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)
|
exists, pickupErr := GetAttachmentByHash(attachment.HashCode)
|
||||||
if pickupErr == nil {
|
if pickupErr == nil {
|
||||||
linked = true
|
linked = true
|
||||||
|
exists.Alternative = attachment.Alternative
|
||||||
|
exists.Usage = attachment.Usage
|
||||||
|
exists.Metadata = attachment.Metadata
|
||||||
attachment = exists
|
attachment = exists
|
||||||
attachment.ID = 0
|
attachment.ID = 0
|
||||||
attachment.Uuid = uuid.NewString()
|
|
||||||
attachment.AccountID = user.ID
|
attachment.AccountID = user.ID
|
||||||
} else {
|
} else {
|
||||||
// Upload the new file
|
// Upload the new file
|
||||||
|
@ -10,7 +10,7 @@ preferred_destination = "local"
|
|||||||
accepts_usage = ["p.avatar", "p.banner", "i.attachment", "m.attachment"]
|
accepts_usage = ["p.avatar", "p.banner", "i.attachment", "m.attachment"]
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
database = true
|
database = false
|
||||||
print_routes = false
|
print_routes = false
|
||||||
|
|
||||||
[passport]
|
[passport]
|
||||||
@ -39,4 +39,4 @@ bucket = "bucket"
|
|||||||
endpoint = "s3.ap-east-1.amazonaws.com"
|
endpoint = "s3.ap-east-1.amazonaws.com"
|
||||||
secret_id = "secret"
|
secret_id = "secret"
|
||||||
secret_key = "secret"
|
secret_key = "secret"
|
||||||
enable_ssl = true
|
enable_ssl = true
|
||||||
|
Loading…
Reference in New Issue
Block a user