|
@@ -2,6 +2,7 @@ package com.taais.biz.controller;
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.DirectoryStream;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
@@ -22,7 +23,9 @@ import com.taais.biz.domain.bo.VideoStableStartResultBo;
|
|
|
import com.taais.biz.domain.dto.Metric;
|
|
|
import com.taais.biz.domain.vo.DataAugmentationVo;
|
|
|
import com.taais.biz.domain.vo.TaskDictDataVo;
|
|
|
+import com.taais.biz.domain.vo.VideoUrl;
|
|
|
import com.taais.biz.service.IVideoStableService;
|
|
|
+import com.taais.common.core.config.TaaisConfig;
|
|
|
import com.taais.common.core.service.OssService;
|
|
|
import com.taais.system.domain.SysDictData;
|
|
|
import com.taais.system.domain.SysOss;
|
|
@@ -354,6 +357,18 @@ public class DataAugmentationController extends BaseController {
|
|
|
return CommonResult.success();
|
|
|
}
|
|
|
|
|
|
+ private String readLogFileWithEncoding(Path path, java.nio.charset.Charset charset) throws IOException {
|
|
|
+ try (BufferedReader reader = Files.newBufferedReader(path, charset)) {
|
|
|
+ StringBuilder content = new StringBuilder();
|
|
|
+ String line;
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ content.append(line).append("\n");
|
|
|
+ }
|
|
|
+ return content.toString();
|
|
|
+ } catch (IOException e) {
|
|
|
+ return null; // 读取失败,返回 null
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 获取日志字符串
|
|
|
*/
|
|
@@ -367,8 +382,9 @@ public class DataAugmentationController extends BaseController {
|
|
|
if (!Files.exists(path)) {
|
|
|
return CommonResult.fail( "日志文件" + filePath + "不存在!");
|
|
|
}
|
|
|
+ String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
|
|
// 读取文件内容
|
|
|
- return CommonResult.success(new String(Files.readAllBytes(path)), "获取日志成功");
|
|
|
+ return CommonResult.success(content, "获取日志成功");
|
|
|
} catch (Exception e) {
|
|
|
return CommonResult.fail("日志文件" + filePath + "读取失败!");
|
|
|
}
|
|
@@ -437,4 +453,55 @@ public class DataAugmentationController extends BaseController {
|
|
|
}
|
|
|
return CommonResult.success(taskDictDataVos);
|
|
|
}
|
|
|
+ private static boolean hasSupportedExtension(String filePath, List<String> extensions) {
|
|
|
+ for (String ext : extensions) {
|
|
|
+ if (filePath.toLowerCase().endsWith(ext)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ public static String findFirstVideoFile(String dirPath, List<String> extensions) {
|
|
|
+ File dir = new File(dirPath);
|
|
|
+ if (!dir.exists() || !dir.isDirectory()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ try (Stream<Path> stream = Files.list(Paths.get(dirPath))) {
|
|
|
+ return stream
|
|
|
+ .filter(Files::isRegularFile)
|
|
|
+ .map(Path::toString)
|
|
|
+ .filter(filePath -> hasSupportedExtension(filePath, extensions))
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SaCheckPermission("demo:dataAugmentation:query")
|
|
|
+ @GetMapping(value = "/videoUrl/{id}")
|
|
|
+ public CommonResult<VideoUrl> getVideoUrl(@PathVariable Long id) {
|
|
|
+ DataAugmentation byId = dataAugmentationService.getById(id);
|
|
|
+ String localPath = TaaisConfig.getProfile();
|
|
|
+ List<String> extensions = Arrays.asList(".mp4", ".avi", ".mkv", ".mov", ".flv", ".wmv");
|
|
|
+ String firstInputVideoFile = findFirstVideoFile(byId.getInputPath(), extensions);
|
|
|
+ if (firstInputVideoFile == null) {
|
|
|
+ return CommonResult.fail(byId.getInputPath() + "目录下不存在输入视频文件!");
|
|
|
+ }
|
|
|
+ String firstOutputVideoFile = findFirstVideoFile(byId.getOutputPath(), extensions);
|
|
|
+ if (firstOutputVideoFile == null) {
|
|
|
+ return CommonResult.fail(byId.getOutputPath() + "目录下不存在输出视频文件!");
|
|
|
+ }
|
|
|
+ Path localPathPath = Paths.get(localPath);
|
|
|
+ Path inputPath = Paths.get(firstInputVideoFile);
|
|
|
+ Path outputPath = Paths.get(firstOutputVideoFile);
|
|
|
+
|
|
|
+ // 替换路径
|
|
|
+ String input = inputPath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/");
|
|
|
+ String output = outputPath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/");
|
|
|
+ return CommonResult.success(new VideoUrl(input, output));
|
|
|
+ }
|
|
|
+
|
|
|
}
|