Skip to content

Commit

Permalink
return correct document size (from hashtree)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddvk committed Dec 1, 2024
1 parent 8c9d66c commit df07152
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 2 additions & 4 deletions internal/storage/fs/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (fs *FileSystemStorage) CreateBlobDocument(uid, filename, parent string, st
return nil, errors.New("unsupported extension: " + ext)
}

if ext == storage.RmDocFileExt{
if ext == storage.RmDocFileExt {
return nil, errors.New("TODO: not implemented yet")
}

Expand Down Expand Up @@ -376,8 +376,6 @@ func (fs *FileSystemStorage) CreateBlobDocument(uid, filename, parent string, st
payloadEntry = models.NewHashEntry(payloadHash, docid+ext, size)
err = hashDoc.AddFile(payloadEntry)

hashDoc.PayloadSize = size

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -481,7 +479,7 @@ func (fs *FileSystemStorage) LoadBlob(uid, blobid string) (reader io.ReadCloser,
osFile, err := os.Open(blobPath)
if err != nil {
log.Errorf("cannot open blob %v", err)
return
return
}
//TODO: cache the crc32
crc32, err = common.CRC32FromReader(osFile)
Expand Down
13 changes: 11 additions & 2 deletions internal/storage/models/hashdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type HashDoc struct {

//extra fields that are serialized
MetadataFile
//PayloadType
PayloadType string
PayloadSize int64
}

func NewHashDocWithMeta(documentID string, meta MetadataFile) *HashDoc {
Expand Down Expand Up @@ -87,6 +87,11 @@ func (d *HashDoc) MetadataReader() (hash string, reader io.Reader, err error) {
// AddFile adds an entry
func (d *HashDoc) AddFile(e *HashEntry) error {
d.Files = append(d.Files, e)
size := int64(0)
for _, f := range d.Files {
size += f.Size
}
d.Size = size
return d.Rehash()
}

Expand Down Expand Up @@ -180,7 +185,11 @@ func (d *HashDoc) ReadMetadata(fileEntry *HashEntry, r RemoteStorage) error {
return d.readMetadata(fileEntry.Hash, r)
}
if fileEntry.IsContent() {
return d.readContent(fileEntry.Hash, r)
err := d.readContent(fileEntry.Hash, r)
if err != nil {
return err
}

}
return nil

Expand Down
1 change: 1 addition & 0 deletions internal/ui/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (app *ReactAppWrapper) getBackend(c *gin.Context) backend {
}
return backend
}

func (app *ReactAppWrapper) listDocuments(c *gin.Context) {
uid := userID(c)

Expand Down
2 changes: 1 addition & 1 deletion internal/ui/viewmodel/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func DocTreeFromHashTree(tree *models.HashTree) *DocumentTree {
Type: d.MetadataFile.CollectionType,
LastModified: lastModified,
FileType: d.PayloadType,
Size: d.PayloadSize,
Size: d.Size,
})
}

Expand Down

0 comments on commit df07152

Please sign in to comment.