|
|
@@ -1,5 +1,6 @@
|
|
|
package cn.reghao.dfs.store.controller;
|
|
|
|
|
|
+import cn.reghao.dfs.store.model.dto.PathUrl;
|
|
|
import cn.reghao.dfs.store.service.FileUrlService;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -28,14 +29,15 @@ public class VideoFileController {
|
|
|
public void videoPlayer(@PathVariable("filename") String filename, @RequestHeader(required = false) String range,
|
|
|
HttpServletResponse response) throws Exception {
|
|
|
String uploadId = filename.split("\\.")[0];
|
|
|
- String filePath = fileUrlService.getFilePath(uploadId);
|
|
|
- if (filePath == null) {
|
|
|
+ PathUrl pathUrl = fileUrlService.getPathUrl(uploadId);
|
|
|
+ if (pathUrl == null) {
|
|
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
|
response.getOutputStream().write("".getBytes(StandardCharsets.UTF_8));
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- RandomAccessFile raf = new RandomAccessFile(filePath, "r");
|
|
|
+ String absolutePath = pathUrl.getAbsolutePath();
|
|
|
+ RandomAccessFile raf = new RandomAccessFile(absolutePath, "r");
|
|
|
long fileLength = raf.length();
|
|
|
long partLength = 1024*1024*2;
|
|
|
|
|
|
@@ -77,10 +79,17 @@ public class VideoFileController {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- String filePath = fileUrlService.getFilePath(uploadId);
|
|
|
- File file = new File(filePath);
|
|
|
+ PathUrl pathUrl = fileUrlService.getPathUrl(uploadId);
|
|
|
+ if (pathUrl == null) {
|
|
|
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
|
+ response.getOutputStream().write("".getBytes(StandardCharsets.UTF_8));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String absolutePath = pathUrl.getAbsolutePath();
|
|
|
+ File file = new File(absolutePath);
|
|
|
long len = file.length();
|
|
|
- FileInputStream fis = new FileInputStream(filePath);
|
|
|
+ FileInputStream fis = new FileInputStream(absolutePath);
|
|
|
response.setContentType("video/mp4");
|
|
|
response.setHeader("Content-Length", ""+len);
|
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
|
|
@@ -93,16 +102,30 @@ public class VideoFileController {
|
|
|
@RequestHeader(required = false) String range,
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
if (filename.contains("mpd")) {
|
|
|
- String localFilePath = fileUrlService.getFilePath(uploadId);
|
|
|
- FileInputStream fis = new FileInputStream(localFilePath);
|
|
|
+ PathUrl pathUrl = fileUrlService.getPathUrl(uploadId);
|
|
|
+ if (pathUrl == null) {
|
|
|
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
|
+ response.getOutputStream().write("".getBytes(StandardCharsets.UTF_8));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String absolutePath = pathUrl.getAbsolutePath();
|
|
|
+ FileInputStream fis = new FileInputStream(absolutePath);
|
|
|
response.setStatus(HttpServletResponse.SC_OK);
|
|
|
response.setContentType("application/dash+xml; charset=utf-8");
|
|
|
response.getOutputStream().write(fis.readAllBytes());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- String filePath = fileUrlService.getFilePath(uploadId);
|
|
|
- String parentDir = new File(filePath).getParent();
|
|
|
+ PathUrl pathUrl = fileUrlService.getPathUrl(uploadId);
|
|
|
+ if (pathUrl == null) {
|
|
|
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
|
+ response.getOutputStream().write("".getBytes(StandardCharsets.UTF_8));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String absolutePath = pathUrl.getAbsolutePath();
|
|
|
+ String parentDir = new File(absolutePath).getParent();
|
|
|
String localFilePath1 = parentDir + File.separator + filename;
|
|
|
RandomAccessFile raf = new RandomAccessFile(localFilePath1, "r");
|
|
|
long fileLength = raf.length();
|