dev #1
@@ -122,41 +122,19 @@ public class AdminController {
|
||||
}
|
||||
|
||||
@GetMapping("/download/{fileId}")
|
||||
public ResponseEntity<?> downloadFile(@PathVariable String fileId) {
|
||||
public ResponseEntity<byte[]> downloadFile(@PathVariable String fileId) {
|
||||
Long currentUserId = (Long) httpServletRequest.getAttribute("userId");
|
||||
|
||||
if (!adminSectionPermissionService.canRead(currentUserId,
|
||||
AdminSection.USERS)) {
|
||||
return ResponseEntity.ok(BaseResponse.builder()
|
||||
.msgId(0)
|
||||
.messageCode(MessageCode.PERMISSION_DENIED.getCode())
|
||||
.messageDesc("You can't control")
|
||||
.build());
|
||||
if (!adminSectionPermissionService.canRead(currentUserId, AdminSection.USERS)) {
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
||||
}
|
||||
|
||||
try {
|
||||
ResponseEntity<byte[]> response = dashBoardAppClient.download(fileId);
|
||||
|
||||
StreamingResponseBody streamBody = new StreamingResponseBody() {
|
||||
@Override
|
||||
public void writeTo(OutputStream outputStream) throws IOException {
|
||||
outputStream.write(response.getBody());
|
||||
outputStream.flush();
|
||||
}
|
||||
};
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(response.getHeaders().getContentType())
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,
|
||||
response.getHeaders().getFirst(HttpHeaders.CONTENT_DISPOSITION))
|
||||
.header(HttpHeaders.CACHE_CONTROL,
|
||||
response.getHeaders().getFirst(HttpHeaders.CACHE_CONTROL))
|
||||
.body(streamBody);
|
||||
return dashBoardAppClient.download(fileId);
|
||||
} catch (FeignException.NotFound e) {
|
||||
return ResponseEntity.notFound().build();
|
||||
} catch (FeignException e) {
|
||||
log.error("Error downloading file: {}", fileId, e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user