From 99d7b2b4759310935c6d7f49f669695d0b2d5554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=A7=84=ED=83=9D?= <87135698+jjt4515@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:01:21 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20key?= =?UTF-8?q?=20=ED=98=95=EC=8B=9D=20=EC=88=98=EC=A0=95=20#33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poomasi/domain/image/controller/ImageController.java | 4 ++-- .../poomasi/global/config/s3/S3PresignedUrlService.java | 6 ++++-- src/main/java/poomasi/global/util/EncryptionUtil.java | 4 +--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/poomasi/domain/image/controller/ImageController.java b/src/main/java/poomasi/domain/image/controller/ImageController.java index 8e64c1e..be32b5d 100644 --- a/src/main/java/poomasi/domain/image/controller/ImageController.java +++ b/src/main/java/poomasi/domain/image/controller/ImageController.java @@ -16,14 +16,14 @@ public class ImageController { private final ImageService imageService; - // 이미지 업로드 + // 이미지 정보 저장 @PostMapping public ResponseEntity saveImageInfo(@RequestBody ImageRequest imageRequest) { Image savedImage = imageService.saveImage(imageRequest); return ResponseEntity.ok(savedImage); } - // 여러 이미지 업로드 + // 여러 이미지 정보 저장 @PostMapping("/multiple") public ResponseEntity> saveMultipleImages(@RequestBody List imageRequests) { List savedImages = imageService.saveMultipleImages(imageRequests); diff --git a/src/main/java/poomasi/global/config/s3/S3PresignedUrlService.java b/src/main/java/poomasi/global/config/s3/S3PresignedUrlService.java index bb10e3f..12330c8 100644 --- a/src/main/java/poomasi/global/config/s3/S3PresignedUrlService.java +++ b/src/main/java/poomasi/global/config/s3/S3PresignedUrlService.java @@ -16,6 +16,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Map; +import java.util.UUID; @Service @RequiredArgsConstructor @@ -52,9 +53,10 @@ public String createPresignedPutUrl(String bucketName, String keyPrefix, Map 일단 보류 + // 극악의 확률로 url이 겹치면?? -> 그럴일 거의 없긴할텐데 생기면 s3 원래 파일 지워짐 - String keyName = String.format("%s/%s/%s.jpg", keyPrefix, date, encodedTime); + String uniqueIdentifier = UUID.randomUUID().toString(); + String keyName = String.format("%s/%s/%s_%s.jpg", keyPrefix, date, uniqueIdentifier, encodedTime); PutObjectRequest objectRequest = PutObjectRequest.builder() .bucket(bucketName) diff --git a/src/main/java/poomasi/global/util/EncryptionUtil.java b/src/main/java/poomasi/global/util/EncryptionUtil.java index 9ddd6c4..7681228 100644 --- a/src/main/java/poomasi/global/util/EncryptionUtil.java +++ b/src/main/java/poomasi/global/util/EncryptionUtil.java @@ -8,15 +8,13 @@ import java.security.MessageDigest; import java.time.LocalDateTime; import java.util.Base64; -import java.util.UUID; @Component public class EncryptionUtil { public String encodeTime(LocalDateTime time) { try { - String uniqueSuffix = UUID.randomUUID().toString(); // 추가 요소 - String timeString = time.toString() + uniqueSuffix; + String timeString = time.toString(); byte[] hash = MessageDigest.getInstance("SHA-256") .digest(timeString.getBytes(StandardCharsets.UTF_8)); return Base64.getUrlEncoder().withoutPadding().encodeToString(hash);