Compare commits
2 Commits
d979f85f68
...
1955d94414
Author | SHA1 | Date | |
---|---|---|---|
|
1955d94414 | ||
|
0e0ad9c261 |
@@ -86,6 +86,10 @@ func (v *Attachment) AfterUpdate(tx *gorm.DB) error {
|
|||||||
ctx,
|
ctx,
|
||||||
fmt.Sprintf("attachment#%s", v.Rid),
|
fmt.Sprintf("attachment#%s", v.Rid),
|
||||||
)
|
)
|
||||||
|
_ = marshal.Delete(
|
||||||
|
ctx,
|
||||||
|
fmt.Sprintf("attachment-open#%s", v.Rid),
|
||||||
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -119,6 +123,19 @@ type AttachmentFragment struct {
|
|||||||
FileChunksMissing []string `json:"file_chunks_missing" gorm:"-"` // This field use to prompt client which chunks is pending upload, do not store it
|
FileChunksMissing []string `json:"file_chunks_missing" gorm:"-"` // This field use to prompt client which chunks is pending upload, do not store it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *AttachmentFragment) AfterUpdate(tx *gorm.DB) error {
|
||||||
|
cacheManager := cache.New[any](localCache.S)
|
||||||
|
marshal := marshaler.New(cacheManager)
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
_ = marshal.Delete(
|
||||||
|
ctx,
|
||||||
|
fmt.Sprintf("attachment-fragment#%s", v.Rid),
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (v AttachmentFragment) ToAttachment() Attachment {
|
func (v AttachmentFragment) ToAttachment() Attachment {
|
||||||
return Attachment{
|
return Attachment{
|
||||||
Rid: v.Rid,
|
Rid: v.Rid,
|
||||||
|
@@ -94,7 +94,7 @@ func ActivateBoost(boost models.AttachmentBoost) error {
|
|||||||
return fmt.Errorf("invalid destination: %d", boost.Destination)
|
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...")
|
log.Warn().Any("boost", boost).Err(err).Msg("Unable to activate boost...")
|
||||||
database.C.Model(&boost).Update("status", models.BoostStatusError)
|
database.C.Model(&boost).Update("status", models.BoostStatusError)
|
||||||
return err
|
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 {
|
if meta.Destination == dst {
|
||||||
return fmt.Errorf("destnation cannot be reversed temporary or the same as the original")
|
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() {
|
cleanupDst := func() {
|
||||||
|
if len(doNotUpdate) == 0 || !doNotUpdate[0] {
|
||||||
|
database.C.Save(&meta)
|
||||||
|
}
|
||||||
if prevDst == models.AttachmentDstTemporary {
|
if prevDst == models.AttachmentDstTemporary {
|
||||||
return
|
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)
|
return fmt.Errorf("unable to copy data to dest file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
database.C.Save(&meta)
|
|
||||||
cleanupDst()
|
cleanupDst()
|
||||||
return nil
|
return nil
|
||||||
case models.DestinationTypeS3:
|
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)
|
return fmt.Errorf("unable to upload file to s3: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
database.C.Save(&meta)
|
|
||||||
cleanupDst()
|
cleanupDst()
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user