You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.8 KiB
65 lines
2.8 KiB
|
3 weeks ago
|
package com.youlai.boot.mini.controller;
|
||
|
|
|
||
|
|
import com.youlai.boot.common.annotation.Log;
|
||
|
|
import com.youlai.boot.common.annotation.RepeatSubmit;
|
||
|
|
import com.youlai.boot.common.enums.ActionTypeEnum;
|
||
|
|
import com.youlai.boot.common.enums.LogModuleEnum;
|
||
|
|
import com.youlai.boot.common.result.Result;
|
||
|
|
import com.youlai.boot.framework.security.util.SecurityUtils;
|
||
|
|
import com.youlai.boot.mini.model.dto.PhotoToComicRequest;
|
||
|
|
import com.youlai.boot.mini.model.vo.AiTaskCallbackVO;
|
||
|
|
import com.youlai.boot.mini.service.AiGenerationService;
|
||
|
|
import io.swagger.v3.oas.annotations.Operation;
|
||
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
||
|
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||
|
|
import jakarta.validation.Valid;
|
||
|
|
import lombok.RequiredArgsConstructor;
|
||
|
|
import org.springframework.http.MediaType;
|
||
|
|
import org.springframework.web.bind.annotation.*;
|
||
|
|
import org.springframework.web.multipart.MultipartFile;
|
||
|
|
|
||
|
|
import java.util.Collections;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
@Tag(name = "AI生成图片视频相关接口")
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/api/v1/mini/ai/generation")
|
||
|
|
@RequiredArgsConstructor
|
||
|
|
@Valid
|
||
|
|
public class AiGenerationController {
|
||
|
|
|
||
|
|
private final AiGenerationService aiGenerationService;
|
||
|
|
|
||
|
|
@Operation(summary = "上传AI生成参考文件", operationId = "AiReferenceSaveFile")
|
||
|
|
@PostMapping(value = "/upload-reference", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||
|
|
@RepeatSubmit
|
||
|
|
@Log(module = LogModuleEnum.AI_TASK_MEDIA, value = ActionTypeEnum.INSERT)
|
||
|
|
public Result<List<String>> uploadReferenceFile(
|
||
|
|
@RequestPart(name = "images", required = false) List<MultipartFile> images,
|
||
|
|
@RequestPart(name = "videos", required = false) List<MultipartFile> videos
|
||
|
|
) {
|
||
|
|
Long userId = SecurityUtils.getUserId();
|
||
|
|
List<String> urlList = aiGenerationService.uploadReferenceFile(images, videos, userId);
|
||
|
|
return Result.success(urlList);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Operation(summary = "提交单图漫画生成任务")
|
||
|
|
@PostMapping("/generate-single-image")
|
||
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.INSERT)
|
||
|
|
public Result<String> generateSingleImage(@Valid @RequestBody PhotoToComicRequest request) {
|
||
|
|
Long userId = SecurityUtils.getUserId();
|
||
|
|
String taskUuid = aiGenerationService.createAndGenerateImage(request, userId);
|
||
|
|
return Result.success(taskUuid);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Operation(summary = "AI生成任务回调接口")
|
||
|
|
@PostMapping("/task/callback")
|
||
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.UPDATE)
|
||
|
|
public Result<Boolean> taskCallback(@Valid @RequestBody AiTaskCallbackVO vo) {
|
||
|
|
boolean success = aiGenerationService.handleTaskCallback(vo.getUuid(), vo.getStatus(), vo.getResultUrl());
|
||
|
|
return Result.success(success);
|
||
|
|
}
|
||
|
|
}
|