Jelajahi Sumber

增加目录创建

xueyiming 7 bulan lalu
induk
melakukan
a4215cdef4

+ 12 - 2
long-article-server/src/main/java/com/tzld/piaoquan/longarticle/utils/other/VideoDownloader.java

@@ -128,14 +128,24 @@ public class VideoDownloader {
         String index = String.format("%s-%s-%s", platform, videoId, UUID.randomUUID());
         String md5Hash = DigestUtils.md5Hex(index);
         String fileName = String.format("%s.mp4", md5Hash);
-        return String.join(File.separator, ConfigUtil.getConfig("download.path"), fileName); // 返回文件路径和封面路径
+        String path = ConfigUtil.getConfig("download.path");
+        File uploadDir = new File(path);
+        if (!uploadDir.exists()) {
+            uploadDir.mkdirs(); // 创建目录
+        }
+        return String.join(File.separator, path, fileName); // 返回文件路径和封面路径
     }
 
     private static String generateCoverPath(String platform, String videoId) {
         String index = String.format("%s-%s-%s", platform, videoId, UUID.randomUUID());
         String md5Hash = DigestUtils.md5Hex(index);
         String coverName = String.format("%s.png", md5Hash);
-        return String.join(File.separator, ConfigUtil.getConfig("download.path"), coverName); // 返回文件路径和封面路径
+        String path = ConfigUtil.getConfig("download.path");
+        File uploadDir = new File(path);
+        if (!uploadDir.exists()) {
+            uploadDir.mkdirs(); // 创建目录
+        }
+        return String.join(File.separator, path, coverName); // 返回文件路径和封面路径
     }
 
     public static void main(String[] args) {