|
|
@@ -16,10 +16,12 @@ import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.model.dto.SubmitVideoDTO;
|
|
|
import com.yhlxj.dao.mapper.GroupsRelationMapper;
|
|
|
+import com.yhlxj.dao.mapper.LumaUserApiProviderMapper;
|
|
|
import com.yhlxj.dao.mapper.midjourney.LumaUserConversationMapper;
|
|
|
import com.yhlxj.dao.mapper.midjourney.LumaUserMapper;
|
|
|
import com.yhlxj.dao.model.entity.GroupsRelation;
|
|
|
import com.yhlxj.dao.model.entity.LumaUser;
|
|
|
+import com.yhlxj.dao.model.entity.LumaUserApiProvider;
|
|
|
import com.yhlxj.dao.model.entity.LumaUserConversation;
|
|
|
import com.yhlxj.dao.model.response.SubmitResult;
|
|
|
import com.yhlxj.dao.model.response.VideoTask;
|
|
|
@@ -80,6 +82,8 @@ public class LumaServiceImpl implements LumaService {
|
|
|
|
|
|
private static final List<String> FINISH_STATUS = List.of("completed", "failed");
|
|
|
|
|
|
+ private final LumaUserApiProviderMapper lumaUserApiProviderMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public LumaUser getUser(String userToken) {
|
|
|
if(StringUtils.isBlank(userToken)){
|
|
|
@@ -114,6 +118,7 @@ public class LumaServiceImpl implements LumaService {
|
|
|
conversation.setProgress("0%");
|
|
|
conversation.setStatus("pending");
|
|
|
conversation.setTaskId(taskId);
|
|
|
+ conversation.setProviderId(result.getProviderId());
|
|
|
}
|
|
|
if (conversation.getId() == null) {
|
|
|
conversationMapper.insert(conversation);
|
|
|
@@ -123,10 +128,10 @@ public class LumaServiceImpl implements LumaService {
|
|
|
return conversation;
|
|
|
}
|
|
|
|
|
|
- public SubmitResult submit(LumaUser user, Map<String, Object> param, Long num) throws Exception {
|
|
|
- String url = LUMA_BASE_URL + "/luma/generations";
|
|
|
+ public SubmitResult submit(String domain, String auth, Map<String, Object> param, Long num) throws Exception {
|
|
|
+ String url = domain + "/luma/generations";
|
|
|
HttpRequest request = HttpRequest.post(url).body(Jsons.toJson(param));
|
|
|
- request.header("Authorization", AUTH);
|
|
|
+ request.header("Authorization", auth);
|
|
|
|
|
|
String body = request.setConnectionTimeout(10000).execute().body();
|
|
|
log.info("return body:{}", body);
|
|
|
@@ -159,7 +164,7 @@ public class LumaServiceImpl implements LumaService {
|
|
|
videoParam.put("image_end_url", imageEndUrl);
|
|
|
}
|
|
|
videoParam.put("notify_hook", lumaHost + (EnvCommonService.active_pre.equals(envCommonService.getEnv()) ? "/8083" : "/8085") + VIDEO_NOTIFY_URL);
|
|
|
- SubmitResult result = submit(user, videoParam, num);
|
|
|
+ SubmitResult result = unifiedSubmitVideo(videoParam, num);
|
|
|
LumaUserConversation lumaUserConversation = saveConversation(user.getId(), result, prompt);
|
|
|
result.setRid(lumaUserConversation.getId());
|
|
|
return result;
|
|
|
@@ -174,9 +179,11 @@ public class LumaServiceImpl implements LumaService {
|
|
|
if (lumaUserConversation == null) {
|
|
|
throw BusinessRuntimeException.getInstance("视频不存在");
|
|
|
}
|
|
|
- String url = LUMA_BASE_URL + "/luma/generations/" + lumaUserConversation.getTaskId();
|
|
|
+ Long providerId = lumaUserConversation.getProviderId();
|
|
|
+ LumaUserApiProvider apiProvider = lumaUserApiProviderMapper.selectById(providerId);
|
|
|
+ String url = apiProvider.getDomain() + "/luma/generations/" + lumaUserConversation.getTaskId();
|
|
|
HttpRequest request = HttpRequest.get(url);
|
|
|
- request.header("Authorization", AUTH);
|
|
|
+ request.header("Authorization", apiProvider.getAuth());
|
|
|
|
|
|
String body = request.setConnectionTimeout(50000).execute().body();
|
|
|
log.info("action body:{}", body);
|
|
|
@@ -191,7 +198,7 @@ public class LumaServiceImpl implements LumaService {
|
|
|
SubmitResult.Video video = submitResult.getVideo();
|
|
|
lumaUserConversation.setFinishTime(System.currentTimeMillis());
|
|
|
//出水印
|
|
|
- String removeVideoWatermarkUrl = removeVideoWatermark(lumaUserConversation.getTaskId());
|
|
|
+ String removeVideoWatermarkUrl = removeVideoWatermark(lumaUserConversation.getProviderId(),lumaUserConversation.getTaskId());
|
|
|
lumaUserConversation.setVideoUrl(removeVideoWatermarkUrl);
|
|
|
lumaUserConversation.setThumbnail(video.getThumbnail());
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
|
@@ -226,7 +233,7 @@ public class LumaServiceImpl implements LumaService {
|
|
|
conversation.setStatus(videoTaskData.getState());
|
|
|
VideoTask.Video video = videoTaskData.getVideo();
|
|
|
if (video != null) {
|
|
|
- String removeVideoWatermarkUrl = removeVideoWatermark(conversation.getTaskId());
|
|
|
+ String removeVideoWatermarkUrl = removeVideoWatermark(conversation.getProviderId(), conversation.getTaskId());
|
|
|
conversation.setVideoUrl(removeVideoWatermarkUrl);
|
|
|
conversation.setThumbnail(video.getThumbnail());
|
|
|
}
|
|
|
@@ -252,7 +259,6 @@ public class LumaServiceImpl implements LumaService {
|
|
|
String taskId = videoDTO.getTaskId();
|
|
|
String prompt = videoDTO.getPrompt();
|
|
|
Boolean expandPrompt = videoDTO.getExpandPrompt();
|
|
|
- String url = LUMA_BASE_URL + String.format("/luma/generations/%s/extend", taskId);
|
|
|
|
|
|
LumaUserConversation lumaUserConversation = conversationMapper.selectOne(Wrappers.lambdaQuery(LumaUserConversation.class)
|
|
|
.eq(LumaUserConversation::getTaskId, taskId)
|
|
|
@@ -282,8 +288,11 @@ public class LumaServiceImpl implements LumaService {
|
|
|
//线上接口8085
|
|
|
videoParam.put("notify_hook", lumaHost + (EnvCommonService.active_pre.equals(envCommonService.getEnv()) ? "/8083" : "/8085") + VIDEO_NOTIFY_URL);
|
|
|
|
|
|
+ Long providerId = lumaUserConversation.getProviderId();
|
|
|
+ LumaUserApiProvider apiProvider = lumaUserApiProviderMapper.selectById(providerId);
|
|
|
+ String url = apiProvider.getDomain() + String.format("/luma/generations/%s/extend", taskId);
|
|
|
HttpRequest request = HttpRequest.post(url).setConnectionTimeout(10000).body(Jsons.toJson(videoParam));
|
|
|
- request.header("Authorization", AUTH);
|
|
|
+ request.header("Authorization", apiProvider.getAuth());
|
|
|
String body = request.execute().body();
|
|
|
SubmitResult submitResult = Jsons.parseObject(body, SubmitResult.class);
|
|
|
log.info("return body: {}", body);
|
|
|
@@ -482,12 +491,33 @@ public class LumaServiceImpl implements LumaService {
|
|
|
/**
|
|
|
* 去水印
|
|
|
*/
|
|
|
- public String removeVideoWatermark(String taskId) throws Exception {
|
|
|
- String url = LUMA_BASE_URL + String.format("/luma/generations/%s/download_video_url", taskId);
|
|
|
- HttpRequest request = HttpRequest.get(url).header("Authorization", AUTH).setConnectionTimeout(10000);
|
|
|
+ public String removeVideoWatermark(Long providerId, String taskId) throws Exception {
|
|
|
+ LumaUserApiProvider apiProvider = lumaUserApiProviderMapper.selectById(providerId);
|
|
|
+ String url = apiProvider.getDomain() + String.format("/luma/generations/%s/download_video_url", taskId);
|
|
|
+ HttpRequest request = HttpRequest.get(url).header("Authorization", apiProvider.getAuth()).setConnectionTimeout(10000);
|
|
|
HttpResponse execute = request.execute();
|
|
|
String body = execute.body();
|
|
|
JSONObject re = Jsons.parseObject(body, JSONObject.class);
|
|
|
return re.getStr("url");
|
|
|
}
|
|
|
+
|
|
|
+ private SubmitResult unifiedSubmitVideo(Map<String, Object> videoParam, Long num) {
|
|
|
+ List<LumaUserApiProvider> lumaUserApiProviders = lumaUserApiProviderMapper.selectList(Wrappers.lambdaQuery(LumaUserApiProvider.class)
|
|
|
+ .eq(LumaUserApiProvider::getDeleted, 1));
|
|
|
+ Boolean isSuccess = false;
|
|
|
+ for (LumaUserApiProvider apiProvider : lumaUserApiProviders) {
|
|
|
+ try {
|
|
|
+ SubmitResult submit = submit(apiProvider.getDomain(), apiProvider.getAuth(), videoParam, num);
|
|
|
+ submit.setProviderId(apiProvider.getId());
|
|
|
+ isSuccess = true;
|
|
|
+ return submit;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("apiProvider:{}生成文本视频报错", apiProvider.getDomain());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isSuccess) {
|
|
|
+ throw BusinessRuntimeException.getInstance("生成视频报错,请联系客服..");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|