Commit dbe23cfe8ea14090daabf4edd3fd0d4d8faecf61

Authored by cherishsince
1 parent 3ab218ef

【优化】调试 mj proxy 通知回调

yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/MidjourneyProxyClient.java
1 1 package cn.iocoder.yudao.module.ai.client;
2 2  
  3 +import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
3 4 import cn.iocoder.yudao.module.ai.client.vo.MidjourneyImagineReqVO;
4 5 import cn.iocoder.yudao.module.ai.client.vo.MidjourneySubmitRespVO;
5 6 import jakarta.validation.constraints.NotNull;
6 7 import org.springframework.beans.factory.annotation.Autowired;
7 8 import org.springframework.beans.factory.annotation.Value;
  9 +import org.springframework.http.*;
8 10 import org.springframework.stereotype.Component;
9 11 import org.springframework.validation.annotation.Validated;
10 12 import org.springframework.web.client.RestTemplate;
... ... @@ -35,7 +37,15 @@ public class MidjourneyProxyClient {
35 37 * @return
36 38 */
37 39 public MidjourneySubmitRespVO imagine(@Validated @NotNull MidjourneyImagineReqVO imagineReqVO) {
38   - return restTemplate.postForObject(url.concat(URI_IMAGINE), imagineReqVO, MidjourneySubmitRespVO.class);
  40 + // 创建 HttpHeaders 对象
  41 + HttpHeaders headers = new HttpHeaders();
  42 + headers.setContentType(MediaType.APPLICATION_JSON);
  43 + headers.set("Authorization", "Bearer sk-c3qxUCVKsPfdQiYU8440E3Fc8dE5424d9cB124A4Ee2489E3");
  44 + // 创建 HttpEntity 对象,将 HttpHeaders 和请求体传递给它
  45 + HttpEntity<String> requestEntity = new HttpEntity<>(JsonUtils.toJsonString(imagineReqVO), headers);
  46 + // 发送 post 请求
  47 + ResponseEntity<String> response = restTemplate.exchange(url.concat(URI_IMAGINE), HttpMethod.POST, requestEntity, String.class);
  48 + return JsonUtils.parseObject(response.getBody(), MidjourneySubmitRespVO.class);
39 49 }
40 50  
41 51 }
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/client/vo/MidjourneyNotifyReqVO.java
... ... @@ -19,7 +19,7 @@ public class MidjourneyNotifyReqVO {
19 19 @Schema(description = "任务类型")
20 20 private MidjourneyTaskActionEnum action;
21 21 @Schema(description = "任务状态")
22   - private MidjourneyTaskStatusEnum status = MidjourneyTaskStatusEnum.NOT_START;
  22 + private MidjourneyTaskStatusEnum status;
23 23  
24 24 @Schema(description = "提示词")
25 25 private String prompt;
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java
... ... @@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation;
15 15 import io.swagger.v3.oas.annotations.Parameter;
16 16 import io.swagger.v3.oas.annotations.tags.Tag;
17 17 import jakarta.annotation.Resource;
  18 +import jakarta.annotation.security.PermitAll;
18 19 import lombok.extern.slf4j.Slf4j;
19 20 import org.springframework.validation.annotation.Validated;
20 21 import org.springframework.web.bind.annotation.*;
... ... @@ -70,10 +71,10 @@ public class AiImageController {
70 71 return success(imageService.midjourneyImagine(getLoginUserId(), req));
71 72 }
72 73  
73   - // TODO @芋艿:不拦截
74 74 @Operation(summary = "midjourney proxy - 回调通知")
75   - @RequestMapping("/midjourney-notify")
76   - public CommonResult<Boolean> midjourneyNotify(MidjourneyNotifyReqVO notifyReqVO) {
  75 + @PostMapping("/midjourney-notify")
  76 + @PermitAll
  77 + public CommonResult<Boolean> midjourneyNotify( @RequestBody MidjourneyNotifyReqVO notifyReqVO) {
77 78 return success(imageService.midjourneyNotify(getLoginUserId(), notifyReqVO));
78 79 }
79 80  
... ...
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
... ... @@ -212,7 +212,6 @@ public class AiImageServiceImpl implements AiImageService {
212 212 .setId(image.getId())
213 213 .setStatus(imageStatus)
214 214 .setPicUrl(filePath)
215   -// .setOriginalPicUrl(notifyReqVO.getImageUrl()) TODO @fan:就不存原始的图片地址啦
216 215 );
217 216 return true;
218 217 }
... ...
yudao-server/src/main/resources/application-local.yaml
... ... @@ -76,6 +76,13 @@ server:
76 76 enabled: true
77 77 charset: UTF-8
78 78 force: true
  79 +# ai
  80 +ai:
  81 + midjourney-proxy:
  82 + url: https://api.holdai.top/mj
  83 + notifyUrl: http://7b1aada4.r26.cpolar.top/admin-api/ai/image/midjourney-notify
  84 +
  85 +
79 86 --- #################### 定时任务相关配置 ####################
80 87  
81 88 # Quartz 配置项,对应 QuartzProperties 配置类
... ...