refactor: rename CIDExists to FileExists and have it work on hashes and check in hex format

This commit is contained in:
Derrick Hammer 2024-01-16 00:58:51 -05:00
parent 48f03c0f47
commit 866d105028
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 5 additions and 11 deletions

View File

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

View File

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