|
@@ -69,7 +69,6 @@ import static com.yhlxj.web.wss.MidjourneyServerEndpoint.WSS_SESSION_MAP;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
public class MidjourneyServiceImpl implements MidjourneyService {
|
|
public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
- private static final String RELAX_HOST = "http://172.17.0.1:8086";
|
|
|
|
|
private static final String RELAX_TOKEN = "chen188710";
|
|
private static final String RELAX_TOKEN = "chen188710";
|
|
|
private static final Map<String, ImgSize> TASK_IMG_SIZE_MAP = new ConcurrentHashMap<>();
|
|
private static final Map<String, ImgSize> TASK_IMG_SIZE_MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
@@ -97,6 +96,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
@Value("${midjourney.url}")
|
|
@Value("${midjourney.url}")
|
|
|
private String midjourneyHost;
|
|
private String midjourneyHost;
|
|
|
|
|
|
|
|
|
|
+ @Value("${midjourney.apiUrl}")
|
|
|
|
|
+ private String apiUrl;
|
|
|
|
|
+
|
|
|
private final EnvCommonService envCommonService;
|
|
private final EnvCommonService envCommonService;
|
|
|
|
|
|
|
|
private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
@@ -351,7 +353,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private SubmitResult seed(String taskId) throws Exception {
|
|
private SubmitResult seed(String taskId) throws Exception {
|
|
|
- String url = RELAX_HOST + String.format("/mj/task/%s/image-seed", taskId);
|
|
|
|
|
|
|
+ String url = apiUrl + String.format("/mj/task/%s/image-seed", taskId);
|
|
|
String body = HttpRequest.get(url).header("Authorization", RELAX_TOKEN).execute().body();
|
|
String body = HttpRequest.get(url).header("Authorization", RELAX_TOKEN).execute().body();
|
|
|
log.info("seed body:{}", body);
|
|
log.info("seed body:{}", body);
|
|
|
SubmitResult submitResult = Jsons.parseObject(body, SubmitResult.class);
|
|
SubmitResult submitResult = Jsons.parseObject(body, SubmitResult.class);
|
|
@@ -409,6 +411,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
conversation.setButtons(Jsons.toJson(messageButtons));
|
|
conversation.setButtons(Jsons.toJson(messageButtons));
|
|
|
|
|
+ conversationMapper.updateById(conversation);
|
|
|
}
|
|
}
|
|
|
if (customId.contains("BOOKMARK")) {
|
|
if (customId.contains("BOOKMARK")) {
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
TASK_EXECUTOR.execute(() -> {
|
|
@@ -477,9 +480,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
// if (accountWithMinUsage == null) {
|
|
// if (accountWithMinUsage == null) {
|
|
|
// throw new Exception("没有可用的账号");
|
|
// throw new Exception("没有可用的账号");
|
|
|
// }
|
|
// }
|
|
|
- param.put("accountFilter",MapUtil.builder(new HashMap<String,Object>())
|
|
|
|
|
|
|
+ //param.put("accountFilter",MapUtil.builder(new HashMap<String,Object>())
|
|
|
//.put("instanceId",accountWithMinUsage).build());
|
|
//.put("instanceId",accountWithMinUsage).build());
|
|
|
- .put("modes",List.of(mode == 1 ? "FAST" : "RELAX")).build());
|
|
|
|
|
|
|
+ //.put("modes",List.of(mode == 1 ? "FAST" : "RELAX")).build());
|
|
|
if (mode == 2) {
|
|
if (mode == 2) {
|
|
|
synchronized (user.getId()){
|
|
synchronized (user.getId()){
|
|
|
userSubmitLimit(user,action,param.get("customId"),again);
|
|
userSubmitLimit(user,action,param.get("customId"),again);
|
|
@@ -552,7 +555,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
host = host + "/8083/api/applets/midjourney/notifyHook";
|
|
host = host + "/8083/api/applets/midjourney/notifyHook";
|
|
|
}
|
|
}
|
|
|
param.put("notifyHook",host);
|
|
param.put("notifyHook",host);
|
|
|
- HttpRequest request = HttpRequest.post(RELAX_HOST + getActionUrl(action)).header("mj-api-secret", RELAX_TOKEN).body(Jsons.toJson(param));
|
|
|
|
|
|
|
+ HttpRequest request = HttpRequest.post(apiUrl + getActionUrl(action,mode)).header("mj-api-secret", RELAX_TOKEN).body(Jsons.toJson(param));
|
|
|
String body = request.execute().body();
|
|
String body = request.execute().body();
|
|
|
log.info("action body:{}", body);
|
|
log.info("action body:{}", body);
|
|
|
return Jsons.parseObject(body, SubmitResult.class);
|
|
return Jsons.parseObject(body, SubmitResult.class);
|
|
@@ -662,20 +665,21 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
throw BusinessRuntimeException.getInstance("获取账号失败");
|
|
throw BusinessRuntimeException.getInstance("获取账号失败");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- private String getActionUrl(String action) {
|
|
|
|
|
|
|
+ private String getActionUrl(String action,Integer mode) {
|
|
|
|
|
+ String url = mode == 1 ? "/mj-fast" : "/mj-relax";
|
|
|
switch (action) {
|
|
switch (action) {
|
|
|
case "imagine":
|
|
case "imagine":
|
|
|
- return "/mj/submit/imagine";
|
|
|
|
|
|
|
+ return url + "/mj/submit/imagine";
|
|
|
case "action":
|
|
case "action":
|
|
|
- return "/mj/submit/action";
|
|
|
|
|
|
|
+ return url + "/mj/submit/action";
|
|
|
case "describe":
|
|
case "describe":
|
|
|
- return "/mj/submit/describe";
|
|
|
|
|
|
|
+ return url + "/mj/submit/describe";
|
|
|
case "blend":
|
|
case "blend":
|
|
|
- return"/mj/submit/blend";
|
|
|
|
|
|
|
+ return url + "/mj/submit/blend";
|
|
|
case "modal":
|
|
case "modal":
|
|
|
- return "/mj/submit/modal";
|
|
|
|
|
|
|
+ return url + "/mj/submit/modal";
|
|
|
case "shorten":
|
|
case "shorten":
|
|
|
- return "/mj/submit/shorten";
|
|
|
|
|
|
|
+ return url + "/mj/submit/shorten";
|
|
|
default: throw new IllegalArgumentException("Unknown action: " + action);
|
|
default: throw new IllegalArgumentException("Unknown action: " + action);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -762,6 +766,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
conversation.setOriginalImageUrl(conversation.getImageUrl());
|
|
conversation.setOriginalImageUrl(conversation.getImageUrl());
|
|
|
conversation.setAction(dbConversation.getAction());
|
|
conversation.setAction(dbConversation.getAction());
|
|
|
|
|
+ conversation.setMode(dbConversation.getMode());
|
|
|
conversation.setId(dbConversation.getId());
|
|
conversation.setId(dbConversation.getId());
|
|
|
conversationMapper.updateById(conversation);
|
|
conversationMapper.updateById(conversation);
|
|
|
//失败返还次数
|
|
//失败返还次数
|
|
@@ -888,7 +893,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
public JSONArray listByIds(List<String> ids) throws Exception {
|
|
public JSONArray listByIds(List<String> 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();
|
|
|
- HttpRequest request = HttpRequest.post(RELAX_HOST + "/mj/task/list-by-condition").header("mj-api-secret", RELAX_TOKEN);
|
|
|
|
|
|
|
+ HttpRequest request = HttpRequest.post(apiUrl + "/mj/task/list-by-condition").header("mj-api-secret", RELAX_TOKEN);
|
|
|
String body = request.body(Jsons.toJson(param)).execute().body();
|
|
String body = request.body(Jsons.toJson(param)).execute().body();
|
|
|
log.info("listByIds body:{}", body);
|
|
log.info("listByIds body:{}", body);
|
|
|
return JSONUtil.parseArray(body);
|
|
return JSONUtil.parseArray(body);
|
|
@@ -913,7 +918,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void cancel(Long taskId) {
|
|
public void cancel(Long taskId) {
|
|
|
- String body = HttpUtil.post(RELAX_HOST + "/mj/task/"+taskId+"/cancel",MapUtil.empty());
|
|
|
|
|
|
|
+ String body = HttpUtil.post(apiUrl + "/mj/task/"+taskId+"/cancel",MapUtil.empty());
|
|
|
log.info("cancel body:{}", body);
|
|
log.info("cancel body:{}", body);
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(body);
|
|
JSONObject jsonObject = JSONUtil.parseObj(body);
|
|
|
if (jsonObject.getInt("code") != 1) {
|
|
if (jsonObject.getInt("code") != 1) {
|
|
@@ -1211,7 +1216,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public MidjourneyUserConversation uploadFile(SubmitUploadDTO uploadDTO,MidjourneyUser user) throws Exception {
|
|
public MidjourneyUserConversation uploadFile(SubmitUploadDTO uploadDTO,MidjourneyUser user) throws Exception {
|
|
|
- HttpRequest request = HttpRequest.post(RELAX_HOST + "/mj/submit/upload-discord-images").header("mj-api-secret", RELAX_TOKEN).body(Jsons.toJson(uploadDTO));
|
|
|
|
|
|
|
+ HttpRequest request = HttpRequest.post(apiUrl + "/mj/submit/upload-discord-images").header("mj-api-secret", RELAX_TOKEN).body(Jsons.toJson(uploadDTO));
|
|
|
String body = request.execute().body();
|
|
String body = request.execute().body();
|
|
|
log.info("action body:{}", body);
|
|
log.info("action body:{}", body);
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(body);
|
|
JSONObject jsonObject = JSONUtil.parseObj(body);
|