feat: add CIDExists

This commit is contained in:
Derrick Hammer 2024-01-16 00:40:50 -05:00
parent 47602854a0
commit 62e22d0d39
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 18 additions and 0 deletions

View File

@ -5,4 +5,7 @@ import "io"
type StorageService interface {
Init()
PutFile(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error)
CIDExists(cid interface {
ToString() (string, error)
}) bool
}

View File

@ -3,6 +3,7 @@ package storage
import (
"bytes"
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
"git.lumeweb.com/LumeWeb/portal/db/models"
"git.lumeweb.com/LumeWeb/portal/interfaces"
"github.com/go-resty/resty/v2"
"go.uber.org/zap"
@ -105,3 +106,17 @@ 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
}
var count int64
s.portal.Db().Model(&models.Upload{}).Where(&models.Upload{CID: cidStr}).Count(&count)
return count > 0
}