🐛 Bug fixes on fragment based uploading
This commit is contained in:
		| @@ -23,8 +23,6 @@ func openAttachment(c *fiber.Ctx) error { | |||||||
| 	metadata, err := services.GetAttachmentByRID(id) | 	metadata, err := services.GetAttachmentByRID(id) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return fiber.NewError(fiber.StatusNotFound) | 		return fiber.NewError(fiber.StatusNotFound) | ||||||
| 	} else if !metadata.IsUploaded { |  | ||||||
| 		return fiber.NewError(fiber.StatusNotFound, "file is in uploading progress, please wait until all chunk uploaded") |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", metadata.Destination)) | 	destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", metadata.Destination)) | ||||||
| @@ -91,7 +89,6 @@ func updateAttachmentMeta(c *fiber.Ctx) error { | |||||||
|  |  | ||||||
| 	var data struct { | 	var data struct { | ||||||
| 		Alternative *string         `json:"alt"` | 		Alternative *string         `json:"alt"` | ||||||
| 		Thumbnail   *string         `json:"thumbnail"` |  | ||||||
| 		Metadata    *map[string]any `json:"metadata"` | 		Metadata    *map[string]any `json:"metadata"` | ||||||
| 		IsIndexable *bool           `json:"is_indexable"` | 		IsIndexable *bool           `json:"is_indexable"` | ||||||
| 	} | 	} | ||||||
| @@ -108,9 +105,6 @@ func updateAttachmentMeta(c *fiber.Ctx) error { | |||||||
| 	if data.Alternative != nil { | 	if data.Alternative != nil { | ||||||
| 		attachment.Alternative = *data.Alternative | 		attachment.Alternative = *data.Alternative | ||||||
| 	} | 	} | ||||||
| 	if data.Thumbnail != nil { |  | ||||||
| 		attachment.Thumbnail = *data.Thumbnail |  | ||||||
| 	} |  | ||||||
| 	if data.Metadata != nil { | 	if data.Metadata != nil { | ||||||
| 		attachment.Usermeta = *data.Metadata | 		attachment.Usermeta = *data.Metadata | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -48,7 +48,6 @@ func createAttachmentDirectly(c *fiber.Ctx) error { | |||||||
| 		MimeType:    c.FormValue("mimetype"), | 		MimeType:    c.FormValue("mimetype"), | ||||||
| 		Usermeta:    usermeta, | 		Usermeta:    usermeta, | ||||||
| 		IsAnalyzed:  false, | 		IsAnalyzed:  false, | ||||||
| 		IsUploaded:  true, |  | ||||||
| 		Destination: models.AttachmentDstTemporary, | 		Destination: models.AttachmentDstTemporary, | ||||||
| 		Pool:        &pool, | 		Pool:        &pool, | ||||||
| 		PoolID:      &pool.ID, | 		PoolID:      &pool.ID, | ||||||
|   | |||||||
| @@ -99,9 +99,7 @@ func ScanUnanalyzedFileFromDatabase() { | |||||||
| } | } | ||||||
|  |  | ||||||
| func AnalyzeAttachment(file models.Attachment) error { | func AnalyzeAttachment(file models.Attachment) error { | ||||||
| 	if !file.IsUploaded { | 	if file.Destination != models.AttachmentDstTemporary { | ||||||
| 		return fmt.Errorf("file isn't finish multipart upload") |  | ||||||
| 	} else if file.Destination != models.AttachmentDstTemporary { |  | ||||||
| 		return fmt.Errorf("attachment isn't in temporary storage, unable to analyze") | 		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) | 	PublishAnalyzeTask(attachment) | ||||||
|  |  | ||||||
| 	// Clean up: remove chunk files | 	// Clean up: remove chunk files | ||||||
|  | 	go DeleteFragment(meta) | ||||||
| 	for _, chunk := range arrange { | 	for _, chunk := range arrange { | ||||||
| 		chunkPath := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, chunk)) | 		chunkPath := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, chunk)) | ||||||
| 		if err := os.Remove(chunkPath); err != nil { | 		if err := os.Remove(chunkPath); err != nil { | ||||||
|   | |||||||
| @@ -79,21 +79,21 @@ func RunScheduleDeletionTask() { | |||||||
| 	database.C.Where("cleaned_at IS NOT NULL").Delete(&models.Attachment{}) | 	database.C.Where("cleaned_at IS NOT NULL").Delete(&models.Attachment{}) | ||||||
| } | } | ||||||
|  |  | ||||||
| func DeleteFile(meta models.Attachment) error { | func DeleteFragment(meta models.AttachmentFragment) error { | ||||||
| 	if !meta.IsUploaded { | 	destMap := viper.GetStringMap("destinations.0") | ||||||
| 		destMap := viper.GetStringMap("destinations.0") | 	var dest models.LocalDestination | ||||||
| 		var dest models.LocalDestination | 	rawDest, _ := jsoniter.Marshal(destMap) | ||||||
| 		rawDest, _ := jsoniter.Marshal(destMap) | 	_ = jsoniter.Unmarshal(rawDest, &dest) | ||||||
| 		_ = jsoniter.Unmarshal(rawDest, &dest) |  | ||||||
|  |  | ||||||
| 		for cid := range meta.FileChunks { | 	for cid := range meta.FileChunks { | ||||||
| 			path := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, cid)) | 		path := filepath.Join(dest.Path, fmt.Sprintf("%s.part%s", meta.Uuid, cid)) | ||||||
| 			_ = os.Remove(path) | 		_ = os.Remove(path) | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		return nil |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func DeleteFile(meta models.Attachment) error { | ||||||
| 	destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", meta.Destination)) | 	destMap := viper.GetStringMap(fmt.Sprintf("destinations.%d", meta.Destination)) | ||||||
|  |  | ||||||
| 	var dest models.BaseDestination | 	var dest models.BaseDestination | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user