feat: add storage CreateUpload

This commit is contained in:
Derrick Hammer 2024-01-17 14:46:22 -05:00
parent d16731807c
commit 8c4687fd67
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 20 additions and 0 deletions

View File

@ -10,4 +10,5 @@ type StorageService interface {
PutFile(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error) PutFile(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error)
FileExists(hash []byte) (bool, models.Upload) FileExists(hash []byte) (bool, models.Upload)
GetHash(file io.ReadSeeker) ([]byte, error) GetHash(file io.ReadSeeker) ([]byte, error)
CreateUpload(hash []byte, uploaderID uint, uploaderIP string, size uint64, protocol string) (*models.Upload, error)
} }

View File

@ -129,3 +129,22 @@ func (s *StorageServiceImpl) GetHash(file io.ReadSeeker) ([]byte, error) {
return hash[:], nil 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
}