feat: update by query
This commit is contained in:
@@ -153,7 +153,7 @@ func (d *DiscoverMedias) getFileMD5(filePath string) (string, error) {
|
||||
}
|
||||
|
||||
// extractAudio extract audio from video
|
||||
func (d *DiscoverMedias) extractAudio(video string, output string) error {
|
||||
func (d *DiscoverMedias) extractAudio(video, output string) error {
|
||||
args := []string{
|
||||
"-i", video,
|
||||
"-vn",
|
||||
@@ -303,7 +303,7 @@ func (d *DiscoverMedias) runCleanup(to string) {
|
||||
}
|
||||
|
||||
// getSnapshot get the snapshot of target seconds of a video
|
||||
func (d *DiscoverMedias) ffmpegVideoToPoster(video string, output string) error {
|
||||
func (d *DiscoverMedias) ffmpegVideoToPoster(video, output string) error {
|
||||
args := []string{
|
||||
"-y", // 添加 -y 参数强制覆盖
|
||||
"-i", video,
|
||||
|
||||
@@ -21,6 +21,5 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -21,6 +21,5 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Container.Provide(func(
|
||||
userSvc *users.Service,
|
||||
) (*Create, error) {
|
||||
@@ -35,7 +34,6 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Container.Provide(func(
|
||||
userSvc *users.Service,
|
||||
) (*Expire, error) {
|
||||
@@ -49,6 +47,5 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
hashids "github.com/speps/go-hashids/v2"
|
||||
"github.com/speps/go-hashids/v2"
|
||||
)
|
||||
|
||||
// @provider
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"git.ipao.vip/rogeecn/atom/container"
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
"git.ipao.vip/rogeecn/atom/utils/opt"
|
||||
hashids "github.com/speps/go-hashids/v2"
|
||||
"github.com/speps/go-hashids/v2"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
@@ -24,7 +24,6 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Container.Provide(func(
|
||||
controller *Controller,
|
||||
) (contracts.HttpRoute, error) {
|
||||
@@ -38,7 +37,6 @@ func Provide(opts ...opt.Option) error {
|
||||
}, atom.GroupRoutes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Container.Provide(func(
|
||||
db *sql.DB,
|
||||
hashIds *hashids.HashID,
|
||||
@@ -56,6 +54,5 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"backend/providers/storage"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/qrm"
|
||||
"github.com/grafov/m3u8"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/samber/lo"
|
||||
@@ -163,7 +164,7 @@ func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *Li
|
||||
}
|
||||
|
||||
// GetUserBoughtMedias
|
||||
func (svc *Service) GetUserBoughtMedias(ctx context.Context, tenant int64, userID int64) ([]int64, error) {
|
||||
func (svc *Service) GetUserBoughtMedias(ctx context.Context, tenant, userID int64) ([]int64, error) {
|
||||
log := svc.log.WithField("method", "GetUserBoughtMedias")
|
||||
|
||||
tbl := table.UserMedias
|
||||
@@ -229,11 +230,21 @@ func (svc *Service) Upsert(ctx context.Context, tenantId int64, item media_store
|
||||
}
|
||||
|
||||
tbl := table.Medias
|
||||
stmt := tbl.
|
||||
INSERT(tbl.TenantID, tbl.Hash, tbl.Title, tbl.Price, tbl.Duration, tbl.Resources, tbl.Publish).
|
||||
VALUES(Int(tenantId), String(item.Hash), String(item.Name), Int(item.Price()), Int(item.Duration), Json(resources.MustValue()), Bool(true)).
|
||||
ON_CONFLICT(tbl.Hash).
|
||||
DO_UPDATE(
|
||||
// if hash exists then update
|
||||
stmt := tbl.SELECT(tbl.ID.AS("id")).WHERE(tbl.Hash.EQ(String(item.Hash)))
|
||||
log.Debug(stmt.DebugSql())
|
||||
|
||||
var m struct {
|
||||
ID int64
|
||||
}
|
||||
if err := stmt.QueryContext(ctx, svc.db, &m); err != nil && !errors.Is(err, qrm.ErrNoRows) {
|
||||
return errors.Wrapf(err, "query media by hash %s", item.Hash)
|
||||
}
|
||||
|
||||
if m.ID > 0 {
|
||||
// update media
|
||||
stmt2 := tbl.
|
||||
UPDATE().
|
||||
SET(
|
||||
tbl.Title.SET(String(item.Name)),
|
||||
tbl.Price.SET(Int(item.Price())),
|
||||
@@ -241,14 +252,29 @@ func (svc *Service) Upsert(ctx context.Context, tenantId int64, item media_store
|
||||
tbl.Duration.SET(Int(item.Duration)),
|
||||
tbl.Publish.SET(Bool(true)),
|
||||
tbl.UpdatedAt.SET(TimestampT(time.Now())),
|
||||
),
|
||||
)
|
||||
log.Debug(stmt.DebugSql())
|
||||
).
|
||||
WHERE(tbl.ID.EQ(Int(m.ID)))
|
||||
log.Debug(stmt2.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
|
||||
return errors.Wrapf(err, "upsert media: %s %s", item.Hash, item.Name)
|
||||
if _, err := stmt2.ExecContext(ctx, svc.db); err != nil {
|
||||
return errors.Wrapf(err, "update media: %s %s", item.Hash, item.Name)
|
||||
}
|
||||
svc.log.Infof("update media: %d %s %s", m.ID, item.Hash, item.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
stmt3 := tbl.
|
||||
INSERT(tbl.TenantID, tbl.Hash, tbl.Title, tbl.Price, tbl.Duration, tbl.Resources, tbl.Publish).
|
||||
VALUES(Int(tenantId), String(item.Hash), String(item.Name), Int(item.Price()), Int(item.Duration), Json(resources.MustValue()), Bool(true)).
|
||||
ON_CONFLICT(tbl.Hash).
|
||||
DO_NOTHING()
|
||||
log.Debug(stmt3.DebugSql())
|
||||
|
||||
if _, err := stmt3.ExecContext(ctx, svc.db); err != nil {
|
||||
return errors.Wrapf(err, "insert into media: %s %s", item.Hash, item.Name)
|
||||
}
|
||||
|
||||
svc.log.Infof("insert media: %s %s", item.Hash, item.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,5 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
hashids "github.com/speps/go-hashids/v2"
|
||||
"github.com/speps/go-hashids/v2"
|
||||
)
|
||||
|
||||
// @provider
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"git.ipao.vip/rogeecn/atom/container"
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
"git.ipao.vip/rogeecn/atom/utils/opt"
|
||||
hashids "github.com/speps/go-hashids/v2"
|
||||
"github.com/speps/go-hashids/v2"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
@@ -23,7 +23,6 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Container.Provide(func(
|
||||
controller *Controller,
|
||||
) (contracts.HttpRoute, error) {
|
||||
@@ -37,7 +36,6 @@ func Provide(opts ...opt.Option) error {
|
||||
}, atom.GroupRoutes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := container.Container.Provide(func(
|
||||
db *sql.DB,
|
||||
hashIds *hashids.HashID,
|
||||
@@ -53,6 +51,5 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -27,6 +27,5 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,6 +26,5 @@ func Provide(opts ...opt.Option) error {
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user