feat(backend): add JPEG compression support and new image processing functions

This commit is contained in:
keven1024
2025-06-02 12:45:57 +08:00
parent 4b8654e6ed
commit 8cd9f278ba
2 changed files with 27 additions and 5 deletions

View File

@@ -104,16 +104,16 @@ watch(
v-for="item in taskData?.result"
>
<div
class="bg-white/80 p-2 rounded-md w-full flex flex-row items-center justify-between"
class="bg-white/80 p-2 rounded-md w-full flex flex-row items-center justify-between gap-2"
>
<div class="flex flex-row gap-2 items-center">
<div class="flex flex-row gap-2 items-center max-w-2/3">
<div
class="flex flex-row items-center justify-center rounded-md bg-black/5 p-2"
>
<LucideImage />
</div>
{{ props?.data?.file?.name }}
<div class="flex flex-row gap-2 items-center text-sm">
<div class="truncate w-auto">{{ props?.data?.file?.name }}</div>
<div class="flex flex-row gap-2 items-center text-sm shrink-0">
<span class="opacity-75">{{
filesize(item.new_file.size ?? 0)
}}</span>

View File

@@ -44,6 +44,17 @@ func CompressImage(ctx context.Context, task *asynq.Task) error {
if err != nil {
return err
}
case "image/jpeg":
err := utils.CopyFile(originalPath, originalPath+"_compressed")
if err != nil {
return err
}
args := []string{"-m", "90", "--strip-all", originalPath + "_compressed"}
cmd := exec.Command("jpegoptim", args...)
_, err = cmd.CombinedOutput()
if err != nil {
return err
}
default:
return errors.New("不支持的文件类型")
}
@@ -57,7 +68,6 @@ func CompressImage(ctx context.Context, task *asynq.Task) error {
"status": "success",
"result": []any{
map[string]any{
"status": "success",
"old_file": map[string]any{
"id": payload.FileId,
"size": originalFileInfo.FileSize,
@@ -72,3 +82,15 @@ func CompressImage(ctx context.Context, task *asynq.Task) error {
return nil
}
func UpscaleImage(ctx context.Context, task *asynq.Task) error {
return nil
}
func TranslateImage(ctx context.Context, task *asynq.Task) error {
return nil
}
func CreateAIImage(ctx context.Context, task *asynq.Task) error {
return nil
}