Przeglądaj źródła

fix 上传图片

zwhui 2 lat temu
rodzic
commit
1e84ca0724

+ 3 - 0
midjourney/src/main/java/com/yhlxj/dao/model/entity/MidjourneyUserConversation.java

@@ -124,6 +124,9 @@ public class MidjourneyUserConversation extends BaseEntity implements Serializab
             if(StringUtils.isNotBlank(progress)){
                 this.progressNum = Integer.parseInt(this.progress.replace("%",""));
             }
+            if ("FAILURE".equals(this.getStatus())){
+                this.progressNum = 100;
+            }
         }catch (Exception e) {
 
         }

+ 2 - 1
midjourney/src/main/java/com/yhlxj/service/midjourney/MidjourneyService.java

@@ -1,6 +1,7 @@
 package com.yhlxj.service.midjourney;
 
 
+import com.yhlxj.dao.mapper.midjourney.MidjourneyUserConversationMapper;
 import com.yhlxj.dao.model.dto.BlendDimensions;
 import com.yhlxj.dao.model.dto.SubmitUploadDTO;
 import com.yhlxj.dao.model.entity.MidjourneyUser;
@@ -40,7 +41,7 @@ public interface MidjourneyService {
 
     void syscConversation();
 
-    SubmitResult uploadFile(SubmitUploadDTO uploadDTO) throws Exception;
+    MidjourneyUserConversation uploadFile(SubmitUploadDTO uploadDTO,MidjourneyUser user) throws Exception;
 
     void syncMidjourneyStatus();
 }

+ 1 - 0
midjourney/src/main/java/com/yhlxj/service/midjourney/impl/MidJourneyAccountServiceImpl.java

@@ -310,6 +310,7 @@ public class MidJourneyAccountServiceImpl extends ServiceImpl<MidjourneyAccountM
                     midjourneyAccount.setGuildId(Long.parseLong(accountInfo.getGuildId()));
                     midjourneyAccount.setChannelId(Long.parseLong(accountInfo.getChannelId()));
                     midjourneyAccount.setUserToken(accountInfo.getUserToken());
+                    midjourneyAccount.setStatus(accountInfo.isEnable());
                 }
                 midjourneyAccount.setInstanceId(Long.parseLong(accountInfo.getId()));
                 if (midjourneyAccount.getStatus() != accountInfo.isEnable()) {

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

@@ -907,7 +907,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
         synchronized (key.intern()) {
             String currentProgressStr = redisService.getStr(key);
             int currentProgress = StringUtils.isBlank(currentProgressStr) ? 0 : Integer.parseInt(currentProgressStr);
-            if (conversation.getProgressNum() > currentProgress || "FAILURE".equals(conversation.getStatus())) {
+            if (conversation.getProgressNum() > currentProgress) {
                 redisService.set(key, String.valueOf(conversation.getProgressNum()), RedisService.key.MIDJOURNEY_PROGRESS.getTimeout());
                 sendProgressToClient(conversation);
             }
@@ -995,11 +995,21 @@ public class MidjourneyServiceImpl implements MidjourneyService {
     }
 
     @Override
-    public SubmitResult uploadFile(SubmitUploadDTO uploadDTO) throws Exception {
+    public MidjourneyUserConversation uploadFile(SubmitUploadDTO uploadDTO,MidjourneyUser user) throws Exception {
         HttpRequest request = HttpRequest.post(RELAX_HOST + "/mj/submit/upload-discord-images").body(Jsons.toJson(uploadDTO));
         String body = request.execute().body();
         log.info("action body:{}", body);
-        return Jsons.parseObject(body, SubmitResult.class);
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+        if (jsonObject.getInt("code") != 1) {
+            throw BusinessRuntimeException.getInstance("action error message:" + jsonObject.getStr("description"));
+        }
+        MidjourneyUserConversation conversation = new MidjourneyUserConversation();
+        conversation.setAction("UPLOAD");
+        conversation.setUserId(user.getId());
+        conversation.setStatus("SUCCESS");
+        conversation.setImageUrl(jsonObject.getJSONArray("result").getStr(0));
+        conversationMapper.insert(conversation);
+        return conversation;
     }
 
 

+ 3 - 2
midjourney/src/main/java/com/yhlxj/web/mirror/MidjourneyController.java

@@ -576,8 +576,9 @@ public class MidjourneyController {
      * 上传文件到discord
      */
     @PostMapping("/upload")
-    public Result<SubmitResult> upload(@RequestBody SubmitUploadDTO uploadDTO) throws Exception {
+    public Result<MidjourneyUserConversation> upload(@RequestBody SubmitUploadDTO uploadDTO) throws Exception {
         log.info("上传文件到discord");
-        return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyService.uploadFile(uploadDTO));
+        return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyService.uploadFile(uploadDTO,getUser()));
     }
+
 }