From e0c6c88e7596df805c6b012b094cb47ca2b0c81c Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 22 Jan 2024 17:49:03 -0500 Subject: [PATCH] feat: add TusUploadCompleted method --- interfaces/storage.go | 1 + storage/storage.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/interfaces/storage.go b/interfaces/storage.go index c22fb1b..824d9d4 100644 --- a/interfaces/storage.go +++ b/interfaces/storage.go @@ -21,6 +21,7 @@ type StorageService interface { TusUploadExists(hash []byte) (bool, models.TusUpload) CreateTusUpload(hash []byte, uploadID string, uploaderID uint, uploaderIP string, protocol string) (*models.TusUpload, error) TusUploadProgress(uploadID string) error + TusUploadCompleted(uploadID string) error DeleteTusUpload(uploadID string) error ScheduleTusUpload(uploadID string, attempt int) error Tus() *tusd.Handler diff --git a/storage/storage.go b/storage/storage.go index 468dec1..838778c 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -418,6 +418,21 @@ func (s *StorageServiceImpl) TusUploadProgress(uploadID string) error { return nil } +func (s *StorageServiceImpl) TusUploadCompleted(uploadID string) error { + + find := &models.TusUpload{UploadID: uploadID} + + var upload models.TusUpload + result := s.portal.Database().Model(&models.TusUpload{}).Where(find).First(&upload) + + if result.RowsAffected == 0 { + return errors.New("upload not found") + } + + result = s.portal.Database().Model(&models.TusUpload{}).Where(find).Update("completed", true) + + return nil +} func (s *StorageServiceImpl) DeleteTusUpload(uploadID string) error { result := s.portal.Database().Where(&models.TusUpload{UploadID: uploadID}).Delete(&models.TusUpload{})