From e2c4b81cadd26880bfbafbd7780c0ab254eeb352 Mon Sep 17 00:00:00 2001 From: ThisBirchWood Date: Thu, 15 May 2025 10:07:48 +0200 Subject: [PATCH] RENAME methods for consistency --- .gitignore | 3 +++ .../vodsystem/controllers/DownloadController.java | 5 +---- .../ddf/vodsystem/controllers/EditController.java | 2 +- .../ddf/vodsystem/services/DownloadService.java | 13 ++++++++++++- .../com/ddf/vodsystem/services/EditService.java | 14 +++++--------- .../com/ddf/vodsystem/services/JobService.java | 1 + 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 8a56759..2037d2d 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ build/ ### VS Code ### .vscode/ + +### Generated Files ### +videos/ diff --git a/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java b/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java index 937e432..5d815ac 100644 --- a/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java +++ b/src/main/java/com/ddf/vodsystem/controllers/DownloadController.java @@ -1,14 +1,11 @@ package com.ddf.vodsystem.controllers; -import com.ddf.vodsystem.exceptions.JobNotFinished; -import com.ddf.vodsystem.exceptions.JobNotFound; import com.ddf.vodsystem.services.DownloadService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @@ -24,7 +21,7 @@ public class DownloadController { @GetMapping("/download/{filename}") public ResponseEntity downloadFile(@PathVariable String filename) { - Resource resource = downloadService.download(filename); + Resource resource = downloadService.downloadOutput(filename); if (resource == null || !resource.exists()) { return ResponseEntity.notFound().build(); diff --git a/src/main/java/com/ddf/vodsystem/controllers/EditController.java b/src/main/java/com/ddf/vodsystem/controllers/EditController.java index e2c05f7..425a147 100644 --- a/src/main/java/com/ddf/vodsystem/controllers/EditController.java +++ b/src/main/java/com/ddf/vodsystem/controllers/EditController.java @@ -24,7 +24,7 @@ public class EditController { @GetMapping("/process/{uuid}") public ResponseEntity convert(@PathVariable("uuid") String uuid) { - editService.jobReady(uuid); + editService.process(uuid); return new ResponseEntity<>(uuid, HttpStatus.OK); } diff --git a/src/main/java/com/ddf/vodsystem/services/DownloadService.java b/src/main/java/com/ddf/vodsystem/services/DownloadService.java index ecfb55e..26a47c7 100644 --- a/src/main/java/com/ddf/vodsystem/services/DownloadService.java +++ b/src/main/java/com/ddf/vodsystem/services/DownloadService.java @@ -21,7 +21,18 @@ public class DownloadService { this.jobService = jobService; } - public Resource download(String uuid) { + public Resource downloadInput(String uuid) { + Job job = jobService.get(uuid); + + if (job == null) { + throw new JobNotFound("Job doesn't exist"); + } + + File file = job.getInputFile(); + return new FileSystemResource(file); + } + + public Resource downloadOutput(String uuid) { Job job = jobService.get(uuid); if (job == null) { diff --git a/src/main/java/com/ddf/vodsystem/services/EditService.java b/src/main/java/com/ddf/vodsystem/services/EditService.java index 3f77e35..ce16448 100644 --- a/src/main/java/com/ddf/vodsystem/services/EditService.java +++ b/src/main/java/com/ddf/vodsystem/services/EditService.java @@ -17,22 +17,18 @@ public class EditService { public void edit(String uuid, ClipConfig clipConfig) { Job job = jobService.get(uuid); - if (clipConfig.getStartPoint() != null) { - if (clipConfig.getStartPoint() < 0) { - throw new IllegalArgumentException("Start point cannot be negative"); - } + if (clipConfig.getStartPoint() != null && clipConfig.getStartPoint() < 0) { + throw new IllegalArgumentException("Start point cannot be negative"); } - if (clipConfig.getFileSize() != null) { - if (clipConfig.getFileSize() < 100) { - throw new IllegalArgumentException("File size cannot be less than 100kb"); - } + if (clipConfig.getFileSize() != null && clipConfig.getFileSize() < 100) { + throw new IllegalArgumentException("File size cannot be less than 100kb"); } job.setClipConfig(clipConfig); } - public void jobReady(String uuid) { + public void process(String uuid) { jobService.jobReady(uuid); } diff --git a/src/main/java/com/ddf/vodsystem/services/JobService.java b/src/main/java/com/ddf/vodsystem/services/JobService.java index 9491c76..9e71362 100644 --- a/src/main/java/com/ddf/vodsystem/services/JobService.java +++ b/src/main/java/com/ddf/vodsystem/services/JobService.java @@ -56,6 +56,7 @@ public class JobService { try { compressionService.run(job);// Execute the task } catch (IOException | InterruptedException e) { + Thread.currentThread().interrupt(); logger.error("Error while running job {}", job.getUuid(), e); } }