feat: 添加 ImageGeneration 和 GetImageJob 接口
This commit is contained in:
parent
76a5eaaad9
commit
40d5e597f6
@ -31,11 +31,13 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/topfans/backend/pkg/logger"
|
"github.com/topfans/backend/pkg/logger"
|
||||||
|
"github.com/topfans/backend/services/assetService/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AssetController 资产相关控制器
|
// AssetController 资产相关控制器
|
||||||
type AssetController struct {
|
type AssetController struct {
|
||||||
assetService pbAsset.AssetService
|
assetService pbAsset.AssetService
|
||||||
|
minimaxService service.MinimaxService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAssetController 创建资产控制器
|
// NewAssetController 创建资产控制器
|
||||||
@ -47,7 +49,8 @@ func NewAssetController(dubboClient *client.Client) (*AssetController, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &AssetController{
|
return &AssetController{
|
||||||
assetService: assetService,
|
assetService: assetService,
|
||||||
|
minimaxService: service.NewMinimaxService(nil),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1407,3 +1410,81 @@ func (ctrl *AssetController) listOSSImageFiles(
|
|||||||
|
|
||||||
return files, nil
|
return files, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImageGeneration 创建图生图任务
|
||||||
|
// @Summary 图生图
|
||||||
|
// @Description 创建图生图任务
|
||||||
|
// @Tags assets
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param request body dto.ImageGenerationRequest true "图生图请求"
|
||||||
|
// @Success 202 {object} response.Response
|
||||||
|
// @Router /api/v1/assets/mints/image/generation [post]
|
||||||
|
func (ctrl *AssetController) ImageGeneration(c *gin.Context) {
|
||||||
|
var req dto.ImageGenerationRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.Error(c, 400, "Invalid request: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userID := c.GetInt64("userID")
|
||||||
|
starID := c.GetInt64("starID")
|
||||||
|
|
||||||
|
job, err := ctrl.minimaxService.CreateJob(c.Request.Context(), userID, starID, &req)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, 500, "Failed to create job: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(202, gin.H{"code": 202, "message": "ok", "data": &dto.ImageJobCreateResponse{
|
||||||
|
JobID: job.JobID,
|
||||||
|
Status: string(job.Status),
|
||||||
|
CreatedAt: job.CreatedAt,
|
||||||
|
}})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetImageJob 查询图生图任务状态
|
||||||
|
// @Summary 查询图生图任务
|
||||||
|
// @Description 查询图生图任务状态和结果
|
||||||
|
// @Tags assets
|
||||||
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
|
// @Param job_id path string true "任务ID"
|
||||||
|
// @Success 200 {object} response.Response
|
||||||
|
// @Router /api/v1/assets/mints/image/generation/{job_id} [get]
|
||||||
|
func (ctrl *AssetController) GetImageJob(c *gin.Context) {
|
||||||
|
jobID := c.Param("job_id")
|
||||||
|
if jobID == "" {
|
||||||
|
response.Error(c, 400, "job_id is required")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userID := c.GetInt64("userID")
|
||||||
|
starID := c.GetInt64("starID")
|
||||||
|
|
||||||
|
job, err := ctrl.minimaxService.GetJob(c.Request.Context(), jobID, userID, starID)
|
||||||
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "not found") {
|
||||||
|
response.Error(c, 404, "Job not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if strings.Contains(err.Error(), "access denied") {
|
||||||
|
response.Error(c, 403, "Access denied")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
response.Error(c, 500, "Failed to get job: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, &dto.ImageJobResponse{
|
||||||
|
JobID: job.JobID,
|
||||||
|
Status: string(job.Status),
|
||||||
|
Progress: job.Progress,
|
||||||
|
Images: job.Images,
|
||||||
|
ErrorMsg: job.ErrorMsg,
|
||||||
|
CreatedAt: job.CreatedAt,
|
||||||
|
UpdatedAt: job.UpdatedAt,
|
||||||
|
CompletedAt: job.CompletedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user