|
@@ -514,6 +514,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
token = midjourneyApiChannel.getToken();
|
|
token = midjourneyApiChannel.getToken();
|
|
|
|
|
|
|
|
} else if (mode == 2) {
|
|
} else if (mode == 2) {
|
|
|
|
|
+ synchronized (user.getId()){
|
|
|
|
|
+ userSubmitLimit(user,action,param.get("customId"));
|
|
|
|
|
+ }
|
|
|
url = RELAX_HOST;
|
|
url = RELAX_HOST;
|
|
|
token = RELAX_TOKEN;
|
|
token = RELAX_TOKEN;
|
|
|
//慢速查询在使用次数最少的账号
|
|
//慢速查询在使用次数最少的账号
|
|
@@ -534,9 +537,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
if (StringUtils.isNotBlank(accountWithMinUsage) && mode == 2) {
|
|
if (StringUtils.isNotBlank(accountWithMinUsage) && mode == 2) {
|
|
|
submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
|
|
submitResult.setInstanceId(Long.valueOf(accountWithMinUsage));
|
|
|
- synchronized (user.getId()){
|
|
|
|
|
- userSubmitLimit(user,action,param.get("customId"));
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
return submitResult;
|
|
return submitResult;
|
|
|
}
|
|
}
|
|
@@ -967,52 +967,73 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
log.info("获取到的图片 url:{}", conversation.getImageUrl());
|
|
log.info("获取到的图片 url:{}", conversation.getImageUrl());
|
|
|
ImgSize imgSize = TASK_IMG_SIZE_MAP.get(conversation.getTaskId());
|
|
ImgSize imgSize = TASK_IMG_SIZE_MAP.get(conversation.getTaskId());
|
|
|
URL url = new URL(conversation.getImageUrl());
|
|
URL url = new URL(conversation.getImageUrl());
|
|
|
- if(imgSize != null){
|
|
|
|
|
|
|
+ //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 {
|
|
try {
|
|
|
String filePath = url.getFile();
|
|
String filePath = url.getFile();
|
|
|
- // 注册 WebP 插件
|
|
|
|
|
- ImageIO.scanForPlugins();
|
|
|
|
|
|
|
|
|
|
- // 从 URL 中读取图像,特别处理 WebP 格式
|
|
|
|
|
BufferedImage image = null;
|
|
BufferedImage image = null;
|
|
|
if (filePath.contains("webp")) {
|
|
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));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ image = readWebPImage(url);
|
|
|
} else {
|
|
} else {
|
|
|
image = ImageIO.read(url);
|
|
image = ImageIO.read(url);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (image == null) {
|
|
if (image == null) {
|
|
|
- throw new IOException("Failed to read image from URL: " + conversation.getImageUrl());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (imgSize == null) {
|
|
|
|
|
- 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));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 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));
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("下载图获取尺寸错误, {}", StringUtil.getErrorText(e));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1051,6 +1072,28 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private BufferedImage readWebPImage(URL url) {
|
|
|
|
|
+ BufferedImage image = null;
|
|
|
|
|
+ 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("读取WebP图像错误, {}", StringUtil.getErrorText(e));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return image;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private ImgSize createImgSize(BufferedImage image) {
|
|
|
|
|
+ ImgSize imgSize = new ImgSize();
|
|
|
|
|
+ imgSize.setHeight(image.getHeight());
|
|
|
|
|
+ imgSize.setWidth(image.getWidth());
|
|
|
|
|
+ return imgSize;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void handleCallback(MidjourneyUserConversation conversation) {
|
|
public void handleCallback(MidjourneyUserConversation conversation) {
|
|
|
String key = RedisService.key.MIDJOURNEY_PROGRESS.getName() + conversation.getTaskId();
|
|
String key = RedisService.key.MIDJOURNEY_PROGRESS.getName() + conversation.getTaskId();
|
|
|
|
|
|