chenbiao 2 rokov pred
rodič
commit
53c5147a35

+ 14 - 14
midjourney/src/main/java/com/yhlxj/service/midjourney/impl/MidjourneyServiceImpl.java

@@ -835,7 +835,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
                     .eq(MidjourneyUserConversation::getUserId, userId).orderByDesc(MidjourneyUserConversation::getId).last(" limit 1"));
             if (dbConversation != null) {
                 if ("SUCCESS".equals(dbConversation.getStatus()) || "FAILURE".equals(dbConversation.getStatus())) {
-                    TASK_IMG_SIZE_MAP.remove(dbConversation.getTaskId());
                     return;
                 }
                 if (conversation.getProgressNum() <= dbConversation.getProgressNum() && !conversation.getStatus().equals("FAILURE")){
@@ -1047,7 +1046,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
         if (StringUtil.isNotBlank(conversation.getImageUrl())) {
             log.info("获取到的图片 url:{}", conversation.getImageUrl());
             ImgSize imgSize = TASK_IMG_SIZE_MAP.get(conversation.getTaskId());
-            URL url = new URL(conversation.getImageUrl().replace("mj.galaxydvd.com","media.discordapp.net"));
+            String imgUrl = conversation.getImageUrl();
+            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();
@@ -1147,7 +1150,6 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             conversation.setImageUrl(newUrl);
         }
         redisService.set(RedisService.key.MIDJOURNEY_CONVERSATION.getName() + conversation.getTaskId(), conversation,RedisService.key.MIDJOURNEY_CONVERSATION.getTimeout());
-
         TASK_EXECUTOR.execute(() -> {
             try {
                 MidjourneyUserConversation conversation1 = new MidjourneyUserConversation();
@@ -1266,7 +1268,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
 
 
     @Override
-    public void syscConversation() throws Exception {
+    public synchronized void syscConversation() throws Exception {
         List<MidjourneyUserConversation> fastMidjourneyUserConversations = conversationMapper.selectList(Wrappers.lambdaQuery(MidjourneyUserConversation.class)
                 .notIn(MidjourneyUserConversation::getStatus, List.of("SUCCESS","MODAL","FAILURE")).eq(MidjourneyUserConversation::getMode,1).orderByAsc(MidjourneyUserConversation::getId).last(" limit 100"));
 
@@ -1291,26 +1293,24 @@ public class MidjourneyServiceImpl implements MidjourneyService {
             notifyHook(Jsons.toJson(json));
         }
 
-
         //上传图片到cos
         List<MidjourneyUserConversation> imgConversations = conversationMapper.selectList(Wrappers.lambdaQuery(MidjourneyUserConversation.class)
-                .eq(MidjourneyUserConversation::getStatus,"SUCCESS").notLike(MidjourneyUserConversation::getImageUrl,"cdn.mj.galaxydvd.com")
+                .eq(MidjourneyUserConversation::getStatus, "SUCCESS").notLike(MidjourneyUserConversation::getImageUrl, "cdn.mj.galaxydvd.com")
                 .ge(MidjourneyUserConversation::getCreatedTime, DateUtil.offsetMinute(new Date(), -60 * 24)).orderByAsc(MidjourneyUserConversation::getId).last(" limit 10"));
-
-        for (MidjourneyUserConversation conversation : imgConversations) {
-            TASK_EXECUTOR.execute(() -> {
+        TASK_EXECUTOR.execute(() -> {
+            for (MidjourneyUserConversation conversation : imgConversations) {
                 try {
                     String imageUrl = conversation.getImageUrl();
                     if (StringUtil.isNotBlank(imageUrl)) {
-                        conversation.setImageUrl(uploadPic(imageUrl, "conversation"+conversation.getId()));
+                        conversation.setImageUrl(uploadPic(imageUrl, "conversation" + conversation.getId()));
                         conversationMapper.updateById(conversation);
-                        TASK_IMG_SIZE_MAP.remove(conversation.getTaskId());
                     }
                 } catch (IOException e) {
-                    log.error("上传图片失败",e);
+                    log.error("上传图片失败", e);
                 }
-            });
-        }
+
+            }
+        });
     }
 
     @Override