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 +}