From b6e3b848d92406eaf5019b448e2561c1de759a1a Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 19 Oct 2024 17:58:18 +0900 Subject: [PATCH 1/5] feat: implement acl setting method for object storage service --- .../kr/mafoo/photo/service/ObjectStorageService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java b/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java index 2049e400..a5c4cd15 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java @@ -74,4 +74,14 @@ private URL generatePresignedUrl(String fileName, String memberId) { .withExpiration(expiration)); } + public Mono setObjectPublicRead(String filePath) { + return Mono.fromRunnable(() -> { + try { + amazonS3Client.setObjectAcl(bucketName, filePath, CannedAccessControlList.PublicRead); + } catch (Exception e) { + throw new RuntimeException("Failed to set ACL to PublicRead for the file: " + filePath, e); + } + }); + } + } \ No newline at end of file From 7360576ed378c595f2a5d0dc5fbcc9757780e595 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 19 Oct 2024 17:59:44 +0900 Subject: [PATCH 2/5] feat: attach acl setting logic in createNewPhotoFileUrl --- .../src/main/java/kr/mafoo/photo/service/PhotoService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java index f42bc65c..e73091f4 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java @@ -49,8 +49,8 @@ public Mono createNewPhotoByQrUrl(String qrUrl, String requestMembe @Transactional public Flux createNewPhotoFileUrl(String[] fileUrls, String requestMemberId) { return Flux.fromArray(fileUrls) - .flatMap(fileUrl -> - this.createNewPhoto(fileUrl, BrandType.EXTERNAL, requestMemberId) + .flatMap(fileUrl -> objectStorageService.setObjectPublicRead(fileUrl) + .then(createNewPhoto(fileUrl, BrandType.EXTERNAL, requestMemberId)) ); } From 3f5332aee7f99c040d7d68145d339b079183244f Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 19 Oct 2024 18:00:25 +0900 Subject: [PATCH 3/5] fix: fix duplicating lines in createNewPhotoByQrUrl --- .../src/main/java/kr/mafoo/photo/service/PhotoService.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java index e73091f4..960dbe9c 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java @@ -38,11 +38,7 @@ public Mono createNewPhotoByQrUrl(String qrUrl, String requestMembe return qrService .getFileFromQrUrl(qrUrl) .flatMap(fileDto -> objectStorageService.uploadFile(fileDto.fileByte()) - .flatMap(photoUrl -> { - this.createNewPhoto(photoUrl, fileDto.type(), requestMemberId); - PhotoEntity photoEntity = PhotoEntity.newPhoto(IdGenerator.generate(), photoUrl, fileDto.type(), requestMemberId); - return photoRepository.save(photoEntity); - }) + .flatMap(photoUrl -> createNewPhoto(photoUrl, fileDto.type(), requestMemberId)) ); } From 68a8f6efef2bec405fae354b845abe8647534ee0 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 19 Oct 2024 18:09:08 +0900 Subject: [PATCH 4/5] fix: fix object storage error code typo --- .../src/main/java/kr/mafoo/photo/exception/ErrorCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/exception/ErrorCode.java b/photo-service/src/main/java/kr/mafoo/photo/exception/ErrorCode.java index 2b3c256f..8105a0d5 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/exception/ErrorCode.java +++ b/photo-service/src/main/java/kr/mafoo/photo/exception/ErrorCode.java @@ -18,7 +18,7 @@ public enum ErrorCode { PHOTO_DISPLAY_INDEX_IS_SAME("PE0004", "옮기려는 대상 사진 인덱스가 같습니다"), PHOTO_DISPLAY_INDEX_NOT_VALID("PE0005", "옮기려는 대상 사진 인덱스가 유효하지 않습니다"), - PRE_SIGNED_URL_EXCEED_MAXIMUM("OE0005", "한 번에 생성할 수 있는 Pre-signed url 최대치를 초과했습니다"), + PRE_SIGNED_URL_EXCEED_MAXIMUM("OE0001", "한 번에 생성할 수 있는 Pre-signed url 최대치를 초과했습니다"), ; private final String code; From 07563721bcfbcb911fd9dd9d9b82de51387873ce Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Sat, 19 Oct 2024 18:09:52 +0900 Subject: [PATCH 5/5] refactor: add message for uploadFile runtime exception --- .../main/java/kr/mafoo/photo/service/ObjectStorageService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java b/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java index a5c4cd15..44b53761 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.java @@ -48,7 +48,7 @@ public Mono uploadFile(byte[] fileByte) { return "https://kr.object.ncloudstorage.com/" + bucketName + "/" + keyName; } catch (Exception e) { - throw new RuntimeException(e); + throw new RuntimeException("Failed to upload image to object storage: ", e); } }); }