diff --git a/docker-compose.yml b/docker-compose.yml index 8c87eba..7c498dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/src/main/java/com/ddf/vodsystem/services/ClipService.java b/src/main/java/com/ddf/vodsystem/services/ClipService.java index 0abe1ad..c99014f 100644 --- a/src/main/java/com/ddf/vodsystem/services/ClipService.java +++ b/src/main/java/com/ddf/vodsystem/services/ClipService.java @@ -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); } diff --git a/src/main/java/com/ddf/vodsystem/services/DirectoryService.java b/src/main/java/com/ddf/vodsystem/services/DirectoryService.java index 0bbcc62..92cd20a 100644 --- a/src/main/java/com/ddf/vodsystem/services/DirectoryService.java +++ b/src/main/java/com/ddf/vodsystem/services/DirectoryService.java @@ -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);