From e49a944b05084dca679f5cb2cb6526c340eea86a Mon Sep 17 00:00:00 2001 From: vladp Date: Thu, 5 Feb 2026 03:30:15 +0700 Subject: [PATCH] dev add test find by searchapo --- .../nocopy/controller/FileController.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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,