refactor: have FileExists return the upload model if it exists
This commit is contained in:
parent
866d105028
commit
a4e0e1fa58
|
@ -1,10 +1,13 @@
|
|||
package interfaces
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"git.lumeweb.com/LumeWeb/portal/db/models"
|
||||
"io"
|
||||
)
|
||||
|
||||
type StorageService interface {
|
||||
Init()
|
||||
PutFile(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error)
|
||||
FileExists(hash []byte) bool
|
||||
FileExists(hash []byte) (bool, models.Upload)
|
||||
GetHash(file io.ReadSeeker) ([]byte, error)
|
||||
}
|
||||
|
|
|
@ -105,13 +105,13 @@ func (s *StorageServiceImpl) createBucketIfNotExists(bucket string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) FileExists(hash []byte) bool {
|
||||
func (s *StorageServiceImpl) FileExists(hash []byte) (bool, models.Upload) {
|
||||
hashStr := hex.EncodeToString(hash)
|
||||
|
||||
var count int64
|
||||
s.portal.Db().Model(&models.Upload{}).Where(&models.Upload{Hash: hashStr}).Count(&count)
|
||||
var upload models.Upload
|
||||
result := s.portal.Db().Model(&models.Upload{}).Where(&models.Upload{Hash: hashStr}).First(&upload)
|
||||
|
||||
return count > 0
|
||||
return result.RowsAffected > 0, upload
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) GetHash(file io.ReadSeeker) ([]byte, error) {
|
||||
|
|
Loading…
Reference in New Issue