From 0c90924f319f3bb65ba15f33342a0d7044e25e1d Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 9 Mar 2024 15:37:58 -0500 Subject: [PATCH] refactor: add checking tus for metadata before uploads --- api/s5/file.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/api/s5/file.go b/api/s5/file.go index a1ed73e..33b8aa2 100644 --- a/api/s5/file.go +++ b/api/s5/file.go @@ -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 {