Create storage path for videos
This commit is contained in:
@@ -32,6 +32,9 @@ spec:
|
|||||||
- name: apollo-pv-storage
|
- name: apollo-pv-storage
|
||||||
mountPath: /mnt/apollo_storage/documents
|
mountPath: /mnt/apollo_storage/documents
|
||||||
subPath: documents
|
subPath: documents
|
||||||
|
- name: apollo-pv-storage
|
||||||
|
mountPath: /mnt/apollo_storage/videos
|
||||||
|
subPath: videos
|
||||||
- name: apollo-pv-storage
|
- name: apollo-pv-storage
|
||||||
mountPath: /mnt/apollo_storage/repository
|
mountPath: /mnt/apollo_storage/repository
|
||||||
subPath: repository
|
subPath: repository
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ public class KSFileController {
|
|||||||
@RequestParam("file") MultipartFile file,
|
@RequestParam("file") MultipartFile file,
|
||||||
@ModelAttribute FileUploadDTO fileUploadDTO
|
@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 ksDocument = new KSDocument();
|
||||||
ksDocument.setFilePath(filePath);
|
ksDocument.setFilePath(filePath);
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ public class VideoController {
|
|||||||
@RequestParam("file") MultipartFile file,
|
@RequestParam("file") MultipartFile file,
|
||||||
@ModelAttribute VideoUploadDTO videoUploadDTO
|
@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 ksVideo = new KSVideo();
|
||||||
ksVideo.setFilePath(filePath);
|
ksVideo.setFilePath(filePath);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public class StorageProperties {
|
|||||||
|
|
||||||
//private String location = ingestionRepositoryBasePath;
|
//private String location = ingestionRepositoryBasePath;
|
||||||
private String location = "/mnt/apollo_storage/documents";
|
private String location = "/mnt/apollo_storage/documents";
|
||||||
|
private String videoLocation = "/mnt/apollo_storage/videos";
|
||||||
//private String location = "C:\\repos\\olympus_ai\\Documents";
|
//private String location = "C:\\repos\\olympus_ai\\Documents";
|
||||||
public String getLocation() {
|
public String getLocation() {
|
||||||
return location;
|
return location;
|
||||||
@@ -19,4 +20,11 @@ public class StorageProperties {
|
|||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getVideoLocation() {
|
||||||
|
return videoLocation;
|
||||||
|
}
|
||||||
|
public void setVideoLocation(String videoLocation) {
|
||||||
|
this.videoLocation = videoLocation;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,28 +22,35 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
@Service
|
@Service
|
||||||
public class FileSystemStorageService implements StorageService {
|
public class FileSystemStorageService implements StorageService {
|
||||||
|
|
||||||
private final Path rootLocation;
|
private final Path defaultLocation;
|
||||||
|
private final Path videoLocation;
|
||||||
|
private Path currentLocation;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public FileSystemStorageService(StorageProperties properties) {
|
public FileSystemStorageService(StorageProperties properties) {
|
||||||
|
|
||||||
if(properties.getLocation().trim().length() == 0){
|
if(properties.getLocation().trim().length() == 0){
|
||||||
throw new StorageException("File upload location can not be Empty.");
|
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, Boolean isVideo) {
|
||||||
public String store(MultipartFile file, String folder) {
|
|
||||||
String destinationFileString = null;
|
String destinationFileString = null;
|
||||||
|
if(isVideo){
|
||||||
|
this.currentLocation = this.videoLocation;
|
||||||
|
}else{
|
||||||
|
this.currentLocation = this.defaultLocation;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
throw new StorageException("Failed to store empty file.");
|
throw new StorageException("Failed to store empty file.");
|
||||||
}
|
}
|
||||||
Path folderPath = this.rootLocation.resolve(folder).normalize().toAbsolutePath();
|
Path folderPath = this.currentLocation.resolve(folder).normalize().toAbsolutePath();
|
||||||
if (!folderPath.startsWith(this.rootLocation.toAbsolutePath())) {
|
if (!folderPath.startsWith(this.currentLocation.toAbsolutePath())) {
|
||||||
// This is a security check
|
// This is a security check
|
||||||
throw new StorageException("Cannot store file outside current directory.");
|
throw new StorageException("Cannot store file outside current directory.");
|
||||||
}
|
}
|
||||||
@@ -63,19 +70,18 @@ public class FileSystemStorageService implements StorageService {
|
|||||||
@Override
|
@Override
|
||||||
public Stream<Path> loadAll() {
|
public Stream<Path> loadAll() {
|
||||||
try {
|
try {
|
||||||
return Files.walk(this.rootLocation, 1)
|
return Files.walk(this.currentLocation, 1)
|
||||||
.filter(path -> !path.equals(this.rootLocation))
|
.filter(path -> !path.equals(this.currentLocation))
|
||||||
.map(this.rootLocation::relativize);
|
.map(this.currentLocation::relativize);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new StorageException("Failed to read stored files", e);
|
throw new StorageException("Failed to read stored files", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path load(String filename) {
|
public Path load(String filename) {
|
||||||
return rootLocation.resolve(filename);
|
return currentLocation.resolve(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -89,7 +95,6 @@ public class FileSystemStorageService implements StorageService {
|
|||||||
else {
|
else {
|
||||||
throw new StorageFileNotFoundException(
|
throw new StorageFileNotFoundException(
|
||||||
"Could not read file: " + filename);
|
"Could not read file: " + filename);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (MalformedURLException e) {
|
catch (MalformedURLException e) {
|
||||||
@@ -99,18 +104,19 @@ public class FileSystemStorageService implements StorageService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAll() {
|
public void deleteAll() {
|
||||||
FileSystemUtils.deleteRecursively(rootLocation.toFile());
|
FileSystemUtils.deleteRecursively(defaultLocation.toFile());
|
||||||
|
FileSystemUtils.deleteRecursively(videoLocation.toFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(rootLocation);
|
// Create main storage directories
|
||||||
|
Files.createDirectories(defaultLocation);
|
||||||
|
Files.createDirectories(videoLocation);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
throw new StorageException("Could not initialize storage", e);
|
throw new StorageException("Could not initialize storage", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public interface StorageService {
|
|||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
String store(MultipartFile file,String folder);
|
String store(MultipartFile file,String folder, Boolean isVideo);
|
||||||
|
|
||||||
Stream<Path> loadAll();
|
Stream<Path> loadAll();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user