This commit is contained in:
@@ -156,6 +156,35 @@ public class FileController {
|
|||||||
.body(resource);
|
.body(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/public/{fileId}/{type}")
|
||||||
|
public ResponseEntity<Resource> getPublicFileWithTpe(
|
||||||
|
@PathVariable String fileId, @PathVariable String type) throws IOException {
|
||||||
|
|
||||||
|
FileEntity fileEntity = fileRepository.findById(fileId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("File not found"));
|
||||||
|
|
||||||
|
String filePath = type.equals("thumbnail") ? fileEntity.getThumbnailPath(): fileEntity.getFilePath();
|
||||||
|
|
||||||
|
if (fileEntity.getProtectionStatus() == ProtectionStatus.NOT_PROTECTED ||
|
||||||
|
fileEntity.getProtectionStatus() == ProtectionStatus.PROCESSING) {
|
||||||
|
throw new RuntimeException("File is not protected");
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileName = fileEntity.getOriginalFileName().replace("." +
|
||||||
|
fileEntity.getFileExtension(), "") + "_nocopy_protected" +
|
||||||
|
"." + fileEntity.getFileExtension();
|
||||||
|
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8)
|
||||||
|
.replace("+", "%20");
|
||||||
|
|
||||||
|
InputStreamResource resource = new InputStreamResource(cloudStorageService.readFileFromStorage(filePath));
|
||||||
|
|
||||||
|
return ResponseEntity.ok()
|
||||||
|
.contentType(new MediaType(fileEntity.getMimeType(), fileEntity.getFileExtension()))
|
||||||
|
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||||
|
"inline; filename*=UTF-8''" + encodedFileName)
|
||||||
|
.body(resource);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("check-file/status/{userId}")
|
@GetMapping("check-file/status/{userId}")
|
||||||
public ResponseEntity<CheckStatus> getStatus(@PathVariable Long userId) {
|
public ResponseEntity<CheckStatus> getStatus(@PathVariable Long userId) {
|
||||||
CheckStatus status = checkCounterService.getCurrentStatus(userId);
|
CheckStatus status = checkCounterService.getCurrentStatus(userId);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class FileInteranlInfoHandler implements RequestHandler {
|
|||||||
fileMap.put("fileId", file.getId());
|
fileMap.put("fileId", file.getId());
|
||||||
fileMap.put("fileName", file.getOriginalFileName());
|
fileMap.put("fileName", file.getOriginalFileName());
|
||||||
fileMap.put("downloadUrl", "/api/admin/download/" + file.getId());
|
fileMap.put("downloadUrl", "/api/admin/download/" + file.getId());
|
||||||
fileMap.put("image", baseUrl + "/api/files/protected/" + file.getId() + "/thumbnail");
|
fileMap.put("image", baseUrl + "/api/files/public/" + file.getId() + "/thumbnail");
|
||||||
|
|
||||||
fileMap.put("userId", file.getUserId());
|
fileMap.put("userId", file.getUserId());
|
||||||
fileMap.put("status", file.getStatus() != null ? file.getStatus().name() : null);
|
fileMap.put("status", file.getStatus() != null ? file.getStatus().name() : null);
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ public class FileSimilarityService {
|
|||||||
.status(similarImageProjection.getProtectionStatus())
|
.status(similarImageProjection.getProtectionStatus())
|
||||||
.owner(owner)
|
.owner(owner)
|
||||||
// .url(baseUrl + "/api/files/protected/" + similarImageProjection.getId())
|
// .url(baseUrl + "/api/files/protected/" + similarImageProjection.getId())
|
||||||
.url(baseUrl + "/api/files/protected/" + similarImageProjection.getId() + "/thumbnail")
|
.url(baseUrl + "/api/files/public/" + similarImageProjection.getId() + "/thumbnail")
|
||||||
.fileStatus(similarImageProjection.getFileStatus())
|
.fileStatus(similarImageProjection.getFileStatus())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ public class FileEntityService {
|
|||||||
.checksCount(0)
|
.checksCount(0)
|
||||||
.fileUploadDate(fileEntity.getCreatedAt())
|
.fileUploadDate(fileEntity.getCreatedAt())
|
||||||
.protectedFilePath(fileEntity.getProtectedFilePath())
|
.protectedFilePath(fileEntity.getProtectedFilePath())
|
||||||
.thumbnailFileUrl(baseUrl + "/api/files/protected/" + fileEntity.getId() + "/thumbnail")
|
.thumbnailFileUrl(baseUrl + "/api/files/public/" + fileEntity.getId() + "/thumbnail")
|
||||||
.permissions(fileEntity.getPermissions())
|
.permissions(fileEntity.getPermissions())
|
||||||
.appealInfos(appeals)
|
.appealInfos(appeals)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
Reference in New Issue
Block a user