Add file public for thumbnail
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-06-09 11:29:46 +07:00
parent eee3245fa9
commit 10703857f7
4 changed files with 32 additions and 3 deletions
@@ -156,6 +156,35 @@ public class FileController {
.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}")
public ResponseEntity<CheckStatus> getStatus(@PathVariable Long userId) {
CheckStatus status = checkCounterService.getCurrentStatus(userId);
@@ -86,7 +86,7 @@ public class FileInteranlInfoHandler implements RequestHandler {
fileMap.put("fileId", file.getId());
fileMap.put("fileName", file.getOriginalFileName());
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("status", file.getStatus() != null ? file.getStatus().name() : null);
@@ -246,7 +246,7 @@ public class FileSimilarityService {
.status(similarImageProjection.getProtectionStatus())
.owner(owner)
// .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())
.build();
}
@@ -438,7 +438,7 @@ public class FileEntityService {
.checksCount(0)
.fileUploadDate(fileEntity.getCreatedAt())
.protectedFilePath(fileEntity.getProtectedFilePath())
.thumbnailFileUrl(baseUrl + "/api/files/protected/" + fileEntity.getId() + "/thumbnail")
.thumbnailFileUrl(baseUrl + "/api/files/public/" + fileEntity.getId() + "/thumbnail")
.permissions(fileEntity.getPermissions())
.appealInfos(appeals)
.build();