diff --git a/interfaces/storage.go b/interfaces/storage.go index 974bf94..b43020d 100644 --- a/interfaces/storage.go +++ b/interfaces/storage.go @@ -5,8 +5,6 @@ import "io" type StorageService interface { Init() PutFile(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error) - CIDExists(cid interface { - ToString() (string, error) - }) bool + FileExists(hash []byte) bool GetHash(file io.ReadSeeker) ([]byte, error) } diff --git a/storage/storage.go b/storage/storage.go index dd63094..a7579c1 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -2,6 +2,7 @@ package storage import ( "bytes" + "encoding/hex" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/portal/db/models" "git.lumeweb.com/LumeWeb/portal/interfaces" @@ -104,16 +105,11 @@ func (s *StorageServiceImpl) createBucketIfNotExists(bucket string) error { return nil } -func (s *StorageServiceImpl) CIDExists(cid interface { - ToString() (string, error) -}) bool { - cidStr, err := cid.ToString() - if err != nil { - return false - } +func (s *StorageServiceImpl) FileExists(hash []byte) bool { + hashStr := hex.EncodeToString(hash) var count int64 - s.portal.Db().Model(&models.Upload{}).Where(&models.Upload{CID: cidStr}).Count(&count) + s.portal.Db().Model(&models.Upload{}).Where(&models.Upload{Hash: hashStr}).Count(&count) return count > 0 }