💥 Use attachment rid instead of primary key when create

This commit is contained in:
LittleSheep 2024-08-18 22:12:06 +08:00
parent 165a6be985
commit d2ff4087e5
2 changed files with 10 additions and 11 deletions

9
.idea/workspace.xml generated
View File

@ -4,11 +4,9 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":sparkles: Support use rid to get file"> <list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":boom: Replace attachment id by rid when fetching">
<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/internal/server/api/attachment_dir_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/attachment_dir_api.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/server/api/stickers_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/stickers_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/attachments_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/attachments_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/attachments.go" 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" />
@ -137,7 +135,8 @@
<MESSAGE value=":zap: Fix the RandString method cause the lag" /> <MESSAGE value=":zap: Fix the RandString method cause the lag" />
<MESSAGE value=":bug: Fix mark clean required issue" /> <MESSAGE value=":bug: Fix mark clean required issue" />
<MESSAGE value=":sparkles: Support use rid to get file" /> <MESSAGE value=":sparkles: Support use rid to get file" />
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Support use rid to get file" /> <MESSAGE value=":boom: Replace attachment id by rid when fetching" />
<option name="LAST_COMMIT_MESSAGE" value=":boom: Replace attachment id by rid when fetching" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

View File

@ -69,7 +69,7 @@ func createSticker(c *fiber.Ctx) error {
var data struct { var data struct {
Alias string `json:"alias" validate:"required,alphanum,min=2,max=12"` Alias string `json:"alias" validate:"required,alphanum,min=2,max=12"`
Name string `json:"name" validate:"required"` Name string `json:"name" validate:"required"`
AttachmentID uint `json:"attachment_id"` AttachmentID string `json:"attachment_id"`
PackID uint `json:"pack_id"` PackID uint `json:"pack_id"`
} }
@ -78,7 +78,7 @@ func createSticker(c *fiber.Ctx) error {
} }
var attachment models.Attachment var attachment models.Attachment
if err := database.C.Where("id = ?", data.AttachmentID).First(&attachment).Error; err != nil { if err := database.C.Where("rid = ?", data.AttachmentID).First(&attachment).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find attachment: %v", err)) return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find attachment: %v", err))
} else if !attachment.IsAnalyzed { } else if !attachment.IsAnalyzed {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be analyzed") return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be analyzed")
@ -99,7 +99,7 @@ func createSticker(c *fiber.Ctx) error {
Attachment: attachment, Attachment: attachment,
AccountID: user.ID, AccountID: user.ID,
PackID: pack.ID, PackID: pack.ID,
AttachmentID: data.AttachmentID, AttachmentID: attachment.ID,
}) })
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())
@ -117,7 +117,7 @@ func updateSticker(c *fiber.Ctx) error {
var data struct { var data struct {
Alias string `json:"alias" validate:"required,alphanum,min=2,max=12"` Alias string `json:"alias" validate:"required,alphanum,min=2,max=12"`
Name string `json:"name" validate:"required"` Name string `json:"name" validate:"required"`
AttachmentID uint `json:"attachment_id"` AttachmentID string `json:"attachment_id"`
PackID uint `json:"pack_id"` PackID uint `json:"pack_id"`
} }
@ -132,7 +132,7 @@ func updateSticker(c *fiber.Ctx) error {
} }
var attachment models.Attachment var attachment models.Attachment
if err := database.C.Where("id = ?", data.AttachmentID).First(&attachment).Error; err != nil { if err := database.C.Where("rid = ?", data.AttachmentID).First(&attachment).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find attachment: %v", err)) return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find attachment: %v", err))
} else if !attachment.IsAnalyzed { } else if !attachment.IsAnalyzed {
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be analyzed") return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be analyzed")
@ -150,7 +150,7 @@ func updateSticker(c *fiber.Ctx) error {
sticker.Alias = data.Alias sticker.Alias = data.Alias
sticker.Name = data.Name sticker.Name = data.Name
sticker.PackID = data.PackID sticker.PackID = data.PackID
sticker.AttachmentID = data.AttachmentID sticker.AttachmentID = attachment.ID
if sticker, err = services.UpdateSticker(sticker); err != nil { if sticker, err = services.UpdateSticker(sticker); err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())