Commit 9c27de28134d9c6526014a85eddb6f5b823de603

Authored by 648540858
1 parent 14dd9e9b

像zlm添加下载支持页面

src/main/java/top/panll/assist/config/StartConfig.java
1 package top.panll.assist.config; 1 package top.panll.assist.config;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
3 import net.bramp.ffmpeg.FFmpeg; 4 import net.bramp.ffmpeg.FFmpeg;
4 import net.bramp.ffmpeg.FFprobe; 5 import net.bramp.ffmpeg.FFprobe;
5 import net.bramp.ffmpeg.probe.FFmpegProbeResult; 6 import net.bramp.ffmpeg.probe.FFmpegProbeResult;
6 import org.slf4j.Logger; 7 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.beans.factory.annotation.Value;
9 import org.springframework.boot.CommandLineRunner; 11 import org.springframework.boot.CommandLineRunner;
10 import org.springframework.core.annotation.Order; 12 import org.springframework.core.annotation.Order;
11 import org.springframework.stereotype.Component; 13 import org.springframework.stereotype.Component;
@@ -13,8 +15,9 @@ import top.panll.assist.dto.UserSettings; @@ -13,8 +15,9 @@ import top.panll.assist.dto.UserSettings;
13 import top.panll.assist.service.FFmpegExecUtils; 15 import top.panll.assist.service.FFmpegExecUtils;
14 import top.panll.assist.service.VideoFileService; 16 import top.panll.assist.service.VideoFileService;
15 17
16 -import java.io.File;  
17 -import java.io.IOException; 18 +import java.io.*;
  19 +import java.nio.charset.StandardCharsets;
  20 +import java.util.Map;
18 21
19 /** 22 /**
20 * 用于启动检查环境 23 * 用于启动检查环境
@@ -25,6 +28,9 @@ public class StartConfig implements CommandLineRunner { @@ -25,6 +28,9 @@ public class StartConfig implements CommandLineRunner {
25 28
26 private final static Logger logger = LoggerFactory.getLogger(StartConfig.class); 29 private final static Logger logger = LoggerFactory.getLogger(StartConfig.class);
27 30
  31 + @Value("${server.port}")
  32 + private String port;
  33 +
28 @Autowired 34 @Autowired
29 private UserSettings userSettings; 35 private UserSettings userSettings;
30 36
@@ -51,6 +57,8 @@ public class StartConfig implements CommandLineRunner { @@ -51,6 +57,8 @@ public class StartConfig implements CommandLineRunner {
51 logger.error("[userSettings.record]路径无法写入"); 57 logger.error("[userSettings.record]路径无法写入");
52 System.exit(1); 58 System.exit(1);
53 } 59 }
  60 + // 在zlm目录写入assist下载页面
  61 + writeAssistDownPage(recordFile);
54 try { 62 try {
55 String ffmpegPath = userSettings.getFfmpeg(); 63 String ffmpegPath = userSettings.getFfmpeg();
56 String ffprobePath = userSettings.getFfprobe(); 64 String ffprobePath = userSettings.getFfprobe();
@@ -99,4 +107,49 @@ public class StartConfig implements CommandLineRunner { @@ -99,4 +107,49 @@ public class StartConfig implements CommandLineRunner {
99 logger.error("环境错误: " + exception.getMessage()); 107 logger.error("环境错误: " + exception.getMessage());
100 } 108 }
101 } 109 }
  110 +
  111 + private void writeAssistDownPage(File recordFile) {
  112 + try {
  113 + File file = new File(recordFile.getAbsolutePath(), "download.html");
  114 + if (file.exists()) {
  115 + file.delete();
  116 + }
  117 + file.createNewFile();
  118 + FileOutputStream fs = new FileOutputStream(file);
  119 + StringBuffer stringBuffer = new StringBuffer();
  120 + String content = "<!DOCTYPE html>\n" +
  121 + "<html lang=\"en\">\n" +
  122 + "<head>\n" +
  123 + " <meta charset=\"UTF-8\">\n" +
  124 + " <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n" +
  125 + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
  126 + " <title>下载</title>\n" +
  127 + "</head>\n" +
  128 + "<body>\n" +
  129 + " <a id=\"download\" download />\n" +
  130 + " <script>\n" +
  131 + " (function(){\n" +
  132 + " let searchParams = new URLSearchParams(location.search);\n" +
  133 + " var download = document.getElementById(\"download\");\n" +
  134 + " download.setAttribute(\"href\", searchParams.get(\"url\"))\n" +
  135 + " download.click()\n" +
  136 + " setTimeout(()=>{\n" +
  137 + " window.location.href=\"about:blank\";\n" +
  138 + "\t\t\t window.close();\n" +
  139 + " },200)\n" +
  140 + " })();\n" +
  141 + " \n" +
  142 + " </script>\n" +
  143 + "</body>\n" +
  144 + "</html>";
  145 + fs.write(content.getBytes(StandardCharsets.UTF_8));
  146 + logger.error("已写入html配置页面");
  147 + } catch (FileNotFoundException e) {
  148 + logger.error("写入html页面错误", e);
  149 + } catch (IOException e) {
  150 + logger.error("写入html页面错误", e);
  151 + }
  152 +
  153 +
  154 + }
102 } 155 }