diff --git a/src/main/java/ru/soune/nocopy/controller/FileController.java b/src/main/java/ru/soune/nocopy/controller/FileController.java index a8c904e..e08455c 100644 --- a/src/main/java/ru/soune/nocopy/controller/FileController.java +++ b/src/main/java/ru/soune/nocopy/controller/FileController.java @@ -43,12 +43,29 @@ public class FileController { FileEntity fileEntity = fileRepository.findById(fileId) .orElseThrow(() -> new RuntimeException("File not found")); - if (fileEntity.getProtectionStatus() == ProtectionStatus.NOT_PROTECTED) { - throw new RuntimeException("File is not protected"); - } + Resource resource = fileStorageService.loadFileAsResource(fileEntity.getFilePath()); + + return ResponseEntity.ok() + .contentType(new MediaType(fileEntity.getMimeType(), fileEntity.getFileExtension())) + .header(HttpHeaders.CONTENT_DISPOSITION, + "inline; filename=\"" + fileEntity.getOriginalFileName() + "\"") + .body(resource); + } + + @GetMapping("/protected/{fileId}") + public ResponseEntity getProtectedFile( + @PathVariable String fileId) throws IOException { + + FileEntity fileEntity = fileRepository.findById(fileId) + .orElseThrow(() -> new RuntimeException("File not found")); Resource resource = fileStorageService.loadFileAsResource(fileEntity.getProtectedFilePath()); + if (fileEntity.getProtectionStatus() == ProtectionStatus.NOT_PROTECTED || + fileEntity.getProtectionStatus() == ProtectionStatus.PROCESSING) { + throw new RuntimeException("File is not protected"); + } + return ResponseEntity.ok() .contentType(new MediaType(fileEntity.getMimeType(), fileEntity.getFileExtension())) .header(HttpHeaders.CONTENT_DISPOSITION,