Skip to content

Commit

Permalink
perf: 优化共享视频的预览
Browse files Browse the repository at this point in the history
  • Loading branch information
jamebal committed Mar 27, 2024
1 parent 523a77f commit b9abd3a
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.jmal.clouddisk.config.FileProperties;
import com.jmal.clouddisk.service.IShareService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.UrlResource;
import org.springframework.http.HttpHeaders;
Expand All @@ -26,34 +25,34 @@ public class VideoController {
private final IShareService shareService;


@GetMapping("/video/hls/{username}/{fileMd5}.m3u8")
public ResponseEntity<UrlResource> m3u8(@PathVariable String username, @PathVariable String fileMd5) throws IOException {
Path m3u8Path = Paths.get(fileProperties.getRootDir(), fileProperties.getChunkFileDir(), username, fileProperties.getVideoTranscodeCache(), fileMd5, fileMd5 + ".m3u8");
@GetMapping("/video/hls/{username}/{fileId}.m3u8")
public ResponseEntity<UrlResource> m3u8(@PathVariable String username, @PathVariable String fileId) throws IOException {
Path m3u8Path = Paths.get(fileProperties.getRootDir(), fileProperties.getChunkFileDir(), username, fileProperties.getVideoTranscodeCache(), fileId, fileId + ".m3u8");
UrlResource videoResource = new UrlResource(m3u8Path.toUri());
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, "application/vnd.apple.mpegurl")
.body(videoResource);
}

@GetMapping("/video/hls/{username}/{fileMd5}-{index}.ts")
public ResponseEntity<UrlResource> ts(@PathVariable String username, @PathVariable String fileMd5, @PathVariable String index) throws IOException {
Path m3u8Path = Paths.get(fileProperties.getRootDir(), fileProperties.getChunkFileDir(), username, fileProperties.getVideoTranscodeCache(), fileMd5, fileMd5 + "-" + index + ".ts");
@GetMapping("/video/hls/{username}/{fileId}-{index}.ts")
public ResponseEntity<UrlResource> ts(@PathVariable String username, @PathVariable String fileId, @PathVariable String index) throws IOException {
Path m3u8Path = Paths.get(fileProperties.getRootDir(), fileProperties.getChunkFileDir(), username, fileProperties.getVideoTranscodeCache(), fileId, fileId + "-" + index + ".ts");
UrlResource videoResource = new UrlResource(m3u8Path.toUri());
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, "application/vnd.apple.mpegurl")
.body(videoResource);
}

@GetMapping("/public/video/hls/{username}/{fileMd5}.m3u8")
public ResponseEntity<UrlResource> publicM3u8(@PathVariable String username, @PathVariable String fileMd5, HttpServletRequest request) throws IOException {
shareService.validShare(request);
return m3u8(username, fileMd5);
@GetMapping("/public/video/hls/{shareId}/{shareToken}/{username}/{fileId}.m3u8")
public ResponseEntity<UrlResource> publicM3u8(@PathVariable String username, @PathVariable String fileId, @PathVariable String shareId, @PathVariable String shareToken) throws IOException {
shareService.validShare(shareToken, shareId);
return m3u8(username, fileId);
}

@GetMapping("/public/video/hls/{username}/{fileMd5}-{index}.ts")
public ResponseEntity<UrlResource> publicTs(@PathVariable String username, @PathVariable String fileMd5, @PathVariable String index, HttpServletRequest request) throws IOException {
shareService.validShare(request);
return ts(username, fileMd5, index);
@GetMapping("/public/video/hls/{shareId}/{shareToken}/{username}/{fileId}-{index}.ts")
public ResponseEntity<UrlResource> publicTs(@PathVariable String username, @PathVariable String fileId, @PathVariable String index, @PathVariable String shareId, @PathVariable String shareToken) throws IOException {
shareService.validShare(shareToken, shareId);
return ts(username, fileId, index);
}

}

0 comments on commit b9abd3a

Please sign in to comment.