add internal feign key
This commit is contained in:
@@ -122,41 +122,19 @@ public class AdminController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/download/{fileId}")
|
@GetMapping("/download/{fileId}")
|
||||||
public ResponseEntity<?> downloadFile(@PathVariable String fileId) {
|
public ResponseEntity<byte[]> downloadFile(@PathVariable String fileId) {
|
||||||
Long currentUserId = (Long) httpServletRequest.getAttribute("userId");
|
Long currentUserId = (Long) httpServletRequest.getAttribute("userId");
|
||||||
|
|
||||||
if (!adminSectionPermissionService.canRead(currentUserId,
|
if (!adminSectionPermissionService.canRead(currentUserId, AdminSection.USERS)) {
|
||||||
AdminSection.USERS)) {
|
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
||||||
return ResponseEntity.ok(BaseResponse.builder()
|
|
||||||
.msgId(0)
|
|
||||||
.messageCode(MessageCode.PERMISSION_DENIED.getCode())
|
|
||||||
.messageDesc("You can't control")
|
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResponseEntity<byte[]> response = dashBoardAppClient.download(fileId);
|
return 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);
|
|
||||||
} catch (FeignException.NotFound e) {
|
} catch (FeignException.NotFound e) {
|
||||||
return ResponseEntity.notFound().build();
|
return ResponseEntity.notFound().build();
|
||||||
} catch (FeignException e) {
|
} catch (FeignException e) {
|
||||||
log.error("Error downloading file: {}", fileId, e);
|
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user