Commit 9f32954a by xushaohua

feat:部署

parent 2d470330
package com.github.novicezk.midjourney.controller; package com.github.novicezk.midjourney.controller;
import cn.hutool.core.comparator.CompareUtil; import cn.hutool.core.comparator.CompareUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.github.novicezk.midjourney.dto.TaskConditionDTO; import com.github.novicezk.midjourney.dto.TaskConditionDTO;
import com.github.novicezk.midjourney.service.TaskStoreService; import com.github.novicezk.midjourney.service.TaskStoreService;
import com.github.novicezk.midjourney.support.Task; import com.github.novicezk.midjourney.support.Task;
import com.github.novicezk.midjourney.support.TaskQueueHelper; import com.github.novicezk.midjourney.support.TaskQueueHelper;
import com.github.novicezk.midjourney.util.FileUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
...@@ -44,6 +46,14 @@ public class TaskController { ...@@ -44,6 +46,14 @@ public class TaskController {
return this.taskStoreService.get(id); return this.taskStoreService.get(id);
} }
@ApiOperation(value = "转换url")
@GetMapping("convertUrl")
public String convertUrl(String url) {
FileUtil fileUtil = SpringUtil.getBean("fileUtil");
String s = fileUtil.convertFile(url);
return s;
}
@ApiOperation(value = "查询任务队列") @ApiOperation(value = "查询任务队列")
@GetMapping("/queue") @GetMapping("/queue")
public List<Task> queue() { public List<Task> queue() {
......
...@@ -31,6 +31,7 @@ public class FileUtil { ...@@ -31,6 +31,7 @@ public class FileUtil {
* @return * @return
*/ */
public String convertFile(String discordUrl) { public String convertFile(String discordUrl) {
log.info("开始转换图片:{}", discordUrl);
try { try {
// 在线图片地址转换成base64 // 在线图片地址转换成base64
URL url = new URL(discordUrl); URL url = new URL(discordUrl);
...@@ -46,6 +47,7 @@ public class FileUtil { ...@@ -46,6 +47,7 @@ public class FileUtil {
// 将字节数组输出流中的图片数据进行 Base64 编码 // 将字节数组输出流中的图片数据进行 Base64 编码
byte[] imageBytes = outputStream.toByteArray(); byte[] imageBytes = outputStream.toByteArray();
String base64Data = Base64.getEncoder().encodeToString(imageBytes); String base64Data = Base64.getEncoder().encodeToString(imageBytes);
log.info("下载转换成了base64:{}", discordUrl);
String last = discordUrl.substring(discordUrl.lastIndexOf(".") + 1); String last = discordUrl.substring(discordUrl.lastIndexOf(".") + 1);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -57,6 +59,7 @@ public class FileUtil { ...@@ -57,6 +59,7 @@ public class FileUtil {
.header("content-type", "application/json") .header("content-type", "application/json")
.body(jsonObject.toString(), "application/json;charset=utf-8"); .body(jsonObject.toString(), "application/json;charset=utf-8");
HttpResponse httpResponse = request.execute(); HttpResponse httpResponse = request.execute();
log.info("调用远程上传接口返回:{}", httpResponse.body());
String uploadUrl = Optional.ofNullable(httpResponse.body()) String uploadUrl = Optional.ofNullable(httpResponse.body())
.map(JSONObject::new) .map(JSONObject::new)
.map(x -> x.getJSONObject("data")) .map(x -> x.getJSONObject("data"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment