✨ Fragment uploading continue
This commit is contained in:
parent
30097256b6
commit
99dd7f55e0
@ -92,6 +92,8 @@ type AttachmentFragment struct {
|
||||
PoolID *uint `json:"pool_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 {
|
||||
|
@ -58,6 +58,8 @@ func createAttachmentFragment(c *fiber.Ctx) error {
|
||||
})
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
} else {
|
||||
metadata.FileChunksMissing = services.FindFragmentMissingChunks(metadata)
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
|
@ -315,7 +315,7 @@ func HashAttachment(file models.Attachment) (hash string, err error) {
|
||||
}
|
||||
|
||||
// Hash with the file metadata
|
||||
hasher.Write([]byte(fmt.Sprintf("%d", file.Size)))
|
||||
fmt.Fprintf(hasher, "%d", file.Size)
|
||||
|
||||
// Return the combined hash
|
||||
hash = hex.EncodeToString(hasher.Sum(nil))
|
||||
|
@ -151,3 +151,13 @@ func CheckFragmentChunkExists(meta models.AttachmentFragment, cid string) bool {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user