refactor: have FileExists return the upload model if it exists

This commit is contained in:
Derrick Hammer 2024-01-16 01:01:57 -05:00
parent 866d105028
commit a4e0e1fa58
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 9 additions and 6 deletions

View File

@ -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)
}

View File

@ -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) {