|
@@ -414,16 +414,8 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
if (customId.contains("BOOKMARK")) {
|
|
if (customId.contains("BOOKMARK")) {
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
TASK_EXECUTOR.execute(() -> {
|
|
|
- try {
|
|
|
|
|
- conversation.setBookmark(true);
|
|
|
|
|
- String imageUrl = conversation.getImageUrl();
|
|
|
|
|
- if (StringUtil.isNotBlank(imageUrl)) {
|
|
|
|
|
- conversation.setImageUrl(uploadPic(imageUrl, "conversation"+conversation.getId()));
|
|
|
|
|
- conversationMapper.updateById(conversation);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- log.error("上传图片失败",e);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ conversation.setBookmark(true);
|
|
|
|
|
+ conversationMapper.updateById(conversation);
|
|
|
});
|
|
});
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -985,110 +977,13 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
conversation.setProperties(jsonObject.toString());
|
|
conversation.setProperties(jsonObject.toString());
|
|
|
if (StringUtil.isNotBlank(conversation.getImageUrl())) {
|
|
if (StringUtil.isNotBlank(conversation.getImageUrl())) {
|
|
|
log.info("获取到的图片 url:{}", conversation.getImageUrl());
|
|
log.info("获取到的图片 url:{}", conversation.getImageUrl());
|
|
|
- ImgSize imgSize = TASK_IMG_SIZE_MAP.get(conversation.getTaskId());
|
|
|
|
|
String imgUrl = conversation.getImageUrl();
|
|
String imgUrl = conversation.getImageUrl();
|
|
|
if(imgUrl.contains("webp")){
|
|
if(imgUrl.contains("webp")){
|
|
|
- imgUrl = imgUrl.replace("cdn.discordapp.com","media.discordapp.net");
|
|
|
|
|
- }
|
|
|
|
|
- URL url = new URL(imgUrl.replace("mj.galaxydvd.com","media.discordapp.net"));
|
|
|
|
|
- //if(imgSize == null){
|
|
|
|
|
- // try {
|
|
|
|
|
- // String filePath = url.getFile();
|
|
|
|
|
- // // 注册 WebP 插件
|
|
|
|
|
- // ImageIO.scanForPlugins();
|
|
|
|
|
- //
|
|
|
|
|
- // // 从 URL 中读取图像,特别处理 WebP 格式
|
|
|
|
|
- // BufferedImage image = null;
|
|
|
|
|
- // if (filePath.contains("webp")) {
|
|
|
|
|
- // Iterator<ImageReader> readers = ImageIO.getImageReadersByMIMEType("image/webp");
|
|
|
|
|
- // if (readers.hasNext()) {
|
|
|
|
|
- // ImageReader reader = readers.next();
|
|
|
|
|
- // try {
|
|
|
|
|
- // ImageInputStream iis = ImageIO.createImageInputStream(url.openStream());
|
|
|
|
|
- // reader.setInput(iis, true);
|
|
|
|
|
- // image = reader.read(0);
|
|
|
|
|
- // }catch (Exception e){
|
|
|
|
|
- // log.error("下载图获取尺寸错误,{}", StringUtil.getErrorText(e));
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // } else {
|
|
|
|
|
- // image = ImageIO.read(url);
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // if (image == null) {
|
|
|
|
|
- // throw new IOException("Failed to read image from URL: " + conversation.getImageUrl());
|
|
|
|
|
- // }else {
|
|
|
|
|
- // try {
|
|
|
|
|
- // //BufferedImage image = ImageIO.read(new URL(url.getProtocol(), "cdn.mj.liuliangbang.vip", url.getPort(), url.getFile()));
|
|
|
|
|
- // // 获取图像的宽度和高度
|
|
|
|
|
- // int width = image.getWidth();
|
|
|
|
|
- // int height = image.getHeight();
|
|
|
|
|
- // log.info("首次获取到的图片 尺寸:{},{}", width, height);
|
|
|
|
|
- // // 缩小宽度和高度的一半
|
|
|
|
|
- // imgSize = new ImgSize();
|
|
|
|
|
- // imgSize.setHeight(height);
|
|
|
|
|
- // imgSize.setWidth(width);
|
|
|
|
|
- // TASK_IMG_SIZE_MAP.put(conversation.getTaskId(), imgSize);
|
|
|
|
|
- // }catch (Exception e){
|
|
|
|
|
- // log.error("下载图获取尺寸错误,{}", StringUtil.getErrorText(e));
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // }catch (Exception e){
|
|
|
|
|
- // log.error("下载图获取尺寸错误,{}", StringUtil.getErrorText(e));
|
|
|
|
|
- // }
|
|
|
|
|
- //}
|
|
|
|
|
-
|
|
|
|
|
- if (imgSize == null) {
|
|
|
|
|
- try {
|
|
|
|
|
- String filePath = url.getFile();
|
|
|
|
|
-
|
|
|
|
|
- BufferedImage image = null;
|
|
|
|
|
- if (filePath.contains("webp")) {
|
|
|
|
|
- image = readWebPImage(url);
|
|
|
|
|
- } else {
|
|
|
|
|
- image = ImageIO.read(url);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (image == null) {
|
|
|
|
|
- throw new IOException("无法从URL读取图像: " + conversation.getImageUrl());
|
|
|
|
|
- } else {
|
|
|
|
|
- imgSize = createImgSize(image);
|
|
|
|
|
- log.info("首次获取到的图片尺寸: {},{}", imgSize.getWidth(), imgSize.getHeight());
|
|
|
|
|
- TASK_IMG_SIZE_MAP.put(conversation.getTaskId(), imgSize);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("下载图获取尺寸错误, {}", StringUtil.getErrorText(e));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String scaling = "";
|
|
|
|
|
-
|
|
|
|
|
- if (imgSize != null) {
|
|
|
|
|
- // 如果尺寸大于1024 则按比例缩小到512左右
|
|
|
|
|
- // 获取图片的宽度和高度
|
|
|
|
|
- int width = imgSize.getWidth();
|
|
|
|
|
- int height = imgSize.getHeight();
|
|
|
|
|
-
|
|
|
|
|
- // 如果高度大于1024,则按比例缩小到高度512
|
|
|
|
|
- if (height > 1024) {
|
|
|
|
|
- double scalingFactor = 512.0 / height;
|
|
|
|
|
- width = (int) (width * scalingFactor);
|
|
|
|
|
- height = 512;
|
|
|
|
|
- }
|
|
|
|
|
- scaling = "quality=lossless&width=" + width + "&height=" + height;
|
|
|
|
|
- if (url.getFile().contains("webp")) {
|
|
|
|
|
- scaling += "&format=webp";
|
|
|
|
|
- }else {
|
|
|
|
|
- TASK_IMG_SIZE_MAP.remove(conversation.getTaskId());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ imgUrl = imgUrl.replace("cdn.discordapp.com","cdn.mj.liuliangbang.vip");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- log.info("任务执行回调 imgUrl:{}", conversation.getImageUrl());
|
|
|
|
|
- // 使用 Hutool 提取各个部分并构建新 URL
|
|
|
|
|
- String newUrl = URLUtil.toURI(new URL(url.getProtocol(), "cdn.mj.liuliangbang.vip", url.getPort(), url.getFile() + scaling)).toString();
|
|
|
|
|
-
|
|
|
|
|
- conversation.setImageUrl(newUrl);
|
|
|
|
|
|
|
+ conversation.setImageUrl(imgUrl);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
redisService.set(RedisService.key.MIDJOURNEY_CONVERSATION.getName() + conversation.getTaskId(), conversation,RedisService.key.MIDJOURNEY_CONVERSATION.getTimeout());
|
|
redisService.set(RedisService.key.MIDJOURNEY_CONVERSATION.getName() + conversation.getTaskId(), conversation,RedisService.key.MIDJOURNEY_CONVERSATION.getTimeout());
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
TASK_EXECUTOR.execute(() -> {
|
|
|
try {
|
|
try {
|
|
@@ -1100,14 +995,14 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- handleCallback(conversation);
|
|
|
|
|
- conversationMapper.update(null, QueryWrapperUtils.buildUpdateWrapper((wrapper)->{
|
|
|
|
|
- wrapper.eq(MidjourneyUserConversation::getAction,"MODEL").eq(MidjourneyUserConversation::getTaskId, conversation.getTaskId()).set(MidjourneyUserConversation::getAction, conversation.getAction());
|
|
|
|
|
- }));
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("发送任务出错 taskId:{}, error:{}", conversation.getTaskId(), StringUtil.getErrorText(e));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ handleCallback(conversation);
|
|
|
|
|
+ conversationMapper.update(null, QueryWrapperUtils.buildUpdateWrapper((wrapper)->{
|
|
|
|
|
+ wrapper.eq(MidjourneyUserConversation::getAction,"MODEL").eq(MidjourneyUserConversation::getTaskId, conversation.getTaskId()).set(MidjourneyUserConversation::getAction, conversation.getAction());
|
|
|
|
|
+ }));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("发送任务出错 taskId:{}, error:{}", conversation.getTaskId(), StringUtil.getErrorText(e));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1257,21 +1152,19 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
conversation.setUserId(user.getId());
|
|
conversation.setUserId(user.getId());
|
|
|
conversation.setStatus("SUCCESS");
|
|
conversation.setStatus("SUCCESS");
|
|
|
String result = jsonObject.getJSONArray("result").getStr(0);
|
|
String result = jsonObject.getJSONArray("result").getStr(0);
|
|
|
- URL url = new URL(result);
|
|
|
|
|
- url = new URL(url.getProtocol(), "cdn.mj.liuliangbang.vip", url.getPort(), url.getFile());
|
|
|
|
|
- conversation.setImageUrl(url.toString());
|
|
|
|
|
|
|
+ conversation.setImageUrl(result);
|
|
|
conversationMapper.insert(conversation);
|
|
conversationMapper.insert(conversation);
|
|
|
- TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
- try {
|
|
|
|
|
- String imageUrl = conversation.getImageUrl();
|
|
|
|
|
- if (StringUtil.isNotBlank(imageUrl)) {
|
|
|
|
|
- conversation.setImageUrl(uploadPic(imageUrl, "conversation"+conversation.getId()));
|
|
|
|
|
- conversationMapper.updateById(conversation);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- log.error("上传图片失败",e);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+// TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
+// try {
|
|
|
|
|
+// String imageUrl = conversation.getImageUrl();
|
|
|
|
|
+// if (StringUtil.isNotBlank(imageUrl)) {
|
|
|
|
|
+// conversation.setImageUrl(uploadPic(imageUrl, "conversation"+conversation.getId()));
|
|
|
|
|
+// conversationMapper.updateById(conversation);
|
|
|
|
|
+// }
|
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
|
+// log.error("上传图片失败",e);
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
return conversation;
|
|
return conversation;
|
|
|
}
|
|
}
|
|
|
|
|
|