refactor: add checking tus for metadata before uploads

This commit is contained in:
Derrick Hammer 2024-03-09 15:37:58 -05:00
parent f3040399e4
commit 0c90924f31
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 18 additions and 0 deletions

View File

@ -181,6 +181,24 @@ func (f *S5File) init(offset int64) error {
func (f *S5File) Record() (*metadata.UploadMetadata, error) {
if f.record == nil {
exists, tusRecord := f.tus.UploadExists(context.Background(), f.hash)
if exists {
size, err := f.tus.GetUploadSize(context.Background(), f.hash)
if err != nil {
return nil, err
}
return &metadata.UploadMetadata{
Hash: f.hash,
Size: uint64(size),
MimeType: tusRecord.MimeType,
Created: tusRecord.CreatedAt,
Protocol: f.protocol.Name(),
UploaderIP: tusRecord.UploaderIP,
UserID: tusRecord.UploaderID,
}, nil
}
record, err := f.metadata.GetUpload(context.Background(), f.hash)
if err != nil {