🐛 Bug fixes on fragment based uploading
This commit is contained in:
@ -99,9 +99,7 @@ func ScanUnanalyzedFileFromDatabase() {
|
||||
}
|
||||
|
||||
func AnalyzeAttachment(file models.Attachment) error {
|
||||
if !file.IsUploaded {
|
||||
return fmt.Errorf("file isn't finish multipart upload")
|
||||
} else if file.Destination != models.AttachmentDstTemporary {
|
||||
if file.Destination != models.AttachmentDstTemporary {
|
||||
return fmt.Errorf("attachment isn't in temporary storage, unable to analyze")
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,7 @@ func MergeFileChunks(meta models.AttachmentFragment, arrange []string) (models.A
|
||||
PublishAnalyzeTask(attachment)
|
||||
|
||||
// Clean up: remove chunk files
|
||||
go DeleteFragment(meta)
|
||||
for _, chunk := range arrange {
|
||||
chunkPath := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, chunk))
|
||||
if err := os.Remove(chunkPath); err != nil {
|
||||
|
@ -79,21 +79,21 @@ func RunScheduleDeletionTask() {
|
||||
database.C.Where("cleaned_at IS NOT NULL").Delete(&models.Attachment{})
|
||||
}
|
||||
|
||||
func DeleteFile(meta models.Attachment) error {
|
||||
if !meta.IsUploaded {
|
||||
destMap := viper.GetStringMap("destinations.0")
|
||||
var dest models.LocalDestination
|
||||
rawDest, _ := jsoniter.Marshal(destMap)
|
||||
_ = jsoniter.Unmarshal(rawDest, &dest)
|
||||
func DeleteFragment(meta models.AttachmentFragment) error {
|
||||
destMap := viper.GetStringMap("destinations.0")
|
||||
var dest models.LocalDestination
|
||||
rawDest, _ := jsoniter.Marshal(destMap)
|
||||
_ = jsoniter.Unmarshal(rawDest, &dest)
|
||||
|
||||
for cid := range meta.FileChunks {
|
||||
path := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, cid))
|
||||
_ = os.Remove(path)
|
||||
}
|
||||
|
||||
return nil
|
||||
for cid := range meta.FileChunks {
|
||||
path := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, cid))
|
||||
_ = os.Remove(path)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteFile(meta models.Attachment) error {
|
||||
destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", meta.Destination))
|
||||
|
||||
var dest models.BaseDestination
|
||||
|
Reference in New Issue
Block a user