refactor: rename CIDExists to FileExists and have it work on hashes and check in hex format
This commit is contained in:
parent
48f03c0f47
commit
866d105028
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue