From 8c4687fd67131d97598f31e4b2b1dd0d6c499ccb Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 17 Jan 2024 14:46:22 -0500 Subject: [PATCH] feat: add storage CreateUpload --- interfaces/storage.go | 1 + storage/storage.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/interfaces/storage.go b/interfaces/storage.go index 80a37a9..713212f 100644 --- a/interfaces/storage.go +++ b/interfaces/storage.go @@ -10,4 +10,5 @@ type StorageService interface { PutFile(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error) FileExists(hash []byte) (bool, models.Upload) GetHash(file io.ReadSeeker) ([]byte, error) + CreateUpload(hash []byte, uploaderID uint, uploaderIP string, size uint64, protocol string) (*models.Upload, error) } diff --git a/storage/storage.go b/storage/storage.go index bdbb28a..3fd067b 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -129,3 +129,22 @@ func (s *StorageServiceImpl) GetHash(file io.ReadSeeker) ([]byte, error) { return hash[:], nil } +func (s *StorageServiceImpl) CreateUpload(hash []byte, uploaderID uint, uploaderIP string, size uint64, protocol string) (*models.Upload, error) { + hashStr := hex.EncodeToString(hash) + + upload := &models.Upload{ + Hash: hashStr, + UserID: uploaderID, + UploaderIP: uploaderIP, + Protocol: protocol, + Size: size, + } + + result := s.portal.Database().Create(upload) + + if result.Error != nil { + return nil, result.Error + } + + return upload, nil +}