Create storage path for videos

This commit is contained in:
2025-05-09 16:10:13 +02:00
parent 5fbea946fc
commit d501a40f47
6 changed files with 40 additions and 21 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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<Path> 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);
}
}
}

View File

@@ -10,7 +10,7 @@ public interface StorageService {
void init();
String store(MultipartFile file,String folder);
String store(MultipartFile file,String folder, Boolean isVideo);
Stream<Path> loadAll();