feat: add CIDExists
This commit is contained in:
parent
47602854a0
commit
62e22d0d39
|
@ -5,4 +5,7 @@ import "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)
|
||||||
|
CIDExists(cid interface {
|
||||||
|
ToString() (string, error)
|
||||||
|
}) bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package storage
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||||
|
"git.lumeweb.com/LumeWeb/portal/db/models"
|
||||||
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -105,3 +106,17 @@ func (s *StorageServiceImpl) createBucketIfNotExists(bucket string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StorageServiceImpl) CIDExists(cid interface {
|
||||||
|
ToString() (string, error)
|
||||||
|
}) bool {
|
||||||
|
cidStr, err := cid.ToString()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var count int64
|
||||||
|
s.portal.Db().Model(&models.Upload{}).Where(&models.Upload{CID: cidStr}).Count(&count)
|
||||||
|
|
||||||
|
return count > 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue