REMOVE deleteFile in DirectoryService and replace with local methods
This commit is contained in:
@@ -6,6 +6,7 @@ import com.ddf.vodsystem.entities.*;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -175,7 +176,6 @@ public class ClipService {
|
|||||||
throw new FFMPEGException("Error retrieving video metadata for clip: " + e.getMessage());
|
throw new FFMPEGException("Error retrieving video metadata for clip: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
thumbnailService.createThumbnail(clipFile, thumbnailFile, 0.0f);
|
thumbnailService.createThumbnail(clipFile, thumbnailFile, 0.0f);
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
@@ -205,15 +205,11 @@ public class ClipService {
|
|||||||
File clipFile = new File(clip.getVideoPath());
|
File clipFile = new File(clip.getVideoPath());
|
||||||
File thumbnailFile = new File(clip.getThumbnailPath());
|
File thumbnailFile = new File(clip.getThumbnailPath());
|
||||||
|
|
||||||
boolean clipDeleted = directoryService.deleteFile(clipFile);
|
try {
|
||||||
boolean thumbnailDeleted = directoryService.deleteFile(thumbnailFile);
|
Files.deleteIfExists(clipFile.toPath());
|
||||||
|
Files.deleteIfExists(thumbnailFile.toPath());
|
||||||
if (!clipDeleted) {
|
} catch (IOException e) {
|
||||||
throw new FFMPEGException("Failed to delete clip file: " + clipFile.getAbsolutePath());
|
throw new RuntimeException(e);
|
||||||
}
|
|
||||||
|
|
||||||
if (!thumbnailDeleted) {
|
|
||||||
throw new FFMPEGException("Failed to delete thumbnail file: " + thumbnailFile.getAbsolutePath());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
public String getFileExtension(String filePath) {
|
||||||
Path path = Paths.get(filePath);
|
Path path = Paths.get(filePath);
|
||||||
String fileName = path.getFileName().toString();
|
String fileName = path.getFileName().toString();
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.ddf.vodsystem.services;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import com.ddf.vodsystem.dto.Job;
|
import com.ddf.vodsystem.dto.Job;
|
||||||
@@ -75,13 +77,17 @@ public class JobService {
|
|||||||
job.getInputClipOptions().getDuration())
|
job.getInputClipOptions().getDuration())
|
||||||
.thenRun(() -> {
|
.thenRun(() -> {
|
||||||
job.getStatus().getConversion().markComplete();
|
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) {
|
} catch (IOException | InterruptedException e) {
|
||||||
logger.error("Error converting job {}: {}", job.getUuid(), e.getMessage());
|
logger.error("Error converting job {}: {}", job.getUuid(), e.getMessage());
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user