From d501a40f47480403756df60b3c3ddee27ef13c8f Mon Sep 17 00:00:00 2001 From: Emanuele Ferrelli Date: Fri, 9 May 2025 16:10:13 +0200 Subject: [PATCH] Create storage path for videos --- manifests/apollo-deployment.yaml | 3 ++ .../apollo/controllers/KSFileController.java | 3 +- .../apollo/controllers/VideoController.java | 3 +- .../apollo/properties/StorageProperties.java | 8 ++++ .../services/FileSystemStorageService.java | 42 +++++++++++-------- .../apollo/services/StorageService.java | 2 +- 6 files changed, 40 insertions(+), 21 deletions(-) diff --git a/manifests/apollo-deployment.yaml b/manifests/apollo-deployment.yaml index 3529b6e..d0f2572 100644 --- a/manifests/apollo-deployment.yaml +++ b/manifests/apollo-deployment.yaml @@ -32,6 +32,9 @@ spec: - name: apollo-pv-storage mountPath: /mnt/apollo_storage/documents subPath: documents + - name: apollo-pv-storage + mountPath: /mnt/apollo_storage/videos + subPath: videos - name: apollo-pv-storage mountPath: /mnt/apollo_storage/repository subPath: repository diff --git a/src/main/java/com/olympus/apollo/controllers/KSFileController.java b/src/main/java/com/olympus/apollo/controllers/KSFileController.java index 968e008..2c4e587 100644 --- a/src/main/java/com/olympus/apollo/controllers/KSFileController.java +++ b/src/main/java/com/olympus/apollo/controllers/KSFileController.java @@ -54,7 +54,8 @@ public class KSFileController { @RequestParam("file") MultipartFile file, @ModelAttribute FileUploadDTO fileUploadDTO ) { - String filePath = storageService.store(file,fileUploadDTO.getKsProjectName()); + Boolean isVideo = false; + String filePath = storageService.store(file,fileUploadDTO.getKsProjectName(), isVideo); KSDocument ksDocument = new KSDocument(); ksDocument.setFilePath(filePath); diff --git a/src/main/java/com/olympus/apollo/controllers/VideoController.java b/src/main/java/com/olympus/apollo/controllers/VideoController.java index 02db284..e04f2f3 100644 --- a/src/main/java/com/olympus/apollo/controllers/VideoController.java +++ b/src/main/java/com/olympus/apollo/controllers/VideoController.java @@ -31,7 +31,8 @@ public class VideoController { @RequestParam("file") MultipartFile file, @ModelAttribute VideoUploadDTO videoUploadDTO ) { - String filePath = storageService.store(file,videoUploadDTO.getKsProjectName()); + Boolean isVideo = true; + String filePath = storageService.store(file,videoUploadDTO.getKsProjectName(), isVideo); KSVideo ksVideo = new KSVideo(); ksVideo.setFilePath(filePath); diff --git a/src/main/java/com/olympus/apollo/properties/StorageProperties.java b/src/main/java/com/olympus/apollo/properties/StorageProperties.java index 777b468..35291cf 100644 --- a/src/main/java/com/olympus/apollo/properties/StorageProperties.java +++ b/src/main/java/com/olympus/apollo/properties/StorageProperties.java @@ -10,6 +10,7 @@ public class StorageProperties { //private String location = ingestionRepositoryBasePath; private String location = "/mnt/apollo_storage/documents"; + private String videoLocation = "/mnt/apollo_storage/videos"; //private String location = "C:\\repos\\olympus_ai\\Documents"; public String getLocation() { return location; @@ -19,4 +20,11 @@ public class StorageProperties { this.location = location; } + public String getVideoLocation() { + return videoLocation; + } + public void setVideoLocation(String videoLocation) { + this.videoLocation = videoLocation; + } + } \ No newline at end of file diff --git a/src/main/java/com/olympus/apollo/services/FileSystemStorageService.java b/src/main/java/com/olympus/apollo/services/FileSystemStorageService.java index b10a8db..1d0a3d1 100644 --- a/src/main/java/com/olympus/apollo/services/FileSystemStorageService.java +++ b/src/main/java/com/olympus/apollo/services/FileSystemStorageService.java @@ -22,28 +22,35 @@ import org.springframework.web.multipart.MultipartFile; @Service public class FileSystemStorageService implements StorageService { - private final Path rootLocation; + private final Path defaultLocation; + private final Path videoLocation; + private Path currentLocation; @Autowired public FileSystemStorageService(StorageProperties properties) { - if(properties.getLocation().trim().length() == 0){ throw new StorageException("File upload location can not be Empty."); } - - this.rootLocation = Paths.get(properties.getLocation()); + + this.defaultLocation = Paths.get(properties.getLocation()); + this.videoLocation = Paths.get(properties.getVideoLocation()); + this.currentLocation = this.defaultLocation; } - @Override - public String store(MultipartFile file, String folder) { + public String store(MultipartFile file, String folder, Boolean isVideo) { String destinationFileString = null; + if(isVideo){ + this.currentLocation = this.videoLocation; + }else{ + this.currentLocation = this.defaultLocation; + } try { if (file.isEmpty()) { throw new StorageException("Failed to store empty file."); } - Path folderPath = this.rootLocation.resolve(folder).normalize().toAbsolutePath(); - if (!folderPath.startsWith(this.rootLocation.toAbsolutePath())) { + Path folderPath = this.currentLocation.resolve(folder).normalize().toAbsolutePath(); + if (!folderPath.startsWith(this.currentLocation.toAbsolutePath())) { // This is a security check throw new StorageException("Cannot store file outside current directory."); } @@ -63,19 +70,18 @@ public class FileSystemStorageService implements StorageService { @Override public Stream loadAll() { try { - return Files.walk(this.rootLocation, 1) - .filter(path -> !path.equals(this.rootLocation)) - .map(this.rootLocation::relativize); + return Files.walk(this.currentLocation, 1) + .filter(path -> !path.equals(this.currentLocation)) + .map(this.currentLocation::relativize); } catch (IOException e) { throw new StorageException("Failed to read stored files", e); } - } @Override public Path load(String filename) { - return rootLocation.resolve(filename); + return currentLocation.resolve(filename); } @Override @@ -89,7 +95,6 @@ public class FileSystemStorageService implements StorageService { else { throw new StorageFileNotFoundException( "Could not read file: " + filename); - } } catch (MalformedURLException e) { @@ -99,18 +104,19 @@ public class FileSystemStorageService implements StorageService { @Override public void deleteAll() { - FileSystemUtils.deleteRecursively(rootLocation.toFile()); + FileSystemUtils.deleteRecursively(defaultLocation.toFile()); + FileSystemUtils.deleteRecursively(videoLocation.toFile()); } @Override public void init() { try { - Files.createDirectories(rootLocation); + // Create main storage directories + Files.createDirectories(defaultLocation); + Files.createDirectories(videoLocation); } catch (IOException e) { throw new StorageException("Could not initialize storage", e); } } - - } diff --git a/src/main/java/com/olympus/apollo/services/StorageService.java b/src/main/java/com/olympus/apollo/services/StorageService.java index f8aba4f..d2e4b70 100644 --- a/src/main/java/com/olympus/apollo/services/StorageService.java +++ b/src/main/java/com/olympus/apollo/services/StorageService.java @@ -10,7 +10,7 @@ public interface StorageService { void init(); - String store(MultipartFile file,String folder); + String store(MultipartFile file,String folder, Boolean isVideo); Stream loadAll();