|
|
@@ -121,7 +121,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (CollectionUtil.isNotEmpty(base64Array)) {
|
|
|
imagineParam.put("base64Array", base64Array);
|
|
|
}
|
|
|
- SubmitResult result = submit(mode,"imagine", null,imagineParam);
|
|
|
+ SubmitResult result = submit(user,mode,"imagine", null,imagineParam);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
@@ -163,7 +163,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
.put("state", user.getId())
|
|
|
.put("base64", base64)
|
|
|
.build();
|
|
|
- SubmitResult result = submit(mode,"describe", null, param);
|
|
|
+ SubmitResult result = submit(user,mode,"describe", null, param);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
@@ -179,7 +179,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (dimensions != null) {
|
|
|
param.put("dimensions", dimensions);
|
|
|
}
|
|
|
- SubmitResult result = submit(mode,"blend", null, param);
|
|
|
+ SubmitResult result = submit(user,mode,"blend", null, param);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
@@ -198,7 +198,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
if (StringUtils.isNotBlank(maskBase64)) {
|
|
|
param.put("maskBase64", maskBase64);
|
|
|
}
|
|
|
- SubmitResult result = submit(mode,"modal", null, param);
|
|
|
+ SubmitResult result = submit(user,mode,"modal", null, param);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
@@ -211,7 +211,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
.put("prompt", prompt)
|
|
|
.put("state", user.getId())
|
|
|
.build();
|
|
|
- SubmitResult result = submit(mode,"shorten", null, param);
|
|
|
+ SubmitResult result = submit(user,mode,"shorten", null, param);
|
|
|
if (mode == 2) {
|
|
|
redisService.hincr(RedisService.key.MIDJOURNEY_ACCOUNT.getName(), result.getInstanceId().toString(), 1.0);
|
|
|
}
|
|
|
@@ -324,7 +324,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
.put("state", user.getId())
|
|
|
.put("customId", customId)
|
|
|
.build();
|
|
|
- SubmitResult result = submit(mode,"action", conversation.getInstanceId(),param);
|
|
|
+ SubmitResult result = submit(user,mode,"action", conversation.getInstanceId(),param);
|
|
|
if (result.getCode() == 21) {
|
|
|
if (mode == 2 && modalFlag.get()){
|
|
|
MidjourneyUserConversation modal = submitModal(user, mode,Long.valueOf(result.getResult()), conversation.getPrompt(), null);
|
|
|
@@ -345,7 +345,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public SubmitResult submit(Integer mode,String action,Long instanceId, Map<String, Object> param) throws Exception {
|
|
|
+ public SubmitResult submit(MidjourneyUser user,Integer mode,String action,Long instanceId, Map<String, Object> param) throws Exception {
|
|
|
String url = "";
|
|
|
String accountWithMinUsage = "";
|
|
|
if (mode == 1) {
|
|
|
@@ -360,6 +360,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
}
|
|
|
param.put("accountFilter",MapUtil.builder(new HashMap<String,Object>())
|
|
|
.put("instanceId",accountWithMinUsage).build());
|
|
|
+ userSubmitLimit(user,action,param.get("customId"));
|
|
|
}
|
|
|
url = url + getActionUrl(action);
|
|
|
param.put("notifyHook",midjourneyHost +(EnvCommonService.active.equals(envCommonService.getEnv()) ? "/8083":"/8082") + "/api/applets/midjourney/notifyHook");
|
|
|
@@ -376,7 +377,7 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
MidjourneyAccount account = midjourneyAccountService.getOne(Wrappers.lambdaQuery(MidjourneyAccount.class).eq(MidjourneyAccount::getInstanceId, finalAccountWithMinUsage).last("limit 1"));
|
|
|
midjourneyAccountService.updateStatus(account.getId());
|
|
|
});
|
|
|
- submit(mode, action, instanceId, param);
|
|
|
+ submit(user,mode, action, instanceId, param);
|
|
|
}
|
|
|
throw BusinessRuntimeException.getInstance("账号不存在");
|
|
|
}
|
|
|
@@ -396,6 +397,37 @@ public class MidjourneyServiceImpl implements MidjourneyService {
|
|
|
return submitResult;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户生图次数限制
|
|
|
+ */
|
|
|
+ public void userSubmitLimit(MidjourneyUser user,String action,Object customId) {
|
|
|
+ if (StringUtils.equals("modal",action)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (customId != null && customId.toString().contains("upsample")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String key = RedisService.key.MIDJOURNEY_USER_TIME.getName() + user.getId();
|
|
|
+ Object count = redisService.get(key);
|
|
|
+ if (count == null) {
|
|
|
+ redisService.set(key, 1L,RedisService.key.MIDJOURNEY_USER_TIME.getTimeout());
|
|
|
+ }else {
|
|
|
+ if (redisService.incr(key, 1L) > 200) {
|
|
|
+ //24小时内提交次数超过200次 拉黑
|
|
|
+ user.setIsBlack(true);
|
|
|
+ midjourneyUserMapper.updateById(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户30秒内只能提交一次
|
|
|
+ if (redisService.hasKey(RedisService.key.MIDJOURNEY_USER_SUBMIT.getName() + user.getId())) {
|
|
|
+ throw BusinessRuntimeException.getInstance("操作太快了,请等待"+redisService.getExpire(RedisService.key.MIDJOURNEY_USER_SUBMIT.getName() + user.getId())+"秒后再试.为了防止爬虫,让大家有个良好的使用环境,relax模式命令最短时间间隔30秒,fast模式最短间隔5秒");
|
|
|
+ }else {
|
|
|
+ redisService.set(RedisService.key.MIDJOURNEY_USER_SUBMIT.getName() + user.getId(), 1L, 30L);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public String getAccountWithMinUsage(Long instanceId) {
|
|
|
String key = RedisService.key.MIDJOURNEY_ACCOUNT.getName();
|
|
|
try {
|