refactor: change struct naming convention from "impl" to "default"
This commit is contained in:
parent
8449b13a4a
commit
6d34f5b683
|
@ -22,24 +22,24 @@ var Module = fx.Module("account",
|
|||
),
|
||||
)
|
||||
|
||||
type AccountServiceImpl struct {
|
||||
type AccountServiceDefault struct {
|
||||
db *gorm.DB
|
||||
config *viper.Viper
|
||||
identity ed25519.PrivateKey
|
||||
}
|
||||
|
||||
func NewAccountService(params AccountServiceParams) *AccountServiceImpl {
|
||||
return &AccountServiceImpl{db: params.Db, config: params.Config, identity: params.Identity}
|
||||
func NewAccountService(params AccountServiceParams) *AccountServiceDefault {
|
||||
return &AccountServiceDefault{db: params.Db, config: params.Config, identity: params.Identity}
|
||||
}
|
||||
|
||||
func (s AccountServiceImpl) EmailExists(email string) (bool, models.User) {
|
||||
func (s AccountServiceDefault) EmailExists(email string) (bool, models.User) {
|
||||
var user models.User
|
||||
|
||||
result := s.db.Model(&models.User{}).Where(&models.User{Email: email}).First(&user)
|
||||
|
||||
return result.RowsAffected > 0, user
|
||||
}
|
||||
func (s AccountServiceImpl) PubkeyExists(pubkey string) (bool, models.PublicKey) {
|
||||
func (s AccountServiceDefault) PubkeyExists(pubkey string) (bool, models.PublicKey) {
|
||||
var model models.PublicKey
|
||||
|
||||
result := s.db.Model(&models.PublicKey{}).Where(&models.PublicKey{Key: pubkey}).First(&model)
|
||||
|
@ -47,14 +47,14 @@ func (s AccountServiceImpl) PubkeyExists(pubkey string) (bool, models.PublicKey)
|
|||
return result.RowsAffected > 0, model
|
||||
}
|
||||
|
||||
func (s AccountServiceImpl) AccountExists(id uint64) (bool, models.User) {
|
||||
func (s AccountServiceDefault) AccountExists(id uint64) (bool, models.User) {
|
||||
var model models.User
|
||||
|
||||
result := s.db.Model(&models.User{}).First(&model, id)
|
||||
|
||||
return result.RowsAffected > 0, model
|
||||
}
|
||||
func (s AccountServiceImpl) CreateAccount(email string, password string) (*models.User, error) {
|
||||
func (s AccountServiceDefault) CreateAccount(email string, password string) (*models.User, error) {
|
||||
var user models.User
|
||||
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
|
@ -73,7 +73,7 @@ func (s AccountServiceImpl) CreateAccount(email string, password string) (*model
|
|||
|
||||
return &user, nil
|
||||
}
|
||||
func (s AccountServiceImpl) AddPubkeyToAccount(user models.User, pubkey string) error {
|
||||
func (s AccountServiceDefault) AddPubkeyToAccount(user models.User, pubkey string) error {
|
||||
var model models.PublicKey
|
||||
|
||||
model.Key = pubkey
|
||||
|
@ -87,7 +87,7 @@ func (s AccountServiceImpl) AddPubkeyToAccount(user models.User, pubkey string)
|
|||
|
||||
return nil
|
||||
}
|
||||
func (s AccountServiceImpl) LoginPassword(email string, password string) (string, error) {
|
||||
func (s AccountServiceDefault) LoginPassword(email string, password string) (string, error) {
|
||||
var user models.User
|
||||
|
||||
result := s.db.Model(&models.User{}).Where(&models.User{Email: email}).First(&user)
|
||||
|
@ -109,7 +109,7 @@ func (s AccountServiceImpl) LoginPassword(email string, password string) (string
|
|||
return token, nil
|
||||
}
|
||||
|
||||
func (s AccountServiceImpl) LoginPubkey(pubkey string) (string, error) {
|
||||
func (s AccountServiceDefault) LoginPubkey(pubkey string) (string, error) {
|
||||
var model models.PublicKey
|
||||
|
||||
result := s.db.Model(&models.PublicKey{}).Where(&models.PublicKey{Key: pubkey}).First(&model)
|
||||
|
@ -126,7 +126,7 @@ func (s AccountServiceImpl) LoginPubkey(pubkey string) (string, error) {
|
|||
return token, nil
|
||||
}
|
||||
|
||||
func (s AccountServiceImpl) AccountPins(id uint64, createdAfter uint64) ([]models.Pin, error) {
|
||||
func (s AccountServiceDefault) AccountPins(id uint64, createdAfter uint64) ([]models.Pin, error) {
|
||||
var pins []models.Pin
|
||||
|
||||
result := s.db.Model(&models.Pin{}).
|
||||
|
@ -143,7 +143,7 @@ func (s AccountServiceImpl) AccountPins(id uint64, createdAfter uint64) ([]model
|
|||
return pins, nil
|
||||
}
|
||||
|
||||
func (s AccountServiceImpl) DeletePinByHash(hash string, accountID uint) error {
|
||||
func (s AccountServiceDefault) DeletePinByHash(hash string, accountID uint) error {
|
||||
// Define a struct for the query condition
|
||||
uploadQuery := models.Upload{Hash: hash}
|
||||
|
||||
|
@ -175,7 +175,7 @@ func (s AccountServiceImpl) DeletePinByHash(hash string, accountID uint) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
func (s AccountServiceImpl) PinByHash(hash string, accountID uint) error {
|
||||
func (s AccountServiceDefault) PinByHash(hash string, accountID uint) error {
|
||||
// Define a struct for the query condition
|
||||
uploadQuery := models.Upload{Hash: hash}
|
||||
|
||||
|
@ -193,7 +193,7 @@ func (s AccountServiceImpl) PinByHash(hash string, accountID uint) error {
|
|||
return s.PinByID(uploadID, accountID)
|
||||
}
|
||||
|
||||
func (s AccountServiceImpl) PinByID(uploadId uint, accountID uint) error {
|
||||
func (s AccountServiceDefault) PinByID(uploadId uint, accountID uint) error {
|
||||
result := s.db.Model(&models.Pin{}).Where(&models.Pin{UploadID: uploadId, UserID: accountID}).First(&models.Pin{})
|
||||
|
||||
if result.Error != nil && result.Error != gorm.ErrRecordNotFound {
|
||||
|
|
|
@ -43,7 +43,7 @@ func ParseAuthTokenHeader(headers http.Header) string {
|
|||
return authHeader
|
||||
}
|
||||
|
||||
func AuthMiddleware(identity ed25519.PrivateKey, accounts *account.AccountServiceImpl) func(http.Handler) http.Handler {
|
||||
func AuthMiddleware(identity ed25519.PrivateKey, accounts *account.AccountServiceDefault) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
authToken := FindAuthToken(r)
|
||||
|
|
|
@ -82,9 +82,9 @@ type HttpHandler struct {
|
|||
verifier *emailverifier.Verifier
|
||||
config *viper.Viper
|
||||
logger *zap.Logger
|
||||
storage *storage.StorageServiceImpl
|
||||
storage *storage.StorageServiceDefault
|
||||
db *gorm.DB
|
||||
accounts *account.AccountServiceImpl
|
||||
accounts *account.AccountServiceDefault
|
||||
protocol *s5.S5Protocol
|
||||
}
|
||||
|
||||
|
@ -93,9 +93,9 @@ type HttpHandlerParams struct {
|
|||
|
||||
Config *viper.Viper
|
||||
Logger *zap.Logger
|
||||
Storage *storage.StorageServiceImpl
|
||||
Storage *storage.StorageServiceDefault
|
||||
Db *gorm.DB
|
||||
Accounts *account.AccountServiceImpl
|
||||
Accounts *account.AccountServiceDefault
|
||||
Protocol *s5.S5Protocol
|
||||
}
|
||||
|
||||
|
|
10
api/s5/s5.go
10
api/s5/s5.go
|
@ -25,8 +25,8 @@ var (
|
|||
type S5API struct {
|
||||
config *viper.Viper
|
||||
identity ed25519.PrivateKey
|
||||
accounts *account.AccountServiceImpl
|
||||
storage *storage.StorageServiceImpl
|
||||
accounts *account.AccountServiceDefault
|
||||
storage *storage.StorageServiceDefault
|
||||
protocols []protoRegistry.Protocol
|
||||
httpHandler HttpHandler
|
||||
protocol *s5.S5Protocol
|
||||
|
@ -36,8 +36,8 @@ type APIParams struct {
|
|||
fx.In
|
||||
Config *viper.Viper
|
||||
Identity ed25519.PrivateKey
|
||||
Accounts *account.AccountServiceImpl
|
||||
Storage *storage.StorageServiceImpl
|
||||
Accounts *account.AccountServiceDefault
|
||||
Storage *storage.StorageServiceDefault
|
||||
Protocols []protoRegistry.Protocol `group:"protocol"`
|
||||
HttpHandler HttpHandler
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ func (w *s5TusJwtResponseWriter) WriteHeader(statusCode int) {
|
|||
w.ResponseWriter.WriteHeader(statusCode)
|
||||
}
|
||||
|
||||
func BuildS5TusApi(identity ed25519.PrivateKey, accounts *account.AccountServiceImpl, storage *storage.StorageServiceImpl) jape.Handler {
|
||||
func BuildS5TusApi(identity ed25519.PrivateKey, accounts *account.AccountServiceDefault, storage *storage.StorageServiceDefault) jape.Handler {
|
||||
// Create a jape.Handler for your tusHandler
|
||||
tusJapeHandler := func(c jape.Context) {
|
||||
tusHandler := storage.Tus()
|
||||
|
|
18
cron/cron.go
18
cron/cron.go
|
@ -32,7 +32,7 @@ var Module = fx.Module("cron",
|
|||
),
|
||||
)
|
||||
|
||||
type CronServiceImpl struct {
|
||||
type CronServiceDefault struct {
|
||||
scheduler gocron.Scheduler
|
||||
services []CronableService
|
||||
logger *zap.Logger
|
||||
|
@ -56,12 +56,12 @@ type CronJob struct {
|
|||
Options []gocron.JobOption
|
||||
}
|
||||
|
||||
func (c *CronServiceImpl) Scheduler() gocron.Scheduler {
|
||||
func (c *CronServiceDefault) Scheduler() gocron.Scheduler {
|
||||
return c.scheduler
|
||||
}
|
||||
|
||||
func NewCronService(lc fx.Lifecycle, params CronServiceParams) *CronServiceImpl {
|
||||
sc := &CronServiceImpl{
|
||||
func NewCronService(lc fx.Lifecycle, params CronServiceParams) *CronServiceDefault {
|
||||
sc := &CronServiceDefault{
|
||||
logger: params.Logger,
|
||||
scheduler: params.Scheduler,
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ func NewCronService(lc fx.Lifecycle, params CronServiceParams) *CronServiceImpl
|
|||
return sc
|
||||
}
|
||||
|
||||
func (c *CronServiceImpl) start() error {
|
||||
func (c *CronServiceDefault) start() error {
|
||||
for _, service := range c.services {
|
||||
err := service.LoadInitialTasks(c)
|
||||
if err != nil {
|
||||
|
@ -88,11 +88,11 @@ func (c *CronServiceImpl) start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *CronServiceImpl) RegisterService(service CronableService) {
|
||||
func (c *CronServiceDefault) RegisterService(service CronableService) {
|
||||
c.services = append(c.services, service)
|
||||
}
|
||||
|
||||
func (c *CronServiceImpl) RetryableTask(params RetryableTaskParams) CronJob {
|
||||
func (c *CronServiceDefault) RetryableTask(params RetryableTaskParams) CronJob {
|
||||
job := gocron.OneTimeJob(gocron.OneTimeJobStartImmediately())
|
||||
|
||||
if params.Attempt > 0 {
|
||||
|
@ -145,7 +145,7 @@ func (c *CronServiceImpl) RetryableTask(params RetryableTaskParams) CronJob {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *CronServiceImpl) CreateJob(job CronJob) (gocron.Job, error) {
|
||||
func (c *CronServiceDefault) CreateJob(job CronJob) (gocron.Job, error) {
|
||||
ret, err := c.Scheduler().NewJob(job.Job, job.Task, job.Options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -153,7 +153,7 @@ func (c *CronServiceImpl) CreateJob(job CronJob) (gocron.Job, error) {
|
|||
|
||||
return ret, nil
|
||||
}
|
||||
func (c *CronServiceImpl) RerunJob(job CronJob) (gocron.Job, error) {
|
||||
func (c *CronServiceDefault) RerunJob(job CronJob) (gocron.Job, error) {
|
||||
ret, err := c.Scheduler().Update(job.JobId, job.Job, job.Task, job.Options...)
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -29,7 +29,7 @@ var (
|
|||
type S5Protocol struct {
|
||||
config *viper.Viper
|
||||
logger *zap.Logger
|
||||
storage *storage.StorageServiceImpl
|
||||
storage *storage.StorageServiceDefault
|
||||
identity ed25519.PrivateKey
|
||||
node *s5node.Node
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ type S5ProtocolParams struct {
|
|||
fx.In
|
||||
Config *viper.Viper
|
||||
Logger *zap.Logger
|
||||
Storage *storage.StorageServiceImpl
|
||||
Storage *storage.StorageServiceDefault
|
||||
Identity ed25519.PrivateKey
|
||||
ProviderStore *S5ProviderStore
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ func ConfigureS5Protocol(params S5ProtocolParams) (*s5config.NodeConfig, error)
|
|||
return cfg, nil
|
||||
}
|
||||
|
||||
func NewS5ProviderStore(config *viper.Viper, logger *zap.Logger, storage *storage.StorageServiceImpl) *S5ProviderStore {
|
||||
func NewS5ProviderStore(config *viper.Viper, logger *zap.Logger, storage *storage.StorageServiceDefault) *S5ProviderStore {
|
||||
return &S5ProviderStore{
|
||||
config: config,
|
||||
logger: logger,
|
||||
|
@ -205,7 +205,7 @@ func (s *S5Protocol) Stop(ctx context.Context) error {
|
|||
type S5ProviderStore struct {
|
||||
config *viper.Viper
|
||||
logger *zap.Logger
|
||||
storage *storage.StorageServiceImpl
|
||||
storage *storage.StorageServiceDefault
|
||||
}
|
||||
|
||||
func (s S5ProviderStore) CanProvide(hash *encoding.Multihash, kind []types.StorageLocationType) bool {
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||
"git.lumeweb.com/LumeWeb/portal/db/models"
|
||||
"io"
|
||||
"time"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||
"git.lumeweb.com/LumeWeb/portal/db/models"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
type FileImpl struct {
|
||||
reader io.ReadCloser
|
||||
hash []byte
|
||||
storage *StorageServiceImpl
|
||||
storage *StorageServiceDefault
|
||||
record *models.Upload
|
||||
cid *encoding.CID
|
||||
read bool
|
||||
}
|
||||
|
||||
func NewFile(hash []byte, storage *StorageServiceImpl) *FileImpl {
|
||||
func NewFile(hash []byte, storage *StorageServiceDefault) *FileImpl {
|
||||
return &FileImpl{hash: hash, storage: storage, read: false}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ var (
|
|||
)
|
||||
|
||||
type MySQLLocker struct {
|
||||
storage *StorageServiceImpl
|
||||
storage *StorageServiceDefault
|
||||
AcquirerPollInterval time.Duration
|
||||
HolderPollInterval time.Duration
|
||||
db *gorm.DB
|
||||
|
|
|
@ -43,8 +43,8 @@ type StorageServiceParams struct {
|
|||
Config *viper.Viper
|
||||
Logger *zap.Logger
|
||||
Db *gorm.DB
|
||||
Accounts *account.AccountServiceImpl
|
||||
Cron *cron.CronServiceImpl
|
||||
Accounts *account.AccountServiceDefault
|
||||
Cron *cron.CronServiceDefault
|
||||
}
|
||||
|
||||
var Module = fx.Module("storage",
|
||||
|
@ -53,7 +53,7 @@ var Module = fx.Module("storage",
|
|||
),
|
||||
)
|
||||
|
||||
type StorageServiceImpl struct {
|
||||
type StorageServiceDefault struct {
|
||||
busClient *busClient.Client
|
||||
workerClient *workerClient.Client
|
||||
tus *tusd.Handler
|
||||
|
@ -62,20 +62,20 @@ type StorageServiceImpl struct {
|
|||
config *viper.Viper
|
||||
logger *zap.Logger
|
||||
db *gorm.DB
|
||||
accounts *account.AccountServiceImpl
|
||||
cron *cron.CronServiceImpl
|
||||
accounts *account.AccountServiceDefault
|
||||
cron *cron.CronServiceDefault
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) Tus() *tusd.Handler {
|
||||
func (s *StorageServiceDefault) Tus() *tusd.Handler {
|
||||
return s.tus
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) Start() error {
|
||||
func (s *StorageServiceDefault) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewStorageService(params StorageServiceParams) *StorageServiceImpl {
|
||||
return &StorageServiceImpl{
|
||||
func NewStorageService(params StorageServiceParams) *StorageServiceDefault {
|
||||
return &StorageServiceDefault{
|
||||
config: params.Config,
|
||||
logger: params.Logger,
|
||||
db: params.Db,
|
||||
|
@ -84,7 +84,7 @@ func NewStorageService(params StorageServiceParams) *StorageServiceImpl {
|
|||
}
|
||||
}
|
||||
|
||||
func (s StorageServiceImpl) PutFileSmall(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error) {
|
||||
func (s StorageServiceDefault) PutFileSmall(file io.ReadSeeker, bucket string, generateProof bool) ([]byte, error) {
|
||||
hash, err := s.GetHashSmall(file)
|
||||
hashStr, err := encoding.NewMultihash(s.getPrefixedHash(hash)).ToBase64Url()
|
||||
if err != nil {
|
||||
|
@ -109,7 +109,7 @@ func (s StorageServiceImpl) PutFileSmall(file io.ReadSeeker, bucket string, gene
|
|||
|
||||
return hash[:], nil
|
||||
}
|
||||
func (s StorageServiceImpl) PutFile(file io.Reader, bucket string, hash []byte) error {
|
||||
func (s StorageServiceDefault) PutFile(file io.Reader, bucket string, hash []byte) error {
|
||||
hashStr, err := encoding.NewMultihash(s.getPrefixedHash(hash)).ToBase64Url()
|
||||
err = s.createBucketIfNotExists(bucket)
|
||||
if err != nil {
|
||||
|
@ -124,7 +124,7 @@ func (s StorageServiceImpl) PutFile(file io.Reader, bucket string, hash []byte)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) BuildUploadBufferTus(basePath string, preUploadCb TusPreUploadCreateCallback, preFinishCb TusPreFinishResponseCallback) (*tusd.Handler, tusd.DataStore, *s3.Client, error) {
|
||||
func (s *StorageServiceDefault) BuildUploadBufferTus(basePath string, preUploadCb TusPreUploadCreateCallback, preFinishCb TusPreFinishResponseCallback) (*tusd.Handler, tusd.DataStore, *s3.Client, error) {
|
||||
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
||||
if service == s3.ServiceID {
|
||||
return aws.Endpoint{
|
||||
|
@ -172,7 +172,7 @@ func (s *StorageServiceImpl) BuildUploadBufferTus(basePath string, preUploadCb T
|
|||
return handler, store, s3Client, err
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) init() error {
|
||||
func (s *StorageServiceDefault) init() error {
|
||||
|
||||
addr := s.config.GetString("core.sia.url")
|
||||
passwd := s.config.GetString("core.sia.key")
|
||||
|
@ -237,11 +237,11 @@ func (s *StorageServiceImpl) init() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
func (s *StorageServiceImpl) LoadInitialTasks(cron cron.CronService) error {
|
||||
func (s *StorageServiceDefault) LoadInitialTasks(cron cron.CronService) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) createBucketIfNotExists(bucket string) error {
|
||||
func (s *StorageServiceDefault) createBucketIfNotExists(bucket string) error {
|
||||
|
||||
_, err := s.busClient.Bucket(context.Background(), bucket)
|
||||
|
||||
|
@ -267,7 +267,7 @@ func (s *StorageServiceImpl) createBucketIfNotExists(bucket string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) FileExists(hash []byte) (bool, models.Upload) {
|
||||
func (s *StorageServiceDefault) FileExists(hash []byte) (bool, models.Upload) {
|
||||
hashStr := hex.EncodeToString(hash)
|
||||
|
||||
var upload models.Upload
|
||||
|
@ -276,7 +276,7 @@ func (s *StorageServiceImpl) FileExists(hash []byte) (bool, models.Upload) {
|
|||
return result.RowsAffected > 0, upload
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) GetHashSmall(file io.ReadSeeker) ([]byte, error) {
|
||||
func (s *StorageServiceDefault) GetHashSmall(file io.ReadSeeker) ([]byte, error) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
||||
_, err := io.Copy(buf, file)
|
||||
|
@ -288,7 +288,7 @@ func (s *StorageServiceImpl) GetHashSmall(file io.ReadSeeker) ([]byte, error) {
|
|||
|
||||
return hash[:], nil
|
||||
}
|
||||
func (s *StorageServiceImpl) GetHash(file io.Reader) ([]byte, int64, error) {
|
||||
func (s *StorageServiceDefault) GetHash(file io.Reader) ([]byte, int64, error) {
|
||||
hasher := blake3.New(64, nil)
|
||||
|
||||
totalBytes, err := io.Copy(hasher, file)
|
||||
|
@ -302,7 +302,7 @@ func (s *StorageServiceImpl) GetHash(file io.Reader) ([]byte, int64, error) {
|
|||
return hash[:32], totalBytes, nil
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) CreateUpload(hash []byte, mime string, uploaderID uint, uploaderIP string, size uint64, protocol string) (*models.Upload, error) {
|
||||
func (s *StorageServiceDefault) CreateUpload(hash []byte, mime string, uploaderID uint, uploaderIP string, size uint64, protocol string) (*models.Upload, error) {
|
||||
hashStr := hex.EncodeToString(hash)
|
||||
|
||||
upload := &models.Upload{
|
||||
|
@ -322,7 +322,7 @@ func (s *StorageServiceImpl) CreateUpload(hash []byte, mime string, uploaderID u
|
|||
|
||||
return upload, nil
|
||||
}
|
||||
func (s *StorageServiceImpl) tusWorker() {
|
||||
func (s *StorageServiceDefault) tusWorker() {
|
||||
|
||||
for {
|
||||
select {
|
||||
|
@ -392,7 +392,7 @@ func (s *StorageServiceImpl) tusWorker() {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) TusUploadExists(hash []byte) (bool, models.TusUpload) {
|
||||
func (s *StorageServiceDefault) TusUploadExists(hash []byte) (bool, models.TusUpload) {
|
||||
hashStr := hex.EncodeToString(hash)
|
||||
|
||||
var upload models.TusUpload
|
||||
|
@ -401,7 +401,7 @@ func (s *StorageServiceImpl) TusUploadExists(hash []byte) (bool, models.TusUploa
|
|||
return result.RowsAffected > 0, upload
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) CreateTusUpload(hash []byte, uploadID string, uploaderID uint, uploaderIP string, protocol string) (*models.TusUpload, error) {
|
||||
func (s *StorageServiceDefault) CreateTusUpload(hash []byte, uploadID string, uploaderID uint, uploaderIP string, protocol string) (*models.TusUpload, error) {
|
||||
hashStr := hex.EncodeToString(hash)
|
||||
|
||||
upload := &models.TusUpload{
|
||||
|
@ -421,7 +421,7 @@ func (s *StorageServiceImpl) CreateTusUpload(hash []byte, uploadID string, uploa
|
|||
|
||||
return upload, nil
|
||||
}
|
||||
func (s *StorageServiceImpl) TusUploadProgress(uploadID string) error {
|
||||
func (s *StorageServiceDefault) TusUploadProgress(uploadID string) error {
|
||||
|
||||
find := &models.TusUpload{UploadID: uploadID}
|
||||
|
||||
|
@ -440,7 +440,7 @@ func (s *StorageServiceImpl) TusUploadProgress(uploadID string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
func (s *StorageServiceImpl) TusUploadCompleted(uploadID string) error {
|
||||
func (s *StorageServiceDefault) TusUploadCompleted(uploadID string) error {
|
||||
|
||||
find := &models.TusUpload{UploadID: uploadID}
|
||||
|
||||
|
@ -455,7 +455,7 @@ func (s *StorageServiceImpl) TusUploadCompleted(uploadID string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
func (s *StorageServiceImpl) DeleteTusUpload(uploadID string) error {
|
||||
func (s *StorageServiceDefault) DeleteTusUpload(uploadID string) error {
|
||||
result := s.db.Where(&models.TusUpload{UploadID: uploadID}).Delete(&models.TusUpload{})
|
||||
|
||||
if result.Error != nil {
|
||||
|
@ -465,7 +465,7 @@ func (s *StorageServiceImpl) DeleteTusUpload(uploadID string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) ScheduleTusUpload(uploadID string) error {
|
||||
func (s *StorageServiceDefault) ScheduleTusUpload(uploadID string) error {
|
||||
find := &models.TusUpload{UploadID: uploadID}
|
||||
|
||||
var upload models.TusUpload
|
||||
|
@ -498,7 +498,7 @@ func (s *StorageServiceImpl) ScheduleTusUpload(uploadID string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) tusUploadTask(upload *models.TusUpload) error {
|
||||
func (s *StorageServiceDefault) tusUploadTask(upload *models.TusUpload) error {
|
||||
ctx := context.Background()
|
||||
tusUpload, err := s.tusStore.GetUpload(ctx, upload.UploadID)
|
||||
if err != nil {
|
||||
|
@ -605,7 +605,7 @@ func (s *StorageServiceImpl) tusUploadTask(upload *models.TusUpload) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) getPrefixedHash(hash []byte) []byte {
|
||||
func (s *StorageServiceDefault) getPrefixedHash(hash []byte) []byte {
|
||||
return append([]byte{byte(types.HashTypeBlake3)}, hash...)
|
||||
}
|
||||
|
||||
|
@ -620,7 +620,7 @@ func splitS3Ids(id string) (objectId, multipartId string) {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *StorageServiceImpl) GetFile(hash []byte, start int64) (io.ReadCloser, int64, error) {
|
||||
func (s *StorageServiceDefault) GetFile(hash []byte, start int64) (io.ReadCloser, int64, error) {
|
||||
if exists, tusUpload := s.TusUploadExists(hash); exists {
|
||||
if tusUpload.Completed {
|
||||
upload, err := s.tusStore.GetUpload(context.Background(), tusUpload.UploadID)
|
||||
|
@ -675,6 +675,6 @@ func (s *StorageServiceImpl) GetFile(hash []byte, start int64) (io.ReadCloser, i
|
|||
|
||||
return object.Content, int64(upload.Size), nil
|
||||
}
|
||||
func (s *StorageServiceImpl) NewFile(hash []byte) *FileImpl {
|
||||
func (s *StorageServiceDefault) NewFile(hash []byte) *FileImpl {
|
||||
return NewFile(hash, s)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue