feat: update
This commit is contained in:
@@ -3,6 +3,7 @@ package admin
|
||||
import (
|
||||
"quyun/providers/ali"
|
||||
"quyun/providers/app"
|
||||
"quyun/providers/job"
|
||||
"quyun/providers/jwt"
|
||||
|
||||
"go.ipao.vip/atom"
|
||||
@@ -74,10 +75,12 @@ func Provide(opts ...opt.Option) error {
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
app *app.Config,
|
||||
job *job.Job,
|
||||
oss *ali.OSSClient,
|
||||
) (*uploads, error) {
|
||||
obj := &uploads{
|
||||
app: app,
|
||||
job: job,
|
||||
oss: oss,
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ func (up *uploads) PostUploadedAction(ctx fiber.Ctx, body *PostUploadedForm) err
|
||||
}
|
||||
|
||||
if m.MimeType == "video/mp4" {
|
||||
if err := up.job.Add(&jobs.DownloadFromAliOSS{MediaID: m.ID}); err != nil {
|
||||
if err := up.job.Add(&jobs.DownloadFromAliOSS{MediaHash: m.Hash}); err != nil {
|
||||
log.WithError(err).WithField("media", m).Errorf("add job failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
var _ contracts.JobArgs = (*WechatCallback)(nil)
|
||||
|
||||
type DownloadFromAliOSS struct {
|
||||
MediaID int64 `json:"media_id"`
|
||||
MediaHash string `json:"media_hash"`
|
||||
}
|
||||
|
||||
func (s DownloadFromAliOSS) InsertOpts() InsertOpts {
|
||||
@@ -56,7 +56,7 @@ func (w *DownloadFromAliOSSWorker) Work(ctx context.Context, job *Job[DownloadFr
|
||||
log.Infof("[Start] Working on job with strings: %+v", job.Args)
|
||||
defer log.Infof("[End] Finished %s", job.Args.Kind())
|
||||
|
||||
media, err := models.Medias.GetByID(ctx, job.Args.MediaID)
|
||||
media, err := models.Medias.GetByHash(ctx, job.Args.MediaHash)
|
||||
if err != nil {
|
||||
log.Errorf("Error getting media by ID: %v", err)
|
||||
return JobCancel(err)
|
||||
@@ -73,15 +73,15 @@ func (w *DownloadFromAliOSSWorker) Work(ctx context.Context, job *Job[DownloadFr
|
||||
log.Errorf("Error creating directory: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if st.Size() == media.Size {
|
||||
return JobCancel(errors.New("file already downloaded"))
|
||||
} else {
|
||||
// remove file
|
||||
if err := os.Remove(dst); err != nil {
|
||||
log.Errorf("Error removing file: %v", err)
|
||||
return err
|
||||
if st.Size() == media.Size {
|
||||
return JobCancel(errors.New("file already downloaded"))
|
||||
} else {
|
||||
// remove file
|
||||
if err := os.Remove(dst); err != nil {
|
||||
log.Errorf("Error removing file: %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,12 +93,12 @@ func (w *DownloadFromAliOSSWorker) Work(ctx context.Context, job *Job[DownloadFr
|
||||
|
||||
log.Infof("Successfully downloaded file: %s", media.Path)
|
||||
|
||||
if err := w.job.Add(&VideoCut{MediaID: job.Args.MediaID}); err != nil {
|
||||
if err := w.job.Add(&VideoCut{MediaHash: job.Args.MediaHash}); err != nil {
|
||||
log.Errorf("Error adding job: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := w.job.Add(&VideoExtractHeadImage{MediaID: job.Args.MediaID}); err != nil {
|
||||
if err := w.job.Add(&VideoExtractHeadImage{MediaHash: job.Args.MediaHash}); err != nil {
|
||||
log.Errorf("Error adding job: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (t *DownloadFromAliOSSSuite) Test_Work() {
|
||||
Convey("step 1", func() {
|
||||
job := &Job[DownloadFromAliOSS]{
|
||||
Args: DownloadFromAliOSS{
|
||||
MediaID: 3,
|
||||
MediaHash: "959e5310105c96e653f10b74e5bdc36b",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
var _ contracts.JobArgs = (*VideoCut)(nil)
|
||||
|
||||
type VideoCut struct {
|
||||
MediaID int64 `json:"media_id"`
|
||||
MediaHash string `json:"media_hash"`
|
||||
}
|
||||
|
||||
func (s VideoCut) InsertOpts() InsertOpts {
|
||||
@@ -55,7 +55,7 @@ func (w *VideoCutWorker) Work(ctx context.Context, job *Job[VideoCut]) error {
|
||||
log.Infof("[Start] Working on job with strings: %+v", job.Args)
|
||||
defer log.Infof("[End] Finished %s", job.Args.Kind())
|
||||
|
||||
media, err := models.Medias.GetByID(ctx, job.Args.MediaID)
|
||||
media, err := models.Medias.GetByHash(ctx, job.Args.MediaHash)
|
||||
if err != nil {
|
||||
log.Errorf("Error getting media by ID: %v", err)
|
||||
return JobCancel(err)
|
||||
@@ -89,7 +89,7 @@ func (w *VideoCutWorker) Work(ctx context.Context, job *Job[VideoCut]) error {
|
||||
|
||||
// save to database
|
||||
return w.job.Add(&VideoStoreShort{
|
||||
MediaID: media.ID,
|
||||
FilePath: output,
|
||||
MediaHash: media.Hash,
|
||||
FilePath: output,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
var _ contracts.JobArgs = (*VideoExtractHeadImage)(nil)
|
||||
|
||||
type VideoExtractHeadImage struct {
|
||||
MediaID int64 `json:"media_id"`
|
||||
MediaHash string `json:"media_hash"`
|
||||
}
|
||||
|
||||
func (s VideoExtractHeadImage) InsertOpts() InsertOpts {
|
||||
@@ -57,7 +57,7 @@ func (w *VideoExtractHeadImageWorker) Work(ctx context.Context, job *Job[VideoEx
|
||||
log.Infof("[Start] Working on job with strings: %+v", job.Args)
|
||||
defer log.Infof("[End] Finished %s", job.Args.Kind())
|
||||
|
||||
media, err := models.Medias.GetByID(ctx, job.Args.MediaID)
|
||||
media, err := models.Medias.GetByHash(ctx, job.Args.MediaHash)
|
||||
if err != nil {
|
||||
log.Errorf("Error getting media by ID: %v", err)
|
||||
return JobCancel(err)
|
||||
@@ -90,6 +90,7 @@ func (w *VideoExtractHeadImageWorker) Work(ctx context.Context, job *Job[VideoEx
|
||||
log.Errorf("Error getting file MD5: %v", err)
|
||||
return JobCancel(err)
|
||||
}
|
||||
filename := fileMd5 + filepath.Ext(output)
|
||||
|
||||
// create a new media record for the image
|
||||
imageMedia := &model.Medias{
|
||||
@@ -97,7 +98,7 @@ func (w *VideoExtractHeadImageWorker) Work(ctx context.Context, job *Job[VideoEx
|
||||
Name: "[展示图]" + media.Name,
|
||||
MimeType: "image/jpeg",
|
||||
Size: fileSize,
|
||||
Path: w.oss.GetSavePath(filepath.Base(output)),
|
||||
Path: w.oss.GetSavePath(filename),
|
||||
Hash: fileMd5,
|
||||
Metas: fields.Json[fields.MediaMetas]{},
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
var _ contracts.JobArgs = (*VideoStoreShort)(nil)
|
||||
|
||||
type VideoStoreShort struct {
|
||||
MediaID int64 `json:"media_id"`
|
||||
FilePath string `json:"file_path"`
|
||||
MediaHash string `json:"media_hash"`
|
||||
FilePath string `json:"file_path"`
|
||||
}
|
||||
|
||||
func (s VideoStoreShort) InsertOpts() InsertOpts {
|
||||
@@ -57,7 +57,7 @@ func (w *VideoStoreShortWorker) Work(ctx context.Context, job *Job[VideoStoreSho
|
||||
log.Infof("[Start] Working on job with strings: %+v", job.Args)
|
||||
defer log.Infof("[End] Finished %s", job.Args.Kind())
|
||||
|
||||
media, err := models.Medias.GetByID(ctx, job.Args.MediaID)
|
||||
media, err := models.Medias.GetByHash(ctx, job.Args.MediaHash)
|
||||
if err != nil {
|
||||
log.Errorf("Error getting media by ID: %v", err)
|
||||
return JobCancel(err)
|
||||
|
||||
@@ -174,7 +174,7 @@ func (m *mediasModel) Update(ctx context.Context, hash string, model *model.Medi
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, db); err != nil {
|
||||
m.log.Errorf("error updating media item: %v", err)
|
||||
m.log.WithField("hash", hash).Errorf("error updating media item: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,12 @@ func Serve(cmd *cobra.Command, args []string) error {
|
||||
route.Register(group)
|
||||
}
|
||||
|
||||
if err := svc.Job.Start(ctx); err != nil {
|
||||
log.WithError(err).Error("job start failed")
|
||||
return err
|
||||
}
|
||||
defer svc.Job.StopAndCancel(ctx)
|
||||
|
||||
return svc.Http.Serve()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ AccessKeySecret = "hV7spvJuWh8w0EEIXj8NFi2uBlF4aS"
|
||||
Bucket ="rogee-test"
|
||||
Host ="https://assets.jdwan.com"
|
||||
Region ="cn-beijing"
|
||||
CallbackURL = "https://www.baidu.com"
|
||||
|
||||
[WeChat]
|
||||
AppID = "wx47649361b6eba174"
|
||||
|
||||
@@ -32,6 +32,9 @@ func GetMediaDuration(path string) (int64, error) {
|
||||
func CutMedia(input, output string, start, end int64) error {
|
||||
args := []string{
|
||||
"-y",
|
||||
"-hide_banner",
|
||||
"-nostats",
|
||||
"-v", "error",
|
||||
"-ss", strconv.FormatInt(start, 10),
|
||||
"-i", input,
|
||||
"-t", strconv.FormatInt(end, 10),
|
||||
@@ -46,6 +49,9 @@ func CutMedia(input, output string, start, end int64) error {
|
||||
func GetFrameImageFromVideo(input, output string, time int64) error {
|
||||
args := []string{
|
||||
"-y",
|
||||
"-hide_banner",
|
||||
"-nostats",
|
||||
"-v", "error",
|
||||
"-i", input,
|
||||
"-ss", strconv.FormatInt(time, 10),
|
||||
"-vframes", "1",
|
||||
|
||||
@@ -38,7 +38,7 @@ func (c *OSSClient) Download(ctx context.Context, path, dest string) error {
|
||||
Key: oss.Ptr(path),
|
||||
}
|
||||
|
||||
_, err := c.client.GetObjectToFile(ctx, request, dest)
|
||||
_, err := c.internalClient.GetObjectToFile(ctx, request, dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -97,14 +97,7 @@ func (q *Job) Start(ctx context.Context) error {
|
||||
return errors.Wrap(err, "get client failed")
|
||||
}
|
||||
|
||||
if err := client.Start(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
defer client.StopAndCancel(ctx)
|
||||
|
||||
<-ctx.Done()
|
||||
|
||||
return nil
|
||||
return client.Start(ctx)
|
||||
}
|
||||
|
||||
func (q *Job) StopAndCancel(ctx context.Context) error {
|
||||
|
||||
BIN
backend/quyun
BIN
backend/quyun
Binary file not shown.
BIN
fixtures/quyun/959e5310105c96e653f10b74e5bdc36b-short.mp4
Normal file
BIN
fixtures/quyun/959e5310105c96e653f10b74e5bdc36b-short.mp4
Normal file
Binary file not shown.
BIN
fixtures/quyun/959e5310105c96e653f10b74e5bdc36b.mp4
Normal file
BIN
fixtures/quyun/959e5310105c96e653f10b74e5bdc36b.mp4
Normal file
Binary file not shown.
BIN
fixtures/quyun/ce4cd071128cef282cf315dda75bdab4-short.mp4
Normal file
BIN
fixtures/quyun/ce4cd071128cef282cf315dda75bdab4-short.mp4
Normal file
Binary file not shown.
BIN
fixtures/quyun/ce4cd071128cef282cf315dda75bdab4.mp4
Normal file
BIN
fixtures/quyun/ce4cd071128cef282cf315dda75bdab4.mp4
Normal file
Binary file not shown.
Reference in New Issue
Block a user