@@ -437,6 +437,42 @@ public class ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/v{version}/files/public-download/{fileId}")
|
||||
public ResponseEntity<?> downloadFile(
|
||||
@PathVariable(required = false) String fileId, @PathVariable(required = false) Integer version) {
|
||||
FileEntityResponse entityResponse = fileEntityService.getById(fileId, version);
|
||||
FileStatus status = entityResponse.getStatus();
|
||||
|
||||
if (status.equals(FileStatus.BLOCKED) || status.equals(FileStatus.DELETED) ||
|
||||
status.equals(FileStatus.REMOVED)) {
|
||||
Map<String, Object> errorData = new HashMap<>();
|
||||
errorData.put("fileId", entityResponse.getId());
|
||||
|
||||
return ResponseEntity.ok().body(new BaseResponse(20004,
|
||||
MessageCode.FILE_IS_BLOCKED.getCode(),
|
||||
MessageCode.FILE_IS_BLOCKED.getDescription(),
|
||||
errorData));
|
||||
}
|
||||
|
||||
if (!entityResponse.getPermissions().get(PermissionType.DOWNLOAD)) {
|
||||
Map<String, Object> errorData = new HashMap<>();
|
||||
errorData.put("fileId", entityResponse.getId());
|
||||
|
||||
return ResponseEntity.ok().body(new BaseResponse(20004,
|
||||
MessageCode.NOT_HAVE_DOWNLOAD_PERMISSION.getCode(),
|
||||
MessageCode.NOT_HAVE_DOWNLOAD_PERMISSION.getDescription(),
|
||||
errorData));
|
||||
}
|
||||
|
||||
byte[] bytes = cloudStorageService.readFileFromStorageBytes(entityResponse.getProtectedFilePath());
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=\"" + entityResponse.getFileName() + "\"")
|
||||
.body(bytes);
|
||||
}
|
||||
|
||||
@GetMapping("/v{version}/files/download/{fileId}")
|
||||
public ResponseEntity<?> downloadFile(
|
||||
@PathVariable(required = false) String fileId,
|
||||
|
||||
Reference in New Issue
Block a user