fix(directories): inputs absolute paths into db
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user