feat: update

This commit is contained in:
Rogee
2025-05-23 21:43:49 +08:00
parent f13ef4388e
commit 409a2e8304
9 changed files with 21 additions and 126 deletions

View File

@@ -75,7 +75,7 @@ func (up *uploads) PostUploadedAction(ctx fiber.Ctx, body *PostUploadedForm) err
Hash: body.Md5,
Path: filepath.Join(UPLOAD_PATH, body.Md5+filepath.Ext(body.OriginalName)),
}
if err := model.MediasModel().Create(ctx.Context(), m); err != nil {
if err := m.Create(ctx.Context()); err != nil {
return err
}

View File

@@ -89,12 +89,11 @@ func (w *VideoExtractHeadImageWorker) Work(ctx context.Context, job *Job[VideoEx
// create a new media record for the image
imageMedia := &model.Medias{
CreatedAt: time.Now(),
Name: name,
MimeType: "image/jpeg",
Size: fileSize,
Path: w.oss.GetSavePath(filename),
Hash: fileMd5,
Name: name,
MimeType: "image/jpeg",
Size: fileSize,
Path: w.oss.GetSavePath(filename),
Hash: fileMd5,
Metas: fields.ToJson(fields.MediaMetas{
ParentHash: media.Hash,
}),
@@ -110,7 +109,7 @@ func (w *VideoExtractHeadImageWorker) Work(ctx context.Context, job *Job[VideoEx
log.Errorf("Error removing original file: %v", err)
}
if err := model.MediasModel().Create(ctx, imageMedia); err != nil {
if err := imageMedia.Create(ctx); err != nil {
log.Errorf("Error creating media record: %v", err)
return errors.Wrap(err, "failed to create media record")
}

View File

@@ -91,12 +91,11 @@ func (w *VideoStoreShortWorker) Work(ctx context.Context, job *Job[VideoStoreSho
// save to db and relate to master
mediaModel := &model.Medias{
CreatedAt: time.Now(),
Name: "[试听]" + media.Name,
MimeType: media.MimeType,
Size: fileSize,
Path: filePath,
Hash: fileMd5,
Name: "[试听] " + media.Name,
MimeType: media.MimeType,
Size: fileSize,
Path: filePath,
Hash: fileMd5,
Metas: fields.ToJson(fields.MediaMetas{
ParentHash: media.Hash,
Short: true,
@@ -112,7 +111,7 @@ func (w *VideoStoreShortWorker) Work(ctx context.Context, job *Job[VideoStoreSho
}
log.Infof("pending create media record %s", job.Args.FilePath)
if err := model.MediasModel().Create(ctx, mediaModel); err != nil {
if err := mediaModel.Create(ctx); err != nil {
log.Errorf("Error saving media record: %v data: %+v", err, mediaModel)
return err
}

View File

@@ -97,12 +97,12 @@ func (m *Medias) BatchCreate(ctx context.Context, models []*Medias) error {
return nil
}
func (m *Medias) Create(ctx context.Context, medias *Medias) error {
medias.CreatedAt = time.Now()
stmt := table.Medias.INSERT(table.Medias.MutableColumns).MODEL(medias).RETURNING(table.Medias.AllColumns)
func (m *Medias) Create(ctx context.Context) error {
m.CreatedAt = time.Now()
stmt := table.Medias.INSERT(table.Medias.MutableColumns).MODEL(m).RETURNING(table.Medias.AllColumns)
m.log().Infof("sql: %s", stmt.DebugSql())
if err := stmt.QueryContext(ctx, db, medias); err != nil {
if err := stmt.QueryContext(ctx, db, m); err != nil {
m.log().Errorf("error creating media item: %v", err)
return err
}

View File

@@ -132,7 +132,7 @@ func (s *MediasTestSuite) Test_Create() {
Path: "path/to/media.pdf",
}
err := MediasModel().Create(context.Background(), model)
err := model.Create(context.Background())
Convey("Create should not return an error", func() {
So(err, ShouldBeNil)
})
@@ -165,7 +165,7 @@ func (s *MediasTestSuite) Test_Page() {
Path: "path/to/media.pdf",
}
err := MediasModel().Create(context.Background(), model)
err := model.Create(context.Background())
So(err, ShouldBeNil)
}
@@ -208,7 +208,7 @@ func (s *MediasTestSuite) Test_CreateGetID() {
Path: "path/to/media.pdf",
}
err := MediasModel().Create(context.Background(), model)
err := model.Create(context.Background())
So(err, ShouldBeNil)
So(model.ID, ShouldNotBeEmpty)

View File

@@ -1,19 +0,0 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"time"
)
type Migrations struct {
ID int32 `sql:"primary_key" json:"id"`
VersionID int64 `json:"version_id"`
IsApplied bool `json:"is_applied"`
Tstamp time.Time `json:"tstamp"`
}