diff --git a/src/main/java/ru/soune/nocopy/adminpanel/controller/AdminController.java b/src/main/java/ru/soune/nocopy/adminpanel/controller/AdminController.java index 67e1d77..865d6cd 100644 --- a/src/main/java/ru/soune/nocopy/adminpanel/controller/AdminController.java +++ b/src/main/java/ru/soune/nocopy/adminpanel/controller/AdminController.java @@ -122,41 +122,19 @@ public class AdminController { } @GetMapping("/download/{fileId}") - public ResponseEntity downloadFile(@PathVariable String fileId) { + public ResponseEntity 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 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(); } - } }