🐛 Fix on boost reupload
This commit is contained in:
parent
0e0ad9c261
commit
1955d94414
@ -94,7 +94,7 @@ func ActivateBoost(boost models.AttachmentBoost) error {
|
||||
return fmt.Errorf("invalid destination: %d", boost.Destination)
|
||||
}
|
||||
|
||||
if err := ReUploadFile(boost.Attachment, boost.Destination); err != nil {
|
||||
if err := ReUploadFile(boost.Attachment, boost.Destination, true); err != nil {
|
||||
log.Warn().Any("boost", boost).Err(err).Msg("Unable to activate boost...")
|
||||
database.C.Model(&boost).Update("status", models.BoostStatusError)
|
||||
return err
|
||||
|
@ -35,7 +35,7 @@ func UploadFileToTemporary(ctx *fiber.Ctx, file *multipart.FileHeader, meta mode
|
||||
}
|
||||
}
|
||||
|
||||
func ReUploadFile(meta models.Attachment, dst int) error {
|
||||
func ReUploadFile(meta models.Attachment, dst int, doNotUpdate ...bool) error {
|
||||
if meta.Destination == dst {
|
||||
return fmt.Errorf("destnation cannot be reversed temporary or the same as the original")
|
||||
}
|
||||
@ -47,6 +47,9 @@ func ReUploadFile(meta models.Attachment, dst int) error {
|
||||
}
|
||||
|
||||
cleanupDst := func() {
|
||||
if len(doNotUpdate) == 0 || !doNotUpdate[0] {
|
||||
database.C.Save(&meta)
|
||||
}
|
||||
if prevDst == models.AttachmentDstTemporary {
|
||||
return
|
||||
}
|
||||
@ -82,7 +85,6 @@ func ReUploadFile(meta models.Attachment, dst int) error {
|
||||
return fmt.Errorf("unable to copy data to dest file: %v", err)
|
||||
}
|
||||
|
||||
database.C.Save(&meta)
|
||||
cleanupDst()
|
||||
return nil
|
||||
case models.DestinationTypeS3:
|
||||
@ -106,7 +108,6 @@ func ReUploadFile(meta models.Attachment, dst int) error {
|
||||
return fmt.Errorf("unable to upload file to s3: %v", err)
|
||||
}
|
||||
|
||||
database.C.Save(&meta)
|
||||
cleanupDst()
|
||||
return nil
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user