feat: add tenant commands
This commit is contained in:
41
backend/modules/commands/store/store_medias.go
Normal file
41
backend/modules/commands/store/store_medias.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"backend/common/media_store"
|
||||
"backend/modules/medias"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type StoreMedias struct {
|
||||
mediasSvc *medias.Service
|
||||
log *log.Entry `inject:"false"`
|
||||
}
|
||||
|
||||
// Prepare
|
||||
func (d *StoreMedias) Prepare() error {
|
||||
d.log = log.WithField("module", "StoreMedias")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *StoreMedias) RunE(targetPath string) error {
|
||||
d.log.Infof("Store medias from: %s ", targetPath)
|
||||
|
||||
store, err := media_store.NewStore(targetPath)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "new store: %s", targetPath)
|
||||
}
|
||||
|
||||
for _, item := range store {
|
||||
err := d.mediasSvc.Upsert(context.Background(), 1, item)
|
||||
if err != nil {
|
||||
d.log.WithError(err).Errorf("upsert media: %s - %s", item.Hash, item.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user