refactor(media)!: unify processing under asynchronous job workflow #3

Merged
dylan merged 14 commits from refactor/generalize-job-abstraction into master 2026-06-25 20:26:09 +01:00
3 changed files with 21 additions and 8 deletions
Showing only changes of commit 8b299dc4fa - Show all commits

View File

@@ -19,8 +19,8 @@ services:
env_file:
- .env
volumes:
- ${MEDIA_DATA}:/app/data/media
- ${STREAM_DATA}:/stream
- ${MEDIA_DATA}:/app/media
- ${STREAM_DATA}:/app/stream
ports:
- "8080:8080"
restart: unless-stopped

View File

@@ -160,9 +160,9 @@ public class ClipService {
}
String path = clip.getVideoPath();
File file = new File(path);
Path file = directoryService.resolvePath(path);
if (!file.exists()) {
if (!Files.exists(file)) {
throw new JobNotFound("Clip file not found");
}
@@ -183,8 +183,9 @@ public class ClipService {
}
String path = clip.getThumbnailPath();
File file = new File(path);
if (!file.exists()) {
Path file = directoryService.resolvePath(path);
if (!Files.exists(file)) {
throw new JobNotFound("Thumbnail file not found");
}
@@ -213,8 +214,8 @@ public class ClipService {
clip.setFps(options.getFps());
clip.setDuration(options.getDuration() - options.getStartPoint());
clip.setFileSize(options.getFileSize());
clip.setVideoPath(videoPath.toString());
clip.setThumbnailPath(thumbnailPath.toString());
clip.setVideoPath(directoryService.relativisePath(videoPath.toAbsolutePath()).toString());
clip.setThumbnailPath(directoryService.relativisePath(thumbnailPath.toAbsolutePath()).toString());
return clipRepository.save(clip);
}

View File

@@ -77,6 +77,18 @@ public class DirectoryService {
return streamFolder;
}
public Path relativisePath(Path path) {
Path media = Path.of(usersDir).toAbsolutePath();
Path newPath = path.toAbsolutePath();
return media.relativize(newPath);
}
public Path resolvePath(String path) {
Path media = Path.of(usersDir).toAbsolutePath();
Path newPath = Path.of(path);
return media.resolve(newPath);
}
public void saveMultipartFile(Path path, MultipartFile multipartFile) throws IOException {
Files.createDirectories(path.getParent());
Files.copy(multipartFile.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);