file: add taskqueue worker process image thumbnail
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 30s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 30s
This commit is contained in:
49
file/internal/logic/generateimageversionslogic.go
Normal file
49
file/internal/logic/generateimageversionslogic.go
Normal file
@ -0,0 +1,49 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"godemo/file/file"
|
||||
"godemo/file/internal/svc"
|
||||
"godemo/file/worker"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GenerateImageVersionsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGenerateImageVersionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateImageVersionsLogic {
|
||||
return &GenerateImageVersionsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 异步生成图片版本接口
|
||||
func (l *GenerateImageVersionsLogic) GenerateImageVersions(in *file.GenerateImageVersionsRequest) (*file.GenerateImageVersionsResponse, error) {
|
||||
// 1. 验证输入参数
|
||||
|
||||
// 2. 检查文件是否存在
|
||||
|
||||
// 3. 创建任务对象,并提交到任务队列
|
||||
requestID := uuid.New().String()
|
||||
worker.ImageProcessTaskQueue <- worker.ImageProcessTask{
|
||||
FileID: in.FileId,
|
||||
Versions: in.Versions,
|
||||
RequestID: requestID,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
// 4. 返回响应
|
||||
return &file.GenerateImageVersionsResponse{
|
||||
TaskId: requestID,
|
||||
Accepted: true,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user