|
|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.service.midjourney.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
@@ -226,6 +227,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (result.getCode() == 21) {
|
|
|
// 以上操作有弹窗确认,恢复次数
|
|
|
recoverUserLimit(user.getId(), user.getMode(),num);
|
|
|
+ if (user.getMode() == 2){
|
|
|
+ redisService.hdecr(RedisService.key.MIDJOURNEY_ACCOUNT.getName() , String.valueOf(conversation.getInstanceId()), 1.0);
|
|
|
+ }
|
|
|
}else {
|
|
|
syncUser(user.getId(), user.getMode(),num);
|
|
|
}
|
|
|
@@ -257,6 +261,10 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (code == 3) {
|
|
|
if(mode == 2 && StringUtils.isNotBlank(accountWithMinUsage)){
|
|
|
redisService.hdel(RedisService.key.MIDJOURNEY_ACCOUNT.getName(),accountWithMinUsage);
|
|
|
+ TASK_EXECUTOR.execute(() -> {
|
|
|
+ MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, instanceId).last("limit 1"));
|
|
|
+ midjourneyAccountService.updateStatus(account.getId());
|
|
|
+ });
|
|
|
}
|
|
|
throw BusinessRuntimeException.getInstance("账号不存在");
|
|
|
}
|
|
|
@@ -412,13 +420,15 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
private static String uploadPic(String url, String prefix) throws IOException {
|
|
|
byte[] body = HttpUtil.downloadBytes(url);
|
|
|
Path tempFile = Files.createTempFile(prefix, ".png");
|
|
|
- try (FileImageOutputStream imageOutput = new FileImageOutputStream(tempFile.toFile())) {
|
|
|
+ File file = tempFile.toFile();
|
|
|
+ try (FileImageOutputStream imageOutput = new FileImageOutputStream(file)) {
|
|
|
imageOutput.write(body, 0, body.length);
|
|
|
}
|
|
|
Map<String, Object> paramMap = new HashMap<>();
|
|
|
- paramMap.put("file", tempFile.toFile());
|
|
|
+ paramMap.put("file", file);
|
|
|
String json = HttpUtil.post("https://files.liuliangbang.vip/pic/ups", paramMap);
|
|
|
log.info("上传图片结果:url:{},json:{}",url, json);
|
|
|
+ FileUtil.del(file);
|
|
|
return new JSONObject(json).getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
|
|
|
}
|
|
|
|