Fragment uploading continue

This commit is contained in:
LittleSheep 2024-12-28 13:56:25 +08:00
parent 30097256b6
commit 99dd7f55e0
4 changed files with 15 additions and 1 deletions

View File

@ -92,6 +92,8 @@ type AttachmentFragment struct {
PoolID *uint `json:"pool_id"` PoolID *uint `json:"pool_id"`
AccountID uint `json:"account_id"` AccountID uint `json:"account_id"`
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) ToAttachment() Attachment { func (v AttachmentFragment) ToAttachment() Attachment {

View File

@ -58,6 +58,8 @@ func createAttachmentFragment(c *fiber.Ctx) error {
}) })
if err != nil { if err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else {
metadata.FileChunksMissing = services.FindFragmentMissingChunks(metadata)
} }
return c.JSON(fiber.Map{ return c.JSON(fiber.Map{

View File

@ -315,7 +315,7 @@ func HashAttachment(file models.Attachment) (hash string, err error) {
} }
// Hash with the file metadata // Hash with the file metadata
hasher.Write([]byte(fmt.Sprintf("%d", file.Size))) fmt.Fprintf(hasher, "%d", file.Size)
// Return the combined hash // Return the combined hash
hash = hex.EncodeToString(hasher.Sum(nil)) hash = hex.EncodeToString(hasher.Sum(nil))

View File

@ -151,3 +151,13 @@ func CheckFragmentChunkExists(meta models.AttachmentFragment, cid string) bool {
return true return true
} }
} }
func FindFragmentMissingChunks(meta models.AttachmentFragment) []string {
var missing []string
for cid := range meta.FileChunks {
if !CheckFragmentChunkExists(meta, cid) {
missing = append(missing, cid)
}
}
return missing
}