@@ -14,6 +14,7 @@ import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.file.CheckCounterService;
|
||||
import ru.soune.nocopy.service.file.FileStorageService;
|
||||
import ru.soune.nocopy.service.file.ImageResizeService;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URLEncoder;
|
||||
@@ -41,24 +42,8 @@ public class FileController {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
// @GetMapping("/public/{fileId}")
|
||||
// public ResponseEntity<Resource> getPublicFile(
|
||||
// @PathVariable String fileId) throws IOException {
|
||||
//
|
||||
// FileEntity fileEntity = fileRepository.findById(fileId)
|
||||
// .orElseThrow(() -> new RuntimeException("File not found"));
|
||||
//
|
||||
// Resource resource = fileStorageService.loadFileAsResource(fileEntity.getFilePath());
|
||||
//
|
||||
// ContentDisposition contentDisposition = ContentDisposition.inline()
|
||||
// .filename(fileEntity.getOriginalFileName(), StandardCharsets.UTF_8)
|
||||
// .build();
|
||||
//
|
||||
// return ResponseEntity.ok()
|
||||
// .contentType(new MediaType(fileEntity.getMimeType(), fileEntity.getFileExtension()))
|
||||
// .header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString())
|
||||
// .body(resource);
|
||||
// }
|
||||
@Autowired
|
||||
private ImageResizeService imageResizeService;
|
||||
|
||||
@GetMapping("/public/{fileId}")
|
||||
public ResponseEntity<Resource> getPublicFile(@PathVariable String fileId) {
|
||||
@@ -117,14 +102,16 @@ public class FileController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/protected/{fileId}")
|
||||
@GetMapping("/protected/{fileId}/{type}")
|
||||
public ResponseEntity<Resource> getProtectedFile(
|
||||
@PathVariable String fileId) throws IOException {
|
||||
@PathVariable String fileId, @PathVariable String type) throws IOException {
|
||||
|
||||
FileEntity fileEntity = fileRepository.findById(fileId)
|
||||
.orElseThrow(() -> new RuntimeException("File not found"));
|
||||
|
||||
Resource resource = fileStorageService.loadFileAsResource(fileEntity.getProtectedFilePath());
|
||||
String path = imageResizeService.getPath(fileEntity, type);
|
||||
|
||||
Resource resource = fileStorageService.loadFileAsResource(path);
|
||||
|
||||
if (fileEntity.getProtectionStatus() == ProtectionStatus.NOT_PROTECTED ||
|
||||
fileEntity.getProtectionStatus() == ProtectionStatus.PROCESSING) {
|
||||
|
||||
Reference in New Issue
Block a user