feat: add discover medias
This commit is contained in:
39
backend/common/service/task/cmd.go
Normal file
39
backend/common/service/task/cmd.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"backend/modules/tasks"
|
||||||
|
"backend/providers/app"
|
||||||
|
|
||||||
|
"git.ipao.vip/rogeecn/atom"
|
||||||
|
"git.ipao.vip/rogeecn/atom/container"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func defaultProviders(providers ...container.ProviderContainer) container.Providers {
|
||||||
|
return append(container.Providers{
|
||||||
|
app.DefaultProvider(),
|
||||||
|
}, providers...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Command() atom.Option {
|
||||||
|
return atom.Command(
|
||||||
|
atom.Name("tasks"),
|
||||||
|
atom.Short("run tasks"),
|
||||||
|
atom.Providers(defaultProviders().With(
|
||||||
|
tasks.Provide,
|
||||||
|
)),
|
||||||
|
atom.Command(
|
||||||
|
atom.Name("discover"),
|
||||||
|
atom.Arguments(func(cmd *cobra.Command) {
|
||||||
|
cmd.Flags().String("from", "", "from path")
|
||||||
|
cmd.Flags().String("to", "", "to path")
|
||||||
|
}),
|
||||||
|
atom.RunE(func(cmd *cobra.Command, args []string) error {
|
||||||
|
return container.Container.Invoke(func(task *tasks.DiscoverMedias) error {
|
||||||
|
from, to := cmd.Flag("from").Value.String(), cmd.Flag("to").Value.String()
|
||||||
|
return task.RunE(from, to)
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -11,23 +11,22 @@ import (
|
|||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @provider
|
// @provider
|
||||||
type DiscoverMedias struct {
|
type DiscoverMedias struct {
|
||||||
mediasSvc *medias.Service
|
mediasSvc *medias.Service
|
||||||
|
log *log.Entry
|
||||||
log *logrus.Entry `inject:"false"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepare
|
||||||
func (d *DiscoverMedias) Prepare() error {
|
func (d *DiscoverMedias) Prepare() error {
|
||||||
d.log = log.WithField("module", "DiscoverMedias")
|
d.log = log.WithField("module", "DiscoverMedias")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DiscoverMedias) Run(from, to string) error {
|
func (d *DiscoverMedias) RunE(from, to string) error {
|
||||||
d.log.Infof("Discover medias from: %s to: %s", from, to)
|
d.log.Infof("Discover medias from: %s to: %s", from, to)
|
||||||
|
|
||||||
mapFile := filepath.Join(to, "map.json")
|
mapFile := filepath.Join(to, "map.json")
|
||||||
|
|||||||
Reference in New Issue
Block a user