fix(directories): inputs absolute paths into db
This commit is contained in:
@@ -19,8 +19,8 @@ services:
|
|||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
volumes:
|
volumes:
|
||||||
- ${MEDIA_DATA}:/app/data/media
|
- ${MEDIA_DATA}:/app/media
|
||||||
- ${STREAM_DATA}:/stream
|
- ${STREAM_DATA}:/app/stream
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -160,9 +160,9 @@ public class ClipService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String path = clip.getVideoPath();
|
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");
|
throw new JobNotFound("Clip file not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,8 +183,9 @@ public class ClipService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String path = clip.getThumbnailPath();
|
String path = clip.getThumbnailPath();
|
||||||
File file = new File(path);
|
Path file = directoryService.resolvePath(path);
|
||||||
if (!file.exists()) {
|
|
||||||
|
if (!Files.exists(file)) {
|
||||||
throw new JobNotFound("Thumbnail file not found");
|
throw new JobNotFound("Thumbnail file not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,8 +214,8 @@ public class ClipService {
|
|||||||
clip.setFps(options.getFps());
|
clip.setFps(options.getFps());
|
||||||
clip.setDuration(options.getDuration() - options.getStartPoint());
|
clip.setDuration(options.getDuration() - options.getStartPoint());
|
||||||
clip.setFileSize(options.getFileSize());
|
clip.setFileSize(options.getFileSize());
|
||||||
clip.setVideoPath(videoPath.toString());
|
clip.setVideoPath(directoryService.relativisePath(videoPath.toAbsolutePath()).toString());
|
||||||
clip.setThumbnailPath(thumbnailPath.toString());
|
clip.setThumbnailPath(directoryService.relativisePath(thumbnailPath.toAbsolutePath()).toString());
|
||||||
return clipRepository.save(clip);
|
return clipRepository.save(clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,18 @@ public class DirectoryService {
|
|||||||
return streamFolder;
|
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 {
|
public void saveMultipartFile(Path path, MultipartFile multipartFile) throws IOException {
|
||||||
Files.createDirectories(path.getParent());
|
Files.createDirectories(path.getParent());
|
||||||
Files.copy(multipartFile.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(multipartFile.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|||||||
Reference in New Issue
Block a user