fix: issues

This commit is contained in:
Rogee
2024-12-06 16:13:28 +08:00
parent 233847f233
commit 7d9ec4ef81
5 changed files with 54 additions and 4 deletions

View File

@@ -3,8 +3,10 @@ package tasks
import ( import (
"backend/modules/medias" "backend/modules/medias"
"backend/modules/tasks/discover" "backend/modules/tasks/discover"
"backend/modules/tasks/store"
"backend/providers/app" "backend/providers/app"
"backend/providers/postgres" "backend/providers/postgres"
"backend/providers/storage"
"git.ipao.vip/rogeecn/atom" "git.ipao.vip/rogeecn/atom"
"git.ipao.vip/rogeecn/atom/container" "git.ipao.vip/rogeecn/atom/container"
@@ -14,6 +16,7 @@ import (
func defaultProviders(providers ...container.ProviderContainer) container.Providers { func defaultProviders(providers ...container.ProviderContainer) container.Providers {
return append(container.Providers{ return append(container.Providers{
app.DefaultProvider(), app.DefaultProvider(),
storage.DefaultProvider(),
postgres.DefaultProvider(), postgres.DefaultProvider(),
}, providers...) }, providers...)
} }
@@ -39,5 +42,21 @@ func Command() atom.Option {
}) })
}), }),
), ),
atom.Command(
atom.Name("store"),
atom.Providers(defaultProviders().With(
medias.Provide,
store.Provide,
)),
atom.Arguments(func(cmd *cobra.Command) {
cmd.Flags().String("from", "", "from path")
}),
atom.RunE(func(cmd *cobra.Command, args []string) error {
return container.Container.Invoke(func(task *store.StoreMedias) error {
from := cmd.Flag("from").Value.String()
return task.RunE(from)
})
}),
),
) )
} }

View File

@@ -29,4 +29,4 @@ Salt = "LiXi.Y@140202"
[Storage] [Storage]
Type = "local" Type = "local"
Path = "/mnt/yangpingliang/publish/processed" Path = "/projects/mp-qvyun/backend/fixtures/processed"

View File

@@ -2,6 +2,7 @@ package medias
import ( import (
"backend/providers/http" "backend/providers/http"
"backend/providers/storage"
"database/sql" "database/sql"
"git.ipao.vip/rogeecn/atom" "git.ipao.vip/rogeecn/atom"
@@ -37,9 +38,11 @@ func Provide(opts ...opt.Option) error {
if err := container.Container.Provide(func( if err := container.Container.Provide(func(
db *sql.DB, db *sql.DB,
storageConfig *storage.Config,
) (*Service, error) { ) (*Service, error) {
obj := &Service{ obj := &Service{
db: db, db: db,
storageConfig: storageConfig,
} }
if err := obj.Prepare(); err != nil { if err := obj.Prepare(); err != nil {
return nil, err return nil, err

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"path/filepath" "path/filepath"
"time"
"backend/common/media_store" "backend/common/media_store"
"backend/database/models/qvyun/public/table" "backend/database/models/qvyun/public/table"
@@ -182,14 +183,15 @@ func (svc *Service) Upsert(ctx context.Context, tenantId int64, item media_store
tbl := table.Medias tbl := table.Medias
stmt := tbl. stmt := tbl.
INSERT(tbl.TenantID, tbl.Hash, tbl.Title, tbl.Price, tbl.Resources, tbl.Publish). INSERT(tbl.TenantID, tbl.Hash, tbl.Title, tbl.Price, tbl.Resources, tbl.Publish).
VALUES(Int(tenantId), String(item.Hash), String(item.Name), Int(item.Price()), Json(resources), Bool(true)). VALUES(Int(tenantId), String(item.Hash), String(item.Name), Int(item.Price()), Json(resources.MustValue()), Bool(true)).
ON_CONFLICT(tbl.Hash). ON_CONFLICT(tbl.Hash).
DO_UPDATE( DO_UPDATE(
SET( SET(
tbl.Title.SET(String(item.Name)), tbl.Title.SET(String(item.Name)),
tbl.Price.SET(Int(item.Price())), tbl.Price.SET(Int(item.Price())),
tbl.Resources.SET(Json(resources)), tbl.Resources.SET(Json(resources.MustValue())),
tbl.Publish.SET(Bool(true)), tbl.Publish.SET(Bool(true)),
tbl.UpdatedAt.SET(TimestampT(time.Now())),
), ),
) )
log.Debug(stmt.DebugSql()) log.Debug(stmt.DebugSql())

View File

@@ -0,0 +1,26 @@
package store
import (
"backend/modules/medias"
"git.ipao.vip/rogeecn/atom/container"
"git.ipao.vip/rogeecn/atom/utils/opt"
)
func Provide(opts ...opt.Option) error {
if err := container.Container.Provide(func(
mediasSvc *medias.Service,
) (*StoreMedias, error) {
obj := &StoreMedias{
mediasSvc: mediasSvc,
}
if err := obj.Prepare(); err != nil {
return nil, err
}
return obj, nil
}); err != nil {
return err
}
return nil
}