From d575dae98a183104cb30b206c554836d23eba82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=EC=98=81=EB=AF=BC?= Date: Wed, 24 Jul 2024 14:41:46 +0900 Subject: [PATCH 1/4] feat: add photogray brand --- photo-service/src/main/java/kr/mafoo/photo/domain/BrandType.java | 1 + 1 file changed, 1 insertion(+) diff --git a/photo-service/src/main/java/kr/mafoo/photo/domain/BrandType.java b/photo-service/src/main/java/kr/mafoo/photo/domain/BrandType.java index d78c789..d441945 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/domain/BrandType.java +++ b/photo-service/src/main/java/kr/mafoo/photo/domain/BrandType.java @@ -8,6 +8,7 @@ public enum BrandType { HARU_FILM(Pattern.compile("http://haru\\d+\\.mx\\d+\\.co\\.kr/.*")), DONT_LOOK_UP(Pattern.compile("https://x\\.dontlxxkup\\.kr/.*")), MY_FOUR_CUT(Pattern.compile("https://firebasestorage\\.googleapis\\.com:443/v0/b/my4ccu\\.appspot\\.com/.*")), + PHOTOGRAY(Pattern.compile("https://pgshort\\.aprd\\.io/.*")), ; private final Pattern urlPattern; From d0612f2f899063697d78365a3ebb68ce37601c35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=EC=98=81=EB=AF=BC?= Date: Wed, 24 Jul 2024 15:07:41 +0900 Subject: [PATCH 2/4] feat: implement photogray brand --- .../kr/mafoo/photo/service/QrService.java | 18 ++++--- .../service/vendors/PhotoGrayQrVendor.java | 48 +++++++++++++++++++ .../mafoo/photo/service/vendors/QrVendor.java | 7 +++ .../kr/mafoo/photo/util/WebClientUtil.java | 35 ++++++++++++++ 4 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/vendors/QrVendor.java create mode 100644 photo-service/src/main/java/kr/mafoo/photo/util/WebClientUtil.java diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java b/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java index 30baaae..16721f0 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java @@ -5,6 +5,7 @@ import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; import kr.mafoo.photo.exception.RedirectUriNotFoundException; import kr.mafoo.photo.service.dto.FileDto; +import kr.mafoo.photo.service.vendors.PhotoGrayQrVendor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; @@ -24,17 +25,22 @@ public class QrService { private final WebClient externalWebClient; + private final PhotoGrayQrVendor photoGrayQrVendor; + public Mono getFileFromQrUrl(String qrUrl) { BrandType brandType = Optional.ofNullable(BrandType.matchBrandType(qrUrl)) .orElseThrow(PhotoBrandNotExistsException::new); - return switch (brandType) { - case LIFE_FOUR_CUTS -> createFileDto(brandType, getLifeFourCutsFiles(qrUrl)); - case PHOTOISM -> createFileDto(brandType, getPhotoismFiles(qrUrl)); - case HARU_FILM -> createFileDto(brandType, getHaruFilmFiles(qrUrl)); - case DONT_LOOK_UP -> createFileDto(brandType, getDontLookUpFiles(qrUrl)); - case MY_FOUR_CUT -> createFileDto(brandType, getMyFourCutFiles(qrUrl)); + Mono imagePublisher = switch (brandType) { + case LIFE_FOUR_CUTS -> getLifeFourCutsFiles(qrUrl); + case PHOTOISM -> getPhotoismFiles(qrUrl); + case HARU_FILM -> getHaruFilmFiles(qrUrl); + case DONT_LOOK_UP -> getDontLookUpFiles(qrUrl); + case MY_FOUR_CUT -> getMyFourCutFiles(qrUrl); + case PHOTOGRAY -> photoGrayQrVendor.extractImageFromQrUrl(qrUrl); }; + + return createFileDto(brandType, imagePublisher); } private Mono createFileDto(BrandType brandType, Mono fileMono) { diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java new file mode 100644 index 0000000..a2fbb67 --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java @@ -0,0 +1,48 @@ +package kr.mafoo.photo.service.vendors; + +import kr.mafoo.photo.util.WebClientUtil; +import lombok.RequiredArgsConstructor; +import org.apache.http.client.utils.URLEncodedUtils; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.util.UriComponentsBuilder; +import reactor.core.publisher.Mono; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; + +@RequiredArgsConstructor +@Component +public class PhotoGrayQrVendor implements QrVendor { + private final WebClient webClient; + + @Override + public Mono extractImageFromQrUrl(String qrUrl) { + return WebClientUtil // https://pgshort.aprd.io/{qr} + .getRedirectUri(webClient, qrUrl) //https://photogray-download.aprd.io?id={base64} + .flatMap((currentUrl) -> { + String encodedStr = extractIdFromUrl(currentUrl); + String decodedStr = new String(Base64.getDecoder().decode(encodedStr)); + String sessionId = extractSessionIdFromQueryString(decodedStr); + String imageUrl = String.format("https://pg-qr-resource.aprd.io/%s/image.jpg", sessionId); + return WebClientUtil.getBlob(webClient, imageUrl); + }); //https://pg-qr-resource.aprd.io/{sessionId}/image.jpg + } + + private String extractIdFromUrl(String url) { + return UriComponentsBuilder + .fromUriString(url) + .build() + .getQueryParams() + .getFirst("id"); + } + + private String extractSessionIdFromQueryString(String queryString) { + return URLEncodedUtils.parse(queryString, StandardCharsets.UTF_8) + .stream() + .filter(e -> e.getName().equals("sessionId")) + .findFirst() + .orElseThrow() + .getValue(); + } +} diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/QrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/QrVendor.java new file mode 100644 index 0000000..451bc14 --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/QrVendor.java @@ -0,0 +1,7 @@ +package kr.mafoo.photo.service.vendors; + +import reactor.core.publisher.Mono; + +public interface QrVendor { + Mono extractImageFromQrUrl(String qrUrl); +} diff --git a/photo-service/src/main/java/kr/mafoo/photo/util/WebClientUtil.java b/photo-service/src/main/java/kr/mafoo/photo/util/WebClientUtil.java new file mode 100644 index 0000000..69ed12b --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/util/WebClientUtil.java @@ -0,0 +1,35 @@ +package kr.mafoo.photo.util; + +import kr.mafoo.photo.exception.RedirectUriNotFoundException; +import org.springframework.http.MediaType; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.net.URI; + +public class WebClientUtil { + public static Mono getRedirectUri(WebClient client, String url) { + return client + .get() + .uri(url) + .retrieve() + .toBodilessEntity() + .flatMap(response -> { + URI redirectUri = response.getHeaders().getLocation(); + if (redirectUri == null) { + return Mono.error(new RedirectUriNotFoundException()); + } else { + return Mono.just(redirectUri.toString()); + } + }); + } + + public static Mono getBlob(WebClient client, String url) { + return client + .get() + .uri(url) + .accept(MediaType.APPLICATION_OCTET_STREAM) + .retrieve() + .bodyToMono(byte[].class); + } +} From 8df0aee8b3dc0ea4c031ebf149e9a548909b47f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=EC=98=81=EB=AF=BC?= Date: Wed, 24 Jul 2024 15:17:12 +0900 Subject: [PATCH 3/4] refactor: move vendor logics to seperate classes --- .../kr/mafoo/photo/service/QrService.java | 147 ++---------------- .../service/vendors/DontLookUpQrVendor.java | 39 +++++ .../service/vendors/HaruFilmQrVendor.java | 29 ++++ .../service/vendors/LifeFourCutsQrVendor.java | 28 ++++ .../service/vendors/MyFourCutQrVendor.java | 18 +++ .../service/vendors/PhotoismQrVendor.java | 46 ++++++ 6 files changed, 175 insertions(+), 132 deletions(-) create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/vendors/DontLookUpQrVendor.java create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/vendors/HaruFilmQrVendor.java create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/vendors/LifeFourCutsQrVendor.java create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoismQrVendor.java diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java b/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java index 16721f0..2e22074 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/QrService.java @@ -2,20 +2,12 @@ import kr.mafoo.photo.domain.BrandType; import kr.mafoo.photo.exception.PhotoBrandNotExistsException; -import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; -import kr.mafoo.photo.exception.RedirectUriNotFoundException; import kr.mafoo.photo.service.dto.FileDto; -import kr.mafoo.photo.service.vendors.PhotoGrayQrVendor; +import kr.mafoo.photo.service.vendors.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.MediaType; import org.springframework.stereotype.Service; -import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; - -import java.net.URI; -import java.util.LinkedHashMap; -import java.util.Map; import java.util.Optional; @Slf4j @@ -23,140 +15,31 @@ @Service public class QrService { - private final WebClient externalWebClient; - + private final LifeFourCutsQrVendor lifeFourCutsQrVendor; + private final PhotoismQrVendor photoismQrVendor; + private final DontLookUpQrVendor dontLookUpQrVendor; + private final HaruFilmQrVendor haruFilmQrVendor; + private final MyFourCutQrVendor myFourCutQrVendor; private final PhotoGrayQrVendor photoGrayQrVendor; + public Mono getFileFromQrUrl(String qrUrl) { BrandType brandType = Optional.ofNullable(BrandType.matchBrandType(qrUrl)) .orElseThrow(PhotoBrandNotExistsException::new); - Mono imagePublisher = switch (brandType) { - case LIFE_FOUR_CUTS -> getLifeFourCutsFiles(qrUrl); - case PHOTOISM -> getPhotoismFiles(qrUrl); - case HARU_FILM -> getHaruFilmFiles(qrUrl); - case DONT_LOOK_UP -> getDontLookUpFiles(qrUrl); - case MY_FOUR_CUT -> getMyFourCutFiles(qrUrl); - case PHOTOGRAY -> photoGrayQrVendor.extractImageFromQrUrl(qrUrl); + QrVendor qrVendor = switch (brandType) { + case LIFE_FOUR_CUTS -> lifeFourCutsQrVendor; + case PHOTOISM -> photoismQrVendor; + case HARU_FILM -> haruFilmQrVendor; + case DONT_LOOK_UP -> dontLookUpQrVendor; + case MY_FOUR_CUT -> myFourCutQrVendor; + case PHOTOGRAY -> photoGrayQrVendor; }; - return createFileDto(brandType, imagePublisher); + return createFileDto(brandType, qrVendor.extractImageFromQrUrl(qrUrl)); } private Mono createFileDto(BrandType brandType, Mono fileMono) { return fileMono.map(file -> new FileDto(brandType, file)); } - - private Mono getLifeFourCutsFiles(String qrUrl) { - - return getRedirectUri(qrUrl) - .flatMap(redirectUri -> { - String imageUrl = extractValueFromUrl(redirectUri, "path=")[1].replace("index.html", "image.jpg"); - - // TODO : 추후 비디오 URL 추가 예정 - // String videoUrl = redirectUri.toString().replace("index.html", "video.mp4"); - - return getFileAsByte(imageUrl); - }) - .onErrorMap(e -> new PhotoQrUrlExpiredException()); - } - - private Mono getPhotoismFiles(String qrUrl) { - return getRedirectUri(qrUrl) - .flatMap(redirectUri -> { - String uid = extractValueFromUrl(redirectUri, "u=")[1]; - - return externalWebClient - .post() - .uri("https://cmsapi.seobuk.kr/v1/etc/seq/resource") - .contentType(MediaType.APPLICATION_JSON) - .bodyValue(Map.of("uid", uid)) - .retrieve() - .bodyToMono(LinkedHashMap.class) - .flatMap(responseBody -> { - LinkedHashMap content = (LinkedHashMap) responseBody.get("content"); - LinkedHashMap fileInfo = (LinkedHashMap) content.get("fileInfo"); - LinkedHashMap picFile = (LinkedHashMap) fileInfo.get("picFile"); - String imageUrl = (String) picFile.get("path"); - - return getFileAsByte(imageUrl); - }); - }) - .onErrorMap(e -> { - e.printStackTrace(); - return new PhotoQrUrlExpiredException(); - }); - } - - private Mono getHaruFilmFiles(String qrUrl) { - String[] urlValueList = extractValueFromUrl(qrUrl, "/@"); - String albumCode = urlValueList[1]; - - String baseUrl = urlValueList[0] + "/base_api?command=albumdn&albumCode="; - String imageUrl = baseUrl + albumCode + "&type=photo&file_name=output.jpg&max=10&limit=+24 hours"; - - // TODO : 추후 비디오 URL 추가 예정 - // String videoUrl = baseUrl + albumCode + "&type=video&max=10&limit=+24 hours"; - - return getFileAsByte(imageUrl) - .onErrorMap(e -> new PhotoQrUrlExpiredException()); - } - - private Mono getDontLookUpFiles(String qrUrl) { - String imageName = extractValueFromUrl(qrUrl, ".kr/image/")[1]; - - String baseUrl = "https://x.dontlxxkup.kr/uploads/"; - String imageUrl = baseUrl + imageName; - - // TODO : 추후 비디오 URL 추가 예정 - // String videoName = imageName.replace("image", "video").replace(".jpg", ".mp4"); - // String videoUrl = baseUrl + videoName; - - return getRedirectUri(qrUrl) - .flatMap(redirectUri -> { - if (redirectUri.endsWith("/delete")) { - return Mono.error(new PhotoQrUrlExpiredException()); - } else { - return getFileAsByte(imageUrl); - } - }) - .onErrorResume( - RedirectUriNotFoundException.class, e -> getFileAsByte(imageUrl) - ); - } - - private Mono getMyFourCutFiles(String qrUrl) { - return getFileAsByte(qrUrl); - } - - private Mono getRedirectUri(String url) { - return externalWebClient - .get() - .uri(url) - .retrieve() - .toBodilessEntity() - .flatMap(response -> { - URI redirectUri = response.getHeaders().getLocation(); - if (redirectUri == null) { - return Mono.error(new RedirectUriNotFoundException()); - } else { - return Mono.just(redirectUri.toString()); - } - }); - } - - private String[] extractValueFromUrl(String url, String delimiter) { - return url.split(delimiter); - } - - private Mono getFileAsByte(String url) { - return externalWebClient - .get() - .uri(url) - .accept(MediaType.APPLICATION_OCTET_STREAM) - .retrieve() - .bodyToMono(byte[].class); - } - - } diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/DontLookUpQrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/DontLookUpQrVendor.java new file mode 100644 index 0000000..db3a31f --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/DontLookUpQrVendor.java @@ -0,0 +1,39 @@ +package kr.mafoo.photo.service.vendors; + +import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; +import kr.mafoo.photo.exception.RedirectUriNotFoundException; +import kr.mafoo.photo.util.WebClientUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +@Component +public class DontLookUpQrVendor implements QrVendor { + private final WebClient webClient; + + @Override + public Mono extractImageFromQrUrl(String qrUrl) { + String imageName = qrUrl.split(".kr/image/")[1]; + + String baseUrl = "https://x.dontlxxkup.kr/uploads/"; + String imageUrl = baseUrl + imageName; + + // TODO : 추후 비디오 URL 추가 예정 + // String videoName = imageName.replace("image", "video").replace(".jpg", ".mp4"); + // String videoUrl = baseUrl + videoName; + + return WebClientUtil.getRedirectUri(webClient, qrUrl) + .flatMap(redirectUri -> { + if (redirectUri.endsWith("/delete")) { + return Mono.error(new PhotoQrUrlExpiredException()); + } else { + return WebClientUtil.getBlob(webClient, imageUrl); + } + }) + .onErrorResume( + RedirectUriNotFoundException.class, e -> WebClientUtil.getBlob(webClient, imageUrl) + ); + } +} diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/HaruFilmQrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/HaruFilmQrVendor.java new file mode 100644 index 0000000..242f524 --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/HaruFilmQrVendor.java @@ -0,0 +1,29 @@ +package kr.mafoo.photo.service.vendors; + +import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; +import kr.mafoo.photo.util.WebClientUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +@Component +public class HaruFilmQrVendor implements QrVendor { + private final WebClient webClient; + + @Override + public Mono extractImageFromQrUrl(String qrUrl) { + String[] urlValueList = qrUrl.split("/@"); + String albumCode = urlValueList[1]; + + String baseUrl = urlValueList[0] + "/base_api?command=albumdn&albumCode="; + String imageUrl = baseUrl + albumCode + "&type=photo&file_name=output.jpg&max=10&limit=+24 hours"; + + // TODO : 추후 비디오 URL 추가 예정 + // String videoUrl = baseUrl + albumCode + "&type=video&max=10&limit=+24 hours"; + + return WebClientUtil.getBlob(webClient, imageUrl) + .onErrorMap(e -> new PhotoQrUrlExpiredException()); + } +} diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/LifeFourCutsQrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/LifeFourCutsQrVendor.java new file mode 100644 index 0000000..c5c52a8 --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/LifeFourCutsQrVendor.java @@ -0,0 +1,28 @@ +package kr.mafoo.photo.service.vendors; + +import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; +import kr.mafoo.photo.util.WebClientUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +@Component +public class LifeFourCutsQrVendor implements QrVendor { + private final WebClient webClient; + + @Override + public Mono extractImageFromQrUrl(String qrUrl) { + return WebClientUtil.getRedirectUri(webClient, qrUrl) + .flatMap(redirectUri -> { + String imageUrl = redirectUri.split("path=")[1].replace("index.html", "image.jpg"); + + // TODO : 추후 비디오 URL 추가 예정 + // String videoUrl = redirectUri.toString().replace("index.html", "video.mp4"); + + return WebClientUtil.getBlob(webClient, imageUrl); + }) + .onErrorMap(e -> new PhotoQrUrlExpiredException()); + } +} diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java new file mode 100644 index 0000000..882e895 --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java @@ -0,0 +1,18 @@ +package kr.mafoo.photo.service.vendors; + +import kr.mafoo.photo.util.WebClientUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +@Component +public class MyFourCutQrVendor implements QrVendor { + private final WebClient webClient; + + @Override + public Mono extractImageFromQrUrl(String qrUrl) { + return WebClientUtil.getBlob(webClient, qrUrl); //just image url + } +} diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoismQrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoismQrVendor.java new file mode 100644 index 0000000..c909aff --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoismQrVendor.java @@ -0,0 +1,46 @@ +package kr.mafoo.photo.service.vendors; + +import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; +import kr.mafoo.photo.util.WebClientUtil; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.LinkedHashMap; +import java.util.Map; + +@RequiredArgsConstructor +@Component +public class PhotoismQrVendor implements QrVendor { + private final WebClient webClient; + + @Override + public Mono extractImageFromQrUrl(String qrUrl) { + return WebClientUtil.getRedirectUri(webClient, qrUrl) + .flatMap(redirectUri -> { + String uid = redirectUri.split("u=")[1]; + + return webClient + .post() + .uri("https://cmsapi.seobuk.kr/v1/etc/seq/resource") + .contentType(MediaType.APPLICATION_JSON) + .bodyValue(Map.of("uid", uid)) + .retrieve() + .bodyToMono(LinkedHashMap.class) + .flatMap(responseBody -> { + LinkedHashMap content = (LinkedHashMap) responseBody.get("content"); + LinkedHashMap fileInfo = (LinkedHashMap) content.get("fileInfo"); + LinkedHashMap picFile = (LinkedHashMap) fileInfo.get("picFile"); + String imageUrl = (String) picFile.get("path"); + + return WebClientUtil.getBlob(webClient, imageUrl); + }); + }) + .onErrorMap(e -> { + e.printStackTrace(); + return new PhotoQrUrlExpiredException(); + }); + } +} From 55134f4bcfeda516b66318f11891a0e3baabf043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=EC=98=81=EB=AF=BC?= Date: Wed, 24 Jul 2024 15:24:03 +0900 Subject: [PATCH 4/4] feat: add error handling --- .../kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java | 5 ++++- .../kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java index 882e895..7b6a651 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java @@ -1,5 +1,6 @@ package kr.mafoo.photo.service.vendors; +import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; import kr.mafoo.photo.util.WebClientUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -13,6 +14,8 @@ public class MyFourCutQrVendor implements QrVendor { @Override public Mono extractImageFromQrUrl(String qrUrl) { - return WebClientUtil.getBlob(webClient, qrUrl); //just image url + return WebClientUtil + .getBlob(webClient, qrUrl) //just image url + .onErrorMap(e -> new PhotoQrUrlExpiredException()); } } diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java index a2fbb67..af87e6b 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java @@ -1,5 +1,6 @@ package kr.mafoo.photo.service.vendors; +import kr.mafoo.photo.exception.PhotoQrUrlExpiredException; import kr.mafoo.photo.util.WebClientUtil; import lombok.RequiredArgsConstructor; import org.apache.http.client.utils.URLEncodedUtils; @@ -26,7 +27,8 @@ public Mono extractImageFromQrUrl(String qrUrl) { String sessionId = extractSessionIdFromQueryString(decodedStr); String imageUrl = String.format("https://pg-qr-resource.aprd.io/%s/image.jpg", sessionId); return WebClientUtil.getBlob(webClient, imageUrl); - }); //https://pg-qr-resource.aprd.io/{sessionId}/image.jpg + }) //https://pg-qr-resource.aprd.io/{sessionId}/image.jpg + .onErrorMap(e -> new PhotoQrUrlExpiredException()); } private String extractIdFromUrl(String url) {