feat: add storage CreateUpload
This commit is contained in:
parent
d16731807c
commit
8c4687fd67
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue