|
|
@@ -1,5 +1,6 @@
|
|
|
package com.yhlxj.web.mirror;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@@ -48,6 +49,10 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.DirectoryStream;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -97,6 +102,16 @@ public class MidjourneyController {
|
|
|
return midjourneyService.getUser(userToken);
|
|
|
}
|
|
|
|
|
|
+ public MidjourneyUser getUserSimple() throws IOException {
|
|
|
+ String userToken = request.getHeader("user-token");
|
|
|
+ String ip = IpUtils.getIpAddr(request);
|
|
|
+ log.info("用户请求 ip:{}, userToken:{}", ip, userToken);
|
|
|
+ if (StringUtils.isBlank(userToken)) {
|
|
|
+ response.sendRedirect("https://nf.video");
|
|
|
+ }
|
|
|
+ return midjourneyService.getUserSimple(userToken);
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/midjourneyMirrorWithToken/{userToken}")
|
|
|
public void midjourneyMirrorWithToken(@PathVariable String userToken) throws IOException {
|
|
|
Cookie cookie = new Cookie("userToken", userToken);
|
|
|
@@ -230,6 +245,7 @@ public class MidjourneyController {
|
|
|
Integer mode = submitImagineDTO.getMode();
|
|
|
if (submitImagineDTO.getQueueId() != null){
|
|
|
redisService.lRemoveLeft(RedisService.key.MIDJOURNEY_QUEUE_DETAIL_LIMIT.getName() + user.getId());
|
|
|
+ delFile(submitImagineDTO.getQueueId());
|
|
|
}
|
|
|
Map<String, Object> checkResult = checkUserLimit(user, mode);
|
|
|
Long num = (Long) checkResult.get("num");
|
|
|
@@ -253,7 +269,13 @@ public class MidjourneyController {
|
|
|
//syncUser(user.getId(), user.getMode(), num);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(conversation);
|
|
|
}
|
|
|
-
|
|
|
+ public void delFile(Long queueId) throws IOException {
|
|
|
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get("/mnt/picture"), queueId +".*")) {
|
|
|
+ for (Path filePath : stream) {
|
|
|
+ FileUtil.del(filePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 提交Describe任务
|
|
|
*/
|
|
|
@@ -405,7 +427,7 @@ public class MidjourneyController {
|
|
|
@NoSubmit
|
|
|
public Result<SubmitResult> seed(@Validated @RequestBody SubmitSeedDTO seedDTO) throws Exception {
|
|
|
log.info("任务id:{},执行动作:{}",seedDTO.getTaskId(), "seed");
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
try {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyService.submitSeed(user, seedDTO.getTaskId(), seedDTO.getBotType()));
|
|
|
} catch (Exception e) {
|
|
|
@@ -420,7 +442,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/conversation/list")
|
|
|
public Result<SearchResult<MidjourneyUserConversation>> conversationList() throws Exception {
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
log.info("查询会话列表 userId:{}",user.getId());
|
|
|
MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(beanSearcher.search(MidjourneyUserConversation.class,
|
|
|
@@ -435,7 +457,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/conversation/listByIds")
|
|
|
public Result<List<MidjourneyUserConversation>> conversationListByIds(Integer mode,@RequestParam(value = "ids" ) List<String> ids) throws Exception {
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
log.info("根据ids查询会话 userId:{}",user.getId());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyService.listConversationByIds(mode,ids));
|
|
|
}
|
|
|
@@ -446,7 +468,7 @@ public class MidjourneyController {
|
|
|
@PostMapping("/conversation/{id}/cancel")
|
|
|
@NoSubmit
|
|
|
public Result<Void> conversationCancel(@PathVariable("id") Long id) throws Exception {
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
log.info("取消任务 id:{}",id);
|
|
|
midjourneyService.cancelConversation(user,id);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
@@ -520,7 +542,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/get/painting/record")
|
|
|
public Result<SearchResult<MidjourneyUserPaintingDayRecordView>> getPaintingRecord(String prompt, Boolean bookmark) throws Exception {
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
log.info("用户绘画记录 userId:{},prompt:{},bookmark:{}", user.getId(), prompt, bookmark);
|
|
|
String condition = String.format(" and mc.user_id = %s", user.getId());
|
|
|
if (StrUtil.isNotBlank(prompt)) {
|
|
|
@@ -552,7 +574,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/get/settings")
|
|
|
public Result<MidjourneyUserSettings> getSettings() throws Exception {
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyUserSettingsService.getById(user.getSettings().getId()));
|
|
|
}
|
|
|
|
|
|
@@ -561,7 +583,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@PostMapping("/put/settings")
|
|
|
public Result<MidjourneyUserSettings> upSettings(@RequestBody MidjourneyUserSettings settings) throws Exception {
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
if (!user.getId().equals(settings.getUserId())) {
|
|
|
throw BusinessRuntimeException.getInstance("参数错误");
|
|
|
}
|
|
|
@@ -677,7 +699,7 @@ public class MidjourneyController {
|
|
|
@PostMapping("/queue")
|
|
|
public Result<MidjourneyUserQueueView> saveQueue(@Validated @RequestBody SubmitImagineDTO submitImagineDTO) throws Exception {
|
|
|
log.info("提交Imagine任务,提示:{}",submitImagineDTO.getPrompt());
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
Integer mode = submitImagineDTO.getMode();
|
|
|
if (mode != 2){
|
|
|
throw BusinessRuntimeException.getInstance("网络异常!");
|
|
|
@@ -697,7 +719,7 @@ public class MidjourneyController {
|
|
|
*/
|
|
|
@GetMapping("/getTaskPosition")
|
|
|
public Result<List<MidjourneyUserQueue>> getTaskPosition() throws Exception{
|
|
|
- MidjourneyUser user = getUser();
|
|
|
+ MidjourneyUser user = getUserSimple();
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(midjourneyService.getTaskPosition(user.getId()));
|
|
|
}
|
|
|
}
|