This commit is contained in:
@@ -43,12 +43,29 @@ public class FileController {
|
|||||||
FileEntity fileEntity = fileRepository.findById(fileId)
|
FileEntity fileEntity = fileRepository.findById(fileId)
|
||||||
.orElseThrow(() -> new RuntimeException("File not found"));
|
.orElseThrow(() -> new RuntimeException("File not found"));
|
||||||
|
|
||||||
if (fileEntity.getProtectionStatus() == ProtectionStatus.NOT_PROTECTED) {
|
Resource resource = fileStorageService.loadFileAsResource(fileEntity.getFilePath());
|
||||||
throw new RuntimeException("File is not protected");
|
|
||||||
}
|
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<Resource> getProtectedFile(
|
||||||
|
@PathVariable String fileId) throws IOException {
|
||||||
|
|
||||||
|
FileEntity fileEntity = fileRepository.findById(fileId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("File not found"));
|
||||||
|
|
||||||
Resource resource = fileStorageService.loadFileAsResource(fileEntity.getProtectedFilePath());
|
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()
|
return ResponseEntity.ok()
|
||||||
.contentType(new MediaType(fileEntity.getMimeType(), fileEntity.getFileExtension()))
|
.contentType(new MediaType(fileEntity.getMimeType(), fileEntity.getFileExtension()))
|
||||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||||
|
|||||||
Reference in New Issue
Block a user