diff --git a/src/main/java/com/ddf/vodsystem/services/ClipService.java b/src/main/java/com/ddf/vodsystem/services/ClipService.java index c1b0732..3d546f3 100644 --- a/src/main/java/com/ddf/vodsystem/services/ClipService.java +++ b/src/main/java/com/ddf/vodsystem/services/ClipService.java @@ -6,6 +6,7 @@ import com.ddf.vodsystem.entities.*; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -175,7 +176,6 @@ public class ClipService { throw new FFMPEGException("Error retrieving video metadata for clip: " + e.getMessage()); } - try { thumbnailService.createThumbnail(clipFile, thumbnailFile, 0.0f); } catch (IOException | InterruptedException e) { @@ -205,15 +205,11 @@ public class ClipService { File clipFile = new File(clip.getVideoPath()); File thumbnailFile = new File(clip.getThumbnailPath()); - boolean clipDeleted = directoryService.deleteFile(clipFile); - boolean thumbnailDeleted = directoryService.deleteFile(thumbnailFile); - - if (!clipDeleted) { - throw new FFMPEGException("Failed to delete clip file: " + clipFile.getAbsolutePath()); - } - - if (!thumbnailDeleted) { - throw new FFMPEGException("Failed to delete thumbnail file: " + thumbnailFile.getAbsolutePath()); + try { + Files.deleteIfExists(clipFile.toPath()); + Files.deleteIfExists(thumbnailFile.toPath()); + } catch (IOException e) { + throw new RuntimeException(e); } } } diff --git a/src/main/java/com/ddf/vodsystem/services/DirectoryService.java b/src/main/java/com/ddf/vodsystem/services/DirectoryService.java index 2b23515..c7d7e9d 100644 --- a/src/main/java/com/ddf/vodsystem/services/DirectoryService.java +++ b/src/main/java/com/ddf/vodsystem/services/DirectoryService.java @@ -110,22 +110,6 @@ public class DirectoryService { } } - public boolean deleteFile(File file) { - if (file == null || !file.exists()) { - logger.warn("File does not exist: {}", file); - return false; - } - - try { - Files.delete(file.toPath()); - logger.debug("Deleted file: {}", file.getAbsolutePath()); - return true; - } catch (IOException e) { - logger.error("Error deleting file: {}", e.getMessage()); - return false; - } - } - public String getFileExtension(String filePath) { Path path = Paths.get(filePath); String fileName = path.getFileName().toString(); diff --git a/src/main/java/com/ddf/vodsystem/services/JobService.java b/src/main/java/com/ddf/vodsystem/services/JobService.java index f37fa00..1193285 100644 --- a/src/main/java/com/ddf/vodsystem/services/JobService.java +++ b/src/main/java/com/ddf/vodsystem/services/JobService.java @@ -2,6 +2,8 @@ package com.ddf.vodsystem.services; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.concurrent.ConcurrentHashMap; import com.ddf.vodsystem.dto.Job; @@ -75,13 +77,17 @@ public class JobService { job.getInputClipOptions().getDuration()) .thenRun(() -> { job.getStatus().getConversion().markComplete(); - directoryService.deleteFile(tempFile); + + try { + Files.deleteIfExists(Paths.get(tempFile.getAbsolutePath())); + } catch (IOException e) { + throw new RuntimeException(e); + } }); } catch (IOException | InterruptedException e) { logger.error("Error converting job {}: {}", job.getUuid(), e.getMessage()); Thread.currentThread().interrupt(); } - } /**