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
|
package interfaces
|
||||||
|
|
||||||
import "io"
|
import (
|
||||||
|
"git.lumeweb.com/LumeWeb/portal/db/models"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
type StorageService interface {
|
type StorageService interface {
|
||||||
Init()
|
Init()
|
||||||
PutFile(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error)
|
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)
|
GetHash(file io.ReadSeeker) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,13 +105,13 @@ func (s *StorageServiceImpl) createBucketIfNotExists(bucket string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StorageServiceImpl) FileExists(hash []byte) bool {
|
func (s *StorageServiceImpl) FileExists(hash []byte) (bool, models.Upload) {
|
||||||
hashStr := hex.EncodeToString(hash)
|
hashStr := hex.EncodeToString(hash)
|
||||||
|
|
||||||
var count int64
|
var upload models.Upload
|
||||||
s.portal.Db().Model(&models.Upload{}).Where(&models.Upload{Hash: hashStr}).Count(&count)
|
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) {
|
func (s *StorageServiceImpl) GetHash(file io.ReadSeeker) ([]byte, error) {
|
||||||
|
|
Loading…
Reference in New Issue