@@ -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}")
|
@GetMapping("/v{version}/files/download/{fileId}")
|
||||||
public ResponseEntity<?> downloadFile(
|
public ResponseEntity<?> downloadFile(
|
||||||
@PathVariable(required = false) String fileId,
|
@PathVariable(required = false) String fileId,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class DocViewerRequest {
|
|||||||
@JsonProperty("size")
|
@JsonProperty("size")
|
||||||
private int size = 10;
|
private int size = 10;
|
||||||
|
|
||||||
@JsonProperty("created_at")
|
@JsonProperty("sort_by")
|
||||||
private String sortBy = "createdAt";
|
private String sortBy = "createdAt";
|
||||||
|
|
||||||
@JsonProperty("sort_direction")
|
@JsonProperty("sort_direction")
|
||||||
|
|||||||
Reference in New Issue
Block a user