mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
feat(worker): add image conversion endpoint and update file utility references in tasks
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"pkg/models"
|
||||
u "pkg/utils"
|
||||
"worker/internal/utils"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
@@ -36,7 +35,7 @@ func RemoveFile(ctx context.Context, task *asynq.Task) error {
|
||||
}
|
||||
|
||||
rdb, rctx := u.GetRedisClient()
|
||||
uploadPath, err := utils.GetUploadDirPath()
|
||||
uploadPath, err := u.GetUploadDirPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"pkg/models"
|
||||
u "pkg/utils"
|
||||
"worker/internal/utils"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
"github.com/samber/lo"
|
||||
@@ -32,7 +31,7 @@ func RemoveShare(ctx context.Context, task *asynq.Task) error {
|
||||
})
|
||||
if len(shareIDs) == 0 {
|
||||
rdb, ctx := u.GetRedisClient()
|
||||
uploadPath, err := utils.GetUploadDirPath()
|
||||
uploadPath, err := u.GetUploadDirPath()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ func main() {
|
||||
mux.HandleFunc("share:remove", tasks.RemoveShare)
|
||||
mux.HandleFunc("file:remove", tasks.RemoveFile)
|
||||
mux.HandleFunc("image:compress", tasks.CompressImage)
|
||||
mux.HandleFunc("image:convert", tasks.ConvertImage)
|
||||
|
||||
if err := srv.Run(mux); err != nil {
|
||||
log.Fatalf("could not run server: %v", err)
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"pkg/utils"
|
||||
"runtime"
|
||||
"testing"
|
||||
"worker/internal/services"
|
||||
"worker/internal/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -108,5 +108,5 @@ func TestConvertImageWithMagickInvalidExt(t *testing.T) {
|
||||
// 测试非法扩展名(防止注入)
|
||||
_, err = services.ConvertImageWithMagick(filePath, "image/png", ".exe")
|
||||
assert.Error(t, err, "应该返回错误")
|
||||
assert.Equal(t, services.ErrInvalidImageExt, err, "应该返回 ErrInvalidImageExt 错误")
|
||||
assert.Equal(t, services.ErrUnsupportedMimeType, err, "应该返回 ErrUnsupportedMimeType 错误")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user