This commit is contained in:
@@ -337,7 +337,7 @@ public class ApiController {
|
||||
errorData));
|
||||
}
|
||||
|
||||
Path filePath = Paths.get(entityResponse.getFilePath());
|
||||
Path filePath = Paths.get(entityResponse.getProtectStatus());
|
||||
Resource resource = new UrlResource(filePath.toUri());
|
||||
|
||||
if (!resource.exists()) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.entity.file.ProtectionStatus;
|
||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.service.file.FileStorageService;
|
||||
|
||||
@@ -34,11 +35,11 @@ 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 protected");
|
||||
// }
|
||||
if (fileEntity.getProtectionStatus() != ProtectionStatus.NOT_PROTECTED) {
|
||||
throw new RuntimeException("File is protected");
|
||||
}
|
||||
|
||||
Resource resource = fileStorageService.loadFileAsResource(fileEntity.getFilePath());
|
||||
Resource resource = fileStorageService.loadFileAsResource(fileEntity.getProtectedFilePath());
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(new MediaType(fileEntity.getMimeType(), fileEntity.getFileExtension()))
|
||||
@@ -46,19 +47,4 @@ public class FileController {
|
||||
"inline; filename=\"" + fileEntity.getOriginalFileName() + "\"")
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
@GetMapping("/download/{fileId}")
|
||||
public ResponseEntity<Resource> downloadFile(@PathVariable String fileId) throws IOException {
|
||||
|
||||
FileEntity fileEntity = fileRepository.findById(fileId)
|
||||
.orElseThrow(() -> new RuntimeException("File not found"));
|
||||
|
||||
Resource resource = fileStorageService.loadFileAsResource(fileEntity.getFilePath());
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=\"" + fileEntity.getOriginalFileName() + "\"")
|
||||
.body(resource);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,10 +285,6 @@ public class FileEntityHandler implements RequestHandler {
|
||||
.build();
|
||||
} else {
|
||||
fileEntityService.softDeleteFileWithHash(fileEntity);
|
||||
//
|
||||
// imageHashRepository.deleteByFileId(fileEntity.getId());
|
||||
//
|
||||
// fileEntityService.markAsDeleted(fileEntity);
|
||||
|
||||
response = DeleteFileResponse.builder()
|
||||
.fileId(fileRequest.getFileId())
|
||||
|
||||
@@ -353,7 +353,7 @@ public class FileEntityService {
|
||||
.userId(fileEntity.getUserId())
|
||||
.originalFileName(fileEntity.getOriginalFileName())
|
||||
.storedFileName(fileEntity.getStoredFileName())
|
||||
.filePath(fileEntity.getFilePath())
|
||||
.filePath(fileEntity.getProtectedFilePath())
|
||||
.fileSize(fileEntity.getFileSize())
|
||||
.mimeType(fileEntity.getMimeType())
|
||||
.fileExtension(fileEntity.getFileExtension())
|
||||
|
||||
Reference in New Issue
Block a user