|
@@ -6,11 +6,17 @@ import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.backendsys.modules.ai.chat.entity.ChatSseMessage;
|
|
import com.backendsys.modules.ai.chat.entity.ChatSseMessage;
|
|
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
|
|
+import com.backendsys.modules.crt.dao.CrtGenerateImageDao;
|
|
|
|
+import com.backendsys.modules.crt.entity.CrtGenerateImage;
|
|
import com.backendsys.modules.sdk.comfyui.enums.TypeEnums;
|
|
import com.backendsys.modules.sdk.comfyui.enums.TypeEnums;
|
|
import com.backendsys.modules.sdk.comfyui.service.ComfyUISocketService;
|
|
import com.backendsys.modules.sdk.comfyui.service.ComfyUISocketService;
|
|
|
|
+import com.backendsys.modules.sdk.douyincloud.tos.service.DouyinTosService;
|
|
|
|
+import com.backendsys.modules.sdk.tencentcloud.cos.service.TencentCosService;
|
|
import com.backendsys.modules.sse.entity.SseResponse;
|
|
import com.backendsys.modules.sse.entity.SseResponse;
|
|
import com.backendsys.modules.sse.entity.SseResponseEnum;
|
|
import com.backendsys.modules.sse.entity.SseResponseEnum;
|
|
import com.backendsys.modules.sse.utils.SseUtil;
|
|
import com.backendsys.modules.sse.utils.SseUtil;
|
|
|
|
+import com.backendsys.modules.system.service.SysCommonService;
|
|
|
|
+import com.backendsys.modules.upload.entity.SysFileResult;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -35,6 +41,14 @@ public class ComfyUISocketServiceImpl implements ComfyUISocketService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private SseUtil sseUtil;
|
|
private SseUtil sseUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysCommonService sysCommonService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TencentCosService tencentCosService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DouyinTosService douyinTosService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CrtGenerateImageDao crtGenerateImageDao;
|
|
|
|
|
|
@Value("${comfyui.host}")
|
|
@Value("${comfyui.host}")
|
|
private String COMFYUI_HOST;
|
|
private String COMFYUI_HOST;
|
|
@@ -98,8 +112,15 @@ public class ComfyUISocketServiceImpl implements ComfyUISocketService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Mono<Void> connectToSse(String clientId, Integer port) {
|
|
public Mono<Void> connectToSse(String clientId, Integer port) {
|
|
|
|
+ return connectToSse(clientId, port, null);
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public Mono<Void> connectToSse(String clientId, Integer port, Map<String, Object> params) {
|
|
|
|
+
|
|
|
|
+ CrtGenerateImage entity = new CrtGenerateImage();
|
|
|
|
|
|
Long user_id = SecurityUtil.getUserId();
|
|
Long user_id = SecurityUtil.getUserId();
|
|
|
|
+ entity.setUser_id(user_id);
|
|
|
|
|
|
String wsUrl = "ws://" + COMFYUI_HOST + ":" + port + "/ws";
|
|
String wsUrl = "ws://" + COMFYUI_HOST + ":" + port + "/ws";
|
|
return Mono.defer(() -> {
|
|
return Mono.defer(() -> {
|
|
@@ -132,6 +153,9 @@ public class ComfyUISocketServiceImpl implements ComfyUISocketService {
|
|
JSONObject output = JSONUtil.parseObj(dataChildren.get("output"));
|
|
JSONObject output = JSONUtil.parseObj(dataChildren.get("output"));
|
|
|
|
|
|
// -- [生成图片] ------------------------------------------------------
|
|
// -- [生成图片] ------------------------------------------------------
|
|
|
|
+ // 由于图片地址不是公开的,需要加 Token 访问,因此不能公开返回原始图片地址,比如:
|
|
|
|
+ // http://43.128.1.201:8000/api/view?filename=fenjing_1_00012_.png&token=$2b$12$.MR4qGaFetN1FPQzbfyIrehsyjnPJ12xAZhR/l7KZpLkUPQTCG4gy
|
|
|
|
+
|
|
Object imagesObj = output.get("images");
|
|
Object imagesObj = output.get("images");
|
|
if (imagesObj != null) {
|
|
if (imagesObj != null) {
|
|
JSONArray images = JSONUtil.parseArray(imagesObj);
|
|
JSONArray images = JSONUtil.parseArray(imagesObj);
|
|
@@ -144,12 +168,39 @@ public class ComfyUISocketServiceImpl implements ComfyUISocketService {
|
|
JSONObject image = images.getJSONObject(i);
|
|
JSONObject image = images.getJSONObject(i);
|
|
String filename = image.getStr("filename");
|
|
String filename = image.getStr("filename");
|
|
String filepath = "http://" + COMFYUI_HOST + ":" + port + "/api/view?filename=" + filename;
|
|
String filepath = "http://" + COMFYUI_HOST + ":" + port + "/api/view?filename=" + filename;
|
|
- images_path.add(filepath);
|
|
|
|
|
|
+ String filepath_with_token = filepath + "&token=" + COMFYUI_TOKEN;
|
|
|
|
|
|
// -- [图片转存储存桶] -------------------------------------
|
|
// -- [图片转存储存桶] -------------------------------------
|
|
|
|
+ SysFileResult result = new SysFileResult();
|
|
|
|
+ Integer UPLOAD_TARGET = Convert.toInt(sysCommonService.getCommonByTag("UPLOAD_TARGET"));
|
|
|
|
|
|
|
|
+ // target: 上传目标 (-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云)
|
|
|
|
+ if (UPLOAD_TARGET == 1) {
|
|
|
|
+ result = tencentCosService.urlToCOS(filepath_with_token);
|
|
|
|
+ }
|
|
|
|
+ if (UPLOAD_TARGET == 3) {
|
|
|
|
+ result = douyinTosService.urlToTOS(filepath_with_token);
|
|
|
|
+ }
|
|
|
|
+ System.out.println("filepath_with_token = " + filepath_with_token);
|
|
|
|
+ System.out.println("result = " + result);
|
|
|
|
+
|
|
|
|
+ // -- [记录到生成图片记录表] --------------------------------
|
|
|
|
+ if (params != null) {
|
|
|
|
+ Long drama_project_storyboard_id = Convert.toLong(params.get("drama_project_storyboard_id"));
|
|
|
|
+ String prompt_id = Convert.toStr(dataChildren.get("prompt_id"));
|
|
|
|
+ if (drama_project_storyboard_id != null) {
|
|
|
|
+ entity.setDrama_project_storyboard_id(drama_project_storyboard_id);
|
|
|
|
+ entity.setPrompt_id(prompt_id);
|
|
|
|
+ entity.setUrl_origin(filepath);
|
|
|
|
+ System.out.println("crtGenerateImage entity = " + entity);
|
|
|
|
+ crtGenerateImageDao.insert(entity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// ------------------------------------------------------
|
|
// ------------------------------------------------------
|
|
|
|
|
|
|
|
+ // 这里要改成 result 的返回地址拼接?
|
|
|
|
+ images_path.add(filepath);
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
output.put("images_path", images_path);
|
|
output.put("images_path", images_path);
|