|
@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.URLUtil;
|
|
import cn.hutool.core.util.URLUtil;
|
|
|
|
|
+import cn.hutool.db.sql.SqlBuilder;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONArray;
|
|
@@ -164,7 +165,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
public SubmitResult submitImagine(MidjourneyUser user, Integer mode,String prompt, String botType, List<String> base64Array, Long num) throws Exception {
|
|
public SubmitResult submitImagine(MidjourneyUser user, Integer mode,String prompt, String botType, List<String> base64Array, Long num) throws Exception {
|
|
|
Map<String, Object> imagineParam = MapUtil.builder(new HashMap<String,Object>())
|
|
Map<String, Object> imagineParam = MapUtil.builder(new HashMap<String,Object>())
|
|
|
.put("prompt", prompt)
|
|
.put("prompt", prompt)
|
|
|
- .put("state", user.getId().toString())
|
|
|
|
|
|
|
+ .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
.build();
|
|
.build();
|
|
|
if (CollectionUtil.isNotEmpty(base64Array)) {
|
|
if (CollectionUtil.isNotEmpty(base64Array)) {
|
|
|
imagineParam.put("base64Array", base64Array);
|
|
imagineParam.put("base64Array", base64Array);
|
|
@@ -175,7 +176,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}else {
|
|
}else {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
|
}
|
|
}
|
|
|
- saveConversation(user.getId(), mode,result,"IMAGINE", StringUtils.EMPTY, botType);
|
|
|
|
|
|
|
+ saveConversation(user, mode,result,"IMAGINE", StringUtils.EMPTY, botType);
|
|
|
Map<String, Object> properties = result.getProperties();
|
|
Map<String, Object> properties = result.getProperties();
|
|
|
String modeStr;
|
|
String modeStr;
|
|
|
String mjVersionStatusKey;
|
|
String mjVersionStatusKey;
|
|
@@ -201,7 +202,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public MidjourneyUserConversation saveConversation(Long userId,Integer mode,SubmitResult result, String action,String prompt,String botType) throws Exception {
|
|
|
|
|
|
|
+ public MidjourneyUserConversation saveConversation(MidjourneyUser user,Integer mode,SubmitResult result, String action,String prompt,String botType) throws Exception {
|
|
|
if (result.getCode() == 23) {
|
|
if (result.getCode() == 23) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -213,7 +214,8 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
if (conversation == null){
|
|
if (conversation == null){
|
|
|
conversation = new MidjourneyUserConversation();
|
|
conversation = new MidjourneyUserConversation();
|
|
|
- conversation.setUserId(userId);
|
|
|
|
|
|
|
+ conversation.setUserId(user.getId());
|
|
|
|
|
+ conversation.setUserToken(user.getUserToken());
|
|
|
conversation.setTaskId(taskId);
|
|
conversation.setTaskId(taskId);
|
|
|
conversation.setAction(action);
|
|
conversation.setAction(action);
|
|
|
conversation.setPrompt(prompt);
|
|
conversation.setPrompt(prompt);
|
|
@@ -239,14 +241,14 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
@Override
|
|
@Override
|
|
|
public SubmitResult submitDescribe(MidjourneyUser user,Integer mode, String botType, String base64, Long num) throws Exception {
|
|
public SubmitResult submitDescribe(MidjourneyUser user,Integer mode, String botType, String base64, Long num) throws Exception {
|
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
- .put("state", user.getId().toString())
|
|
|
|
|
|
|
+ .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
.put("base64", base64)
|
|
.put("base64", base64)
|
|
|
.build();
|
|
.build();
|
|
|
SubmitResult result = submit(user,mode,"describe", null, param,false, num);
|
|
SubmitResult result = submit(user,mode,"describe", null, param,false, num);
|
|
|
if (mode == 2) {
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
|
}
|
|
}
|
|
|
- saveConversation(user.getId(), mode,result,"DESCRIBE", StringUtils.EMPTY, botType);
|
|
|
|
|
|
|
+ saveConversation(user, mode,result,"DESCRIBE", StringUtils.EMPTY, botType);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -254,7 +256,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
public SubmitResult submitBlend(MidjourneyUser user, Integer mode,BlendDimensions dimensions, String botType, List<String> base64Array, Long num) throws Exception {
|
|
public SubmitResult submitBlend(MidjourneyUser user, Integer mode,BlendDimensions dimensions, String botType, List<String> base64Array, Long num) throws Exception {
|
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
.put("base64Array", base64Array)
|
|
.put("base64Array", base64Array)
|
|
|
- .put("state", user.getId().toString())
|
|
|
|
|
|
|
+ .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
.build();
|
|
.build();
|
|
|
if (dimensions != null) {
|
|
if (dimensions != null) {
|
|
|
param.put("dimensions", dimensions);
|
|
param.put("dimensions", dimensions);
|
|
@@ -263,7 +265,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (mode == 2) {
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
|
}
|
|
}
|
|
|
- saveConversation(user.getId(), mode,result,"BLEND", StringUtils.EMPTY, botType);
|
|
|
|
|
|
|
+ saveConversation(user, mode,result,"BLEND", StringUtils.EMPTY, botType);
|
|
|
Map<String, Object> properties = result.getProperties();
|
|
Map<String, Object> properties = result.getProperties();
|
|
|
MjVersionStatus mjVersionStatus = MJ_VERSION_STATUS_MAP.get(mode == 1 ? "v6-fast-model" : "v6-relax-model");
|
|
MjVersionStatus mjVersionStatus = MJ_VERSION_STATUS_MAP.get(mode == 1 ? "v6-fast-model" : "v6-relax-model");
|
|
|
int count = 1;
|
|
int count = 1;
|
|
@@ -284,7 +286,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
MidjourneyUserConversation midjourneyUserConversation = conversationMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUserConversation.class).eq(MidjourneyUserConversation::getTaskId, taskId).last("limit 1"));
|
|
MidjourneyUserConversation midjourneyUserConversation = conversationMapper.selectOne(Wrappers.lambdaQuery(MidjourneyUserConversation.class).eq(MidjourneyUserConversation::getTaskId, taskId).last("limit 1"));
|
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
.put("taskId", taskId.toString())
|
|
.put("taskId", taskId.toString())
|
|
|
- .put("state", user.getId().toString())
|
|
|
|
|
|
|
+ .put("state",String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
.build();
|
|
.build();
|
|
|
if (StringUtils.isNotBlank(prompt)) {
|
|
if (StringUtils.isNotBlank(prompt)) {
|
|
|
param.put("prompt", prompt);
|
|
param.put("prompt", prompt);
|
|
@@ -305,7 +307,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
SubmitResult result = submit(user,mode,"modal", null, param,false, num);
|
|
SubmitResult result = submit(user,mode,"modal", null, param,false, num);
|
|
|
- saveConversation(user.getId(), mode,result,"MODAL", StringUtils.EMPTY, StringUtils.EMPTY);
|
|
|
|
|
|
|
+ saveConversation(user, mode,result,"MODAL", StringUtils.EMPTY, StringUtils.EMPTY);
|
|
|
Map<String, Object> properties = result.getProperties();
|
|
Map<String, Object> properties = result.getProperties();
|
|
|
String modeStr;
|
|
String modeStr;
|
|
|
String mjVersionStatusKey;
|
|
String mjVersionStatusKey;
|
|
@@ -337,13 +339,13 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
public SubmitResult submitShorten(MidjourneyUser user,Integer mode, String botType, String prompt, Long num) throws Exception {
|
|
public SubmitResult submitShorten(MidjourneyUser user,Integer mode, String botType, String prompt, Long num) throws Exception {
|
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
.put("prompt", prompt)
|
|
.put("prompt", prompt)
|
|
|
- .put("state", user.getId().toString())
|
|
|
|
|
|
|
+ .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
.build();
|
|
.build();
|
|
|
SubmitResult result = submit(user,mode,"shorten", null, param,false, num);
|
|
SubmitResult result = submit(user,mode,"shorten", null, param,false, num);
|
|
|
if (mode == 2) {
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getProperties().get("discordInstanceId").toString(), 1.0);
|
|
|
}
|
|
}
|
|
|
- saveConversation(user.getId(), mode, result,"SHORTEN", StringUtils.EMPTY, botType);
|
|
|
|
|
|
|
+ saveConversation(user, mode, result,"SHORTEN", StringUtils.EMPTY, botType);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -430,7 +432,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
Map<String, Object> param = MapUtil.builder(new HashMap<String,Object>())
|
|
|
.put("taskId", taskId)
|
|
.put("taskId", taskId)
|
|
|
- .put("state", user.getId().toString())
|
|
|
|
|
|
|
+ .put("state", String.join(",",user.getId().toString(),user.getUserToken()))
|
|
|
.put("customId", customId)
|
|
.put("customId", customId)
|
|
|
.build();
|
|
.build();
|
|
|
SubmitResult result = submit(user,mode,"action", conversation.getInstanceId(),param,false, num);
|
|
SubmitResult result = submit(user,mode,"action", conversation.getInstanceId(),param,false, num);
|
|
@@ -468,7 +470,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
}
|
|
|
properties.put("estimateTime", System.currentTimeMillis() + (second * count));
|
|
properties.put("estimateTime", System.currentTimeMillis() + (second * count));
|
|
|
properties.put("finalPrompt",conversation.getPrompt());
|
|
properties.put("finalPrompt",conversation.getPrompt());
|
|
|
- MidjourneyUserConversation midjourneyUserConversation = saveConversation(user.getId(), mode, result, "ACTION", StringUtils.EMPTY, botType);
|
|
|
|
|
|
|
+ MidjourneyUserConversation midjourneyUserConversation = saveConversation(user, mode, result, "ACTION", StringUtils.EMPTY, botType);
|
|
|
properties.put("id",midjourneyUserConversation.getId());
|
|
properties.put("id",midjourneyUserConversation.getId());
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -697,7 +699,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (StringUtil.isNotBlank(conversation.getImageUrl())) {
|
|
if (StringUtil.isNotBlank(conversation.getImageUrl())) {
|
|
|
conversation.setImageUrl(conversation.getImageUrl().replace("cdn.discordapp.com", "mj.galaxydvd.com"));
|
|
conversation.setImageUrl(conversation.getImageUrl().replace("cdn.discordapp.com", "mj.galaxydvd.com"));
|
|
|
}
|
|
}
|
|
|
- conversation.setUserId(jsons.getLong("state"));
|
|
|
|
|
|
|
+ String[] states = jsons.getStr("state").split(",");
|
|
|
|
|
+ conversation.setUserId(Long.parseLong(states[0]));
|
|
|
|
|
+ conversation.setUserToken(states[1]);
|
|
|
conversation.setTaskId(jsons.getStr("id"));
|
|
conversation.setTaskId(jsons.getStr("id"));
|
|
|
list.add(conversation);
|
|
list.add(conversation);
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
TASK_EXECUTOR.execute(() -> {
|
|
@@ -805,7 +809,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
|
|
|
|
|
private static String uploadPic(String url, String prefix) throws IOException {
|
|
private static String uploadPic(String url, String prefix) throws IOException {
|
|
|
// 替换 URL 并下载图像字节
|
|
// 替换 URL 并下载图像字节
|
|
|
- url = url.replace("cdn.mj.liuliangbang.vip", "media.liuliangbang.vip");
|
|
|
|
|
|
|
+ url = url.replace("cdn.mj.liuliangbang.vip", "cdn.discordapp.com");
|
|
|
|
|
|
|
|
byte[] body;
|
|
byte[] body;
|
|
|
try {
|
|
try {
|
|
@@ -943,7 +947,9 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (conversation.getPrompt() == null){
|
|
if (conversation.getPrompt() == null){
|
|
|
conversation.setPrompt(jsons.getStr("promptFull"));
|
|
conversation.setPrompt(jsons.getStr("promptFull"));
|
|
|
}
|
|
}
|
|
|
- conversation.setUserId(jsons.getLong("state"));
|
|
|
|
|
|
|
+ String[] states = jsons.getStr("state").split(",");
|
|
|
|
|
+ conversation.setUserId(Long.parseLong(states[0]));
|
|
|
|
|
+ conversation.setUserToken(states[1]);
|
|
|
conversation.setTaskId(jsons.getStr("id"));
|
|
conversation.setTaskId(jsons.getStr("id"));
|
|
|
conversation.setId(null);
|
|
conversation.setId(null);
|
|
|
JSONObject jsonObject = new JSONObject(conversation.getProperties());
|
|
JSONObject jsonObject = new JSONObject(conversation.getProperties());
|
|
@@ -1169,11 +1175,11 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if(JSONUtil.isJson(conversation.getFailReason())){
|
|
if(JSONUtil.isJson(conversation.getFailReason())){
|
|
|
conversation.setFailReason("生成图片失败");
|
|
conversation.setFailReason("生成图片失败");
|
|
|
}
|
|
}
|
|
|
- String url = "https://web.liuliangbang.vip/8080/api/msg/send";
|
|
|
|
|
|
|
+ String url = "https://mj.liuliangbang.vip/8080/api/msg/send";
|
|
|
Map<String, Object> data = MapUtil.builder(new HashMap<String,Object>())
|
|
Map<String, Object> data = MapUtil.builder(new HashMap<String,Object>())
|
|
|
.put("taskId", conversation.getTaskId())
|
|
.put("taskId", conversation.getTaskId())
|
|
|
.put("msg", JSONUtil.toJsonStr(conversation))
|
|
.put("msg", JSONUtil.toJsonStr(conversation))
|
|
|
- .put("userId", conversation.getUserId())
|
|
|
|
|
|
|
+ .put("userToken", conversation.getUserToken())
|
|
|
.build();
|
|
.build();
|
|
|
HttpUtil.post(url, JSONUtil.toJsonStr(data));
|
|
HttpUtil.post(url, JSONUtil.toJsonStr(data));
|
|
|
//wssSession.sendMessage(WsMessageTypeEnum.SERVER_TASK_INFO, new JSONObject(conversation));
|
|
//wssSession.sendMessage(WsMessageTypeEnum.SERVER_TASK_INFO, new JSONObject(conversation));
|