|
@@ -30,6 +30,7 @@ import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author zwhui
|
|
* @author zwhui
|
|
@@ -95,7 +96,14 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
param.put("dimensions", dimensions);
|
|
param.put("dimensions", dimensions);
|
|
|
}
|
|
}
|
|
|
SubmitResult result = submit(user.getMode(),"blend", param);
|
|
SubmitResult result = submit(user.getMode(),"blend", param);
|
|
|
- return saveConversation(user.getId(), user.getMode(), Long.parseLong(result.getResult()),result.getProperties(),"BLEND", StringUtils.EMPTY);
|
|
|
|
|
|
|
+ Map<String, Object> properties = result.getProperties();
|
|
|
|
|
+ if (user.getMode() == 1) {
|
|
|
|
|
+ String finalPrompt = "%s --ar %s --style raw --s 250";
|
|
|
|
|
+ List<String> picList = uploadBase64Pic(base64Array);
|
|
|
|
|
+ String pics = picList.stream().map(pic -> "<" + pic + ">").collect(Collectors.joining(" "));
|
|
|
|
|
+ properties.put("finalPrompt", String.format(finalPrompt, pics,dimensions.getValue()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return saveConversation(user.getId(), user.getMode(), Long.parseLong(result.getResult()),properties,"BLEND", StringUtils.EMPTY);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -188,6 +196,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (code == 3) {
|
|
if (code == 3) {
|
|
|
throw BusinessRuntimeException.getInstance("账号不存在");
|
|
throw BusinessRuntimeException.getInstance("账号不存在");
|
|
|
}
|
|
}
|
|
|
|
|
+ if (code == 4) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("图片重复");
|
|
|
|
|
+ }
|
|
|
if (code == 24) {
|
|
if (code == 24) {
|
|
|
throw BusinessRuntimeException.getInstance("prompt包含敏感词");
|
|
throw BusinessRuntimeException.getInstance("prompt包含敏感词");
|
|
|
}
|
|
}
|
|
@@ -266,6 +277,27 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
JSONObject result = JSONUtil.parseObj(HttpUtil.post("https://files.liuliangbang.vip/pic/ups", paramMap));
|
|
JSONObject result = JSONUtil.parseObj(HttpUtil.post("https://files.liuliangbang.vip/pic/ups", paramMap));
|
|
|
return result.getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
|
|
return result.getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private static List<String> uploadBase64Pic(List<String> base64Array) throws IOException {
|
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
|
+ for (String base64 : base64Array) {
|
|
|
|
|
+ String fileExt = "jpeg";
|
|
|
|
|
+ if (base64.contains(";")){
|
|
|
|
|
+ fileExt = base64.split(";")[0].split("/")[1];
|
|
|
|
|
+ base64 = base64.split(",")[1];
|
|
|
|
|
+ }
|
|
|
|
|
+ byte[] body = Base64.getDecoder().decode(base64);
|
|
|
|
|
+ Path tempFile = Files.createTempFile(UUID.randomUUID().toString(), "." + fileExt);
|
|
|
|
|
+ try (FileImageOutputStream imageOutput = new FileImageOutputStream(tempFile.toFile())) {
|
|
|
|
|
+ imageOutput.write(body, 0, body.length);
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
|
|
+ paramMap.put("file", tempFile.toFile());
|
|
|
|
|
+ JSONObject result = JSONUtil.parseObj(HttpUtil.post("https://files.liuliangbang.vip/pic/ups", paramMap));
|
|
|
|
|
+ list.add(result.getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl"));
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
public JSONArray listByIds(Integer mode,List<Long> ids) throws Exception {
|
|
public JSONArray listByIds(Integer mode,List<Long> ids) throws Exception {
|
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String, Object>()).put("ids", ids).build();
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String, Object>()).put("ids", ids).build();
|
|
|
String body = HttpRequest.post((mode == 1 ? FAST_HOST : RELAX_HOST) + "/mj/task/list-by-condition").header("Authorization", FAST_TOKEN).body(Jsons.toJson(param)).execute().body();
|
|
String body = HttpRequest.post((mode == 1 ? FAST_HOST : RELAX_HOST) + "/mj/task/list-by-condition").header("Authorization", FAST_TOKEN).body(Jsons.toJson(param)).execute().body();
|