💥 Use attachment rid instead of primary key when create
This commit is contained in:
parent
165a6be985
commit
d2ff4087e5
9
.idea/workspace.xml
generated
9
.idea/workspace.xml
generated
@ -4,11 +4,9 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<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$/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/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" />
|
||||
<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" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -137,7 +135,8 @@
|
||||
<MESSAGE value=":zap: Fix the RandString method cause the lag" />
|
||||
<MESSAGE value=":bug: Fix mark clean required issue" />
|
||||
<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 name="VgoProject">
|
||||
<settings-migrated>true</settings-migrated>
|
||||
|
@ -69,7 +69,7 @@ func createSticker(c *fiber.Ctx) error {
|
||||
var data struct {
|
||||
Alias string `json:"alias" validate:"required,alphanum,min=2,max=12"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
AttachmentID uint `json:"attachment_id"`
|
||||
AttachmentID string `json:"attachment_id"`
|
||||
PackID uint `json:"pack_id"`
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ func createSticker(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
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))
|
||||
} else if !attachment.IsAnalyzed {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "sticker attachment must be analyzed")
|
||||
@ -99,7 +99,7 @@ func createSticker(c *fiber.Ctx) error {
|
||||
Attachment: attachment,
|
||||
AccountID: user.ID,
|
||||
PackID: pack.ID,
|
||||
AttachmentID: data.AttachmentID,
|
||||
AttachmentID: attachment.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
@ -117,7 +117,7 @@ func updateSticker(c *fiber.Ctx) error {
|
||||
var data struct {
|
||||
Alias string `json:"alias" validate:"required,alphanum,min=2,max=12"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
AttachmentID uint `json:"attachment_id"`
|
||||
AttachmentID string `json:"attachment_id"`
|
||||
PackID uint `json:"pack_id"`
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ func updateSticker(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
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))
|
||||
} else if !attachment.IsAnalyzed {
|
||||
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.Name = data.Name
|
||||
sticker.PackID = data.PackID
|
||||
sticker.AttachmentID = data.AttachmentID
|
||||
sticker.AttachmentID = attachment.ID
|
||||
|
||||
if sticker, err = services.UpdateSticker(sticker); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
|
Loading…
Reference in New Issue
Block a user