reghao 3 лет назад
Родитель
Сommit
46db6a78d9

+ 10 - 8
src/main/java/cn/reghao/tnb/file/app/controller/VideoFileController.java

@@ -1,15 +1,9 @@
 package cn.reghao.tnb.file.app.controller;
 
-import org.springframework.core.io.InputStreamResource;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
+import cn.reghao.tnb.file.app.db.mapper.FileUrlMapper;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
-import java.io.ByteArrayInputStream;
-import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
@@ -21,10 +15,18 @@ import java.util.Arrays;
 @RestController
 @RequestMapping("/video")
 public class VideoFileController {
+    private final FileUrlMapper fileUrlMapper;
+
+    public VideoFileController(FileUrlMapper fileUrlMapper) {
+        this.fileUrlMapper = fileUrlMapper;
+    }
+
     @GetMapping("/playback")
-    public void videoPlayer(@RequestParam("videoId") String videoId,
+    public void videoPlayer(@RequestParam("uploadId") String uploadId,
                             @RequestHeader(required = false) String range,
                             HttpServletResponse response) throws Exception {
+        fileUrlMapper.findByUploadId(uploadId);
+
         String filePath = "/home/reghao/Downloads/mp4/test.mp4";
         RandomAccessFile raf = new RandomAccessFile(filePath, "r");
         long fileLength = raf.length();

+ 3 - 0
src/test/java/FileTest.java

@@ -4,6 +4,7 @@ import cn.reghao.tnb.file.app.db.mapper.*;
 import cn.reghao.tnb.file.app.model.po.FileInfo;
 import cn.reghao.tnb.file.app.model.po.FileUrl;
 import cn.reghao.tnb.file.app.model.po.FileUser;
+import org.apache.commons.io.FileUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,6 +12,8 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.io.File;
+import java.io.IOException;
 import java.util.List;
 import java.util.stream.Collectors;
 

+ 26 - 0
src/test/java/FileTest1.java

@@ -0,0 +1,26 @@
+import org.apache.commons.io.FileUtils;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author reghao
+ * @date 2022-04-23 17:17:50
+ */
+public class FileTest1 {
+    @Test
+    public void test1() throws IOException {
+        String baseDir = "/home/reghao/Downloads/dfs";
+        int total = 128;
+        for (int i = 0; i < total; i++) {
+            for (int j = 0; j < total; j++) {
+                String dirPath = String.format("%s/%s/%s", baseDir, i, j);
+                File dir = new File(dirPath);
+                if (!dir.exists()) {
+                    FileUtils.forceMkdir(dir);
+                }
+            }
+        }
+    }
+}