From 20f4e6c8756e87c951cae70ed47f9617e308f0d8 Mon Sep 17 00:00:00 2001 From: JuhyunPark Date: Fri, 5 Apr 2024 15:41:54 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20=ED=8C=8C=EC=9D=BC=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EA=B4=80=EB=A0=A8=20=EC=88=98=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20=EC=83=81=ED=92=88=20=ED=8C=90=EB=A7=A4=20=EC=A4=91=EC=A7=80?= =?UTF-8?q?=20HTTP=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlanIT/common/modules/FileHandler.java | 23 ++++++++++++++++++- .../PlanIT/config/SecurityConfig.java | 2 +- .../file/controller/FileController.java | 4 +--- .../controller/ProductAdminController.java | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java b/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java index 51fedc0..24fd7ab 100644 --- a/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java +++ b/src/main/java/com/sideProject/PlanIT/common/modules/FileHandler.java @@ -11,6 +11,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.Arrays; +import java.util.List; import java.util.UUID; @Component @@ -29,7 +31,12 @@ public String saveFile(MultipartFile file) { File dest = new File(fileStorageDir + File.separator + fileName); file.transferTo(dest); - return fileName; + String fileExtension = getFileExtension(fileName); + if (isImageFile(fileExtension)) { + return "/image/" + fileName; + } else { + return "/file/" + fileName; + } } catch (IOException e) { log.error(e.getMessage()); return "이미지 업로드 오류 발생"; @@ -56,4 +63,18 @@ private String getUniqueFileName(String fileName) { return UUID.randomUUID() + fileName; } + private String getFileExtension(String fileName) { + int lastIndex = fileName.lastIndexOf('.'); + if (lastIndex > 0) { + return fileName.substring(lastIndex + 1); + } + return ""; + } + + private boolean isImageFile(String fileExtension) { + // 이미지 파일 확장자 리스트 + List imageExtensions = Arrays.asList("jpg", "jpeg", "png", "gif"); + return imageExtensions.contains(fileExtension.toLowerCase()); + } + } diff --git a/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java b/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java index eb49fa3..47e8e83 100644 --- a/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java +++ b/src/main/java/com/sideProject/PlanIT/config/SecurityConfig.java @@ -59,7 +59,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { .exceptionHandling((exceptionHandling) -> exceptionHandling.authenticationEntryPoint(jwtAuthenticationEntryPoint)) .authorizeHttpRequests((authorizeRequests) -> authorizeRequests - .requestMatchers("/member/signin", "/member/signup", "/member/refresh", "/member/email/**").permitAll() + .requestMatchers("/member/signin", "/member/signup", "/member/refresh", "/member/email/**", "/login/**").permitAll() .requestMatchers("/admin/**").hasAnyAuthority("ADMIN") .anyRequest().authenticated() ) diff --git a/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java b/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java index 4383650..9115de6 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java @@ -10,14 +10,12 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; @RestController @RequiredArgsConstructor -@RequestMapping("/file") public class FileController { private final FileHandler fileHandler; @@ -35,7 +33,7 @@ public ResponseEntity loadImage(@PathVariable String image_name) { } } - @GetMapping("/{file_name}") + @GetMapping("file/{file_name}") public ResponseEntity loadFile(@PathVariable String file_name) { try { byte[] fileBytes = fileHandler.loadFile(file_name); diff --git a/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java b/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java index f1b3e27..b23d8c1 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/product/controller/ProductAdminController.java @@ -18,7 +18,7 @@ public ApiResponse createProduct(@RequestBody ProductRequestDto product return ApiResponse.ok(productService.createProduct(productRequestDto)); } - @PutMapping("/{product_id}") + @DeleteMapping("/{product_id}") public ApiResponse stopSelling(@PathVariable Long product_id) { return ApiResponse.ok(productService.stopProductSell(product_id)); } From 7b7de927e0754eb0ceb8d7be79e953a8a082c51c Mon Sep 17 00:00:00 2001 From: JuhyunPark Date: Fri, 5 Apr 2024 15:47:19 +0900 Subject: [PATCH 2/2] Update FileController.java --- .../PlanIT/domain/file/controller/FileController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java b/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java index 9115de6..2336f3d 100644 --- a/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java +++ b/src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.java @@ -33,7 +33,7 @@ public ResponseEntity loadImage(@PathVariable String image_name) { } } - @GetMapping("file/{file_name}") + @GetMapping("/file/{file_name}") public ResponseEntity loadFile(@PathVariable String file_name) { try { byte[] fileBytes = fileHandler.loadFile(file_name);