From f3040399e48cf8797d64264cf98da027059433e7 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 9 Mar 2024 15:37:16 -0500 Subject: [PATCH] feat: add GetUploadSize --- protocols/s5/tus.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/protocols/s5/tus.go b/protocols/s5/tus.go index ee20241..50d8cf3 100644 --- a/protocols/s5/tus.go +++ b/protocols/s5/tus.go @@ -309,6 +309,26 @@ func (t *TusHandler) SetStorageProtocol(storageProtocol storage.StorageProtocol) t.storageProtocol = storageProtocol } +func (t *TusHandler) GetUploadSize(ctx context.Context, hash []byte) (int64, error) { + exists, upload := t.UploadExists(ctx, hash) + + if !exists { + return 0, metadata.ErrNotFound + } + + meta, err := t.tusStore.GetUpload(ctx, upload.UploadID) + if err != nil { + return 0, err + } + + info, err := meta.GetInfo(ctx) + if err != nil { + return 0, err + } + + return info.Size, nil +} + func (t *TusHandler) uploadTask(hash []byte) error { ctx := context.Background() exists, upload := t.UploadExists(ctx, hash)