|
@@ -31,6 +31,8 @@ public class ComfyUISocketServiceImpl implements ComfyUISocketService {
|
|
|
@Autowired
|
|
|
private SseUtil sseUtil;
|
|
|
|
|
|
+ @Value("${comfyui.host}")
|
|
|
+ private String COMFYUI_HOST;
|
|
|
@Value("${comfyui.token}")
|
|
|
private String COMFYUI_TOKEN;
|
|
|
|
|
@@ -55,7 +57,9 @@ public class ComfyUISocketServiceImpl implements ComfyUISocketService {
|
|
|
* [ComfyUI] 创建 WebSocket 监听连接
|
|
|
*/
|
|
|
@Override
|
|
|
- public Mono<Void> connect(String clientId, String wsUrl) {
|
|
|
+ public Mono<Void> connect(String clientId, Integer port) {
|
|
|
+
|
|
|
+ String wsUrl = "ws://" + COMFYUI_HOST + ":" + port + "/ws";
|
|
|
return Mono.defer(() -> {
|
|
|
if (sessions.containsKey(clientId)) {
|
|
|
return Mono.error(new IllegalStateException("Connection already exists for client: " + clientId));
|
|
@@ -88,10 +92,11 @@ public class ComfyUISocketServiceImpl implements ComfyUISocketService {
|
|
|
* [ComfyUI] 创建 WebSocket 监听连接 (转发到 SSE)
|
|
|
*/
|
|
|
@Override
|
|
|
- public Mono<Void> connectToSse(String clientId, String wsUrl) {
|
|
|
+ public Mono<Void> connectToSse(String clientId, Integer port) {
|
|
|
|
|
|
Long user_id = SecurityUtil.getUserId();
|
|
|
|
|
|
+ String wsUrl = "ws://" + COMFYUI_HOST + ":" + port + "/ws";
|
|
|
return Mono.defer(() -> {
|
|
|
if (sessions.containsKey(clientId)) {
|
|
|
return Mono.error(new IllegalStateException("Connection already exists for client: " + clientId));
|
|
@@ -117,11 +122,30 @@ public class ComfyUISocketServiceImpl implements ComfyUISocketService {
|
|
|
messageObj = JSONUtil.parseObj(message);
|
|
|
// 记录生成数据
|
|
|
JSONObject output = JSONUtil.parseObj(messageObj.get("output"));
|
|
|
- JSONArray images = JSONUtil.parseArray(output.get("images"));
|
|
|
- // [{"filename": "ComfyUI_00122_.png", "subfolder": "", "type": "output"}]
|
|
|
- // http://43.128.1.201:8001/api/view?filename=ComfyUI_00118_.png
|
|
|
+
|
|
|
+ Object imagesObj = output.get("images");
|
|
|
+ if (imagesObj != null) {
|
|
|
+ JSONArray images = JSONUtil.parseArray(imagesObj);
|
|
|
+ // [{"filename": "ComfyUI_00122_.png", "subfolder": "", "type": "output"}]
|
|
|
+ // http://43.128.1.201:8001/api/view?filename=ComfyUI_00118_.png
|
|
|
+
|
|
|
+ if (images.size() > 0) {
|
|
|
+ for (int i = 0; i < images.size(); i++) {
|
|
|
+
|
|
|
+ JSONObject image = images.getJSONObject(i);
|
|
|
+// JSONObject image = images.getJSONObject(i);
|
|
|
+// String filename = image.getStr("filename");
|
|
|
+// String subfolder = image.getStr("subfolder");
|
|
|
+// String type = image.getStr("type");
|
|
|
+// System.out.println("filename: " + filename + ", subfolder: " + subfolder + ", type: " + type);
|
|
|
+// sseUtil.send(user_id, new SseResponse(SseResponseEnum.COMFYUI, "filename: " + filename + ", subfolder: " + subfolder + ", type: " + type).toJsonStr());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
sseUtil.send(user_id, new SseResponse(SseResponseEnum.COMFYUI, messageObj).toJsonStr());
|
|
|
})
|
|
|
.doOnError(e -> {
|