ADD VideoPlayer component and implement video fetching functionality

This commit is contained in:
2025-07-12 14:27:51 +02:00
parent e6d3b48855
commit 9f8894798d
8 changed files with 102 additions and 8 deletions

View File

@@ -49,4 +49,18 @@ public class DownloadController {
.contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM))
.body(resource);
}
@GetMapping("/clip/{id}")
public ResponseEntity<Resource> downloadClip(@PathVariable Long id) {
Resource resource = downloadService.downloadClip(id);
if (resource == null || !resource.exists()) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + resource.getFilename() + "\"")
.contentType(MediaTypeFactory.getMediaType(resource).orElse(MediaType.APPLICATION_OCTET_STREAM))
.body(resource);
}
}

View File

@@ -13,3 +13,5 @@ public interface ClipRepository extends JpaRepository<Clip, Long> {
@Query("SELECT c FROM Clip c WHERE c.user = ?1")
List<Clip> findByUser(User user);
}

View File

@@ -1,9 +1,11 @@
package com.ddf.vodsystem.services;
import com.ddf.vodsystem.entities.Clip;
import com.ddf.vodsystem.entities.JobStatus;
import com.ddf.vodsystem.exceptions.JobNotFinished;
import com.ddf.vodsystem.exceptions.JobNotFound;
import com.ddf.vodsystem.entities.Job;
import com.ddf.vodsystem.repositories.ClipRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
@@ -15,10 +17,12 @@ import java.io.File;
public class DownloadService {
private final JobService jobService;
private final ClipRepository clipRepository;
@Autowired
public DownloadService(JobService jobService) {
public DownloadService(JobService jobService, ClipRepository clipRepository) {
this.jobService = jobService;
this.clipRepository = clipRepository;
}
public Resource downloadInput(String uuid) {
@@ -46,4 +50,19 @@ public class DownloadService {
File file = job.getOutputFile();
return new FileSystemResource(file);
}
public Resource downloadClip(Clip clip) {
String path = clip.getVideoPath();
File file = new File(path);
if (!file.exists()) {
throw new JobNotFound("Clip file not found");
}
return new FileSystemResource(file);
}
public Resource downloadClip(Long id) {
Clip clip = clipRepository.findById(id).orElseThrow(() -> new JobNotFound("Clip not found with id: " + id));
return downloadClip(clip);
}
}