Commit 9c27de28134d9c6526014a85eddb6f5b823de603
1 parent
14dd9e9b
像zlm添加下载支持页面
Showing
1 changed file
with
55 additions
and
2 deletions
src/main/java/top/panll/assist/config/StartConfig.java
| 1 | 1 | package top.panll.assist.config; |
| 2 | 2 | |
| 3 | +import com.alibaba.fastjson.JSONObject; | |
| 3 | 4 | import net.bramp.ffmpeg.FFmpeg; |
| 4 | 5 | import net.bramp.ffmpeg.FFprobe; |
| 5 | 6 | import net.bramp.ffmpeg.probe.FFmpegProbeResult; |
| 6 | 7 | import org.slf4j.Logger; |
| 7 | 8 | import org.slf4j.LoggerFactory; |
| 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | +import org.springframework.beans.factory.annotation.Value; | |
| 9 | 11 | import org.springframework.boot.CommandLineRunner; |
| 10 | 12 | import org.springframework.core.annotation.Order; |
| 11 | 13 | import org.springframework.stereotype.Component; |
| ... | ... | @@ -13,8 +15,9 @@ import top.panll.assist.dto.UserSettings; |
| 13 | 15 | import top.panll.assist.service.FFmpegExecUtils; |
| 14 | 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 | 28 | |
| 26 | 29 | private final static Logger logger = LoggerFactory.getLogger(StartConfig.class); |
| 27 | 30 | |
| 31 | + @Value("${server.port}") | |
| 32 | + private String port; | |
| 33 | + | |
| 28 | 34 | @Autowired |
| 29 | 35 | private UserSettings userSettings; |
| 30 | 36 | |
| ... | ... | @@ -51,6 +57,8 @@ public class StartConfig implements CommandLineRunner { |
| 51 | 57 | logger.error("[userSettings.record]路径无法写入"); |
| 52 | 58 | System.exit(1); |
| 53 | 59 | } |
| 60 | + // 在zlm目录写入assist下载页面 | |
| 61 | + writeAssistDownPage(recordFile); | |
| 54 | 62 | try { |
| 55 | 63 | String ffmpegPath = userSettings.getFfmpeg(); |
| 56 | 64 | String ffprobePath = userSettings.getFfprobe(); |
| ... | ... | @@ -99,4 +107,49 @@ public class StartConfig implements CommandLineRunner { |
| 99 | 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 | } | ... | ... |