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 1e2e7e9..141e04e 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 @@ -1,24 +1,22 @@ package kr.mafoo.photo.domain; +import java.util.regex.Pattern; + public enum BrandType { - LIFE_FOUR_CUTS("https://api.life4cut.net/"), - PHOTOISM("https://qr.seobuk.kr/"), - HARU_FILM( "http://haru6.mx2.co.kr/"), - DONT_LOOK_UP("https://x.dontlxxkup.kr/"), + LIFE_FOUR_CUTS(Pattern.compile("https://api\\.life4cut\\.net/.*")), + PHOTOISM(Pattern.compile("https://qr\\.seobuk\\.kr/.*")), + HARU_FILM(Pattern.compile("http://haru\\d+\\.mx\\d+\\.co\\.kr/.*")), + DONT_LOOK_UP(Pattern.compile("https://x\\.dontlxxkup\\.kr/.*")), ; - private String urlFormat; - - private BrandType(String urlFormat) { - this.urlFormat = urlFormat; - } + private final Pattern urlPattern; - public String getUrlFormat() { - return urlFormat; + private BrandType(Pattern urlPattern) { + this.urlPattern = urlPattern; } public boolean matches(String qrUrl) { - return qrUrl.startsWith(this.urlFormat); + return urlPattern.matcher(qrUrl).matches(); } public static BrandType matchBrandType(String qrUrl) { @@ -30,3 +28,4 @@ public static BrandType matchBrandType(String qrUrl) { return null; } } + 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 1b6d232..54f5645 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 @@ -57,20 +57,19 @@ private Mono getLifeFourCutsFiles(String qrUrl) { private Mono getPhotoismFiles(String qrUrl) { return getRedirectUri(qrUrl) .flatMap(redirectUri -> { - String uid = extractValueFromUrl(redirectUri, "u="); + 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)) + .bodyValue(Map.of("uid", uid, "appUserId", null)) .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"); + String imageUrl = (String) fileInfo.get("picFile.path"); return getFileAsByte(imageUrl); }); @@ -79,11 +78,14 @@ private Mono getPhotoismFiles(String qrUrl) { } private Mono getHaruFilmFiles(String qrUrl) { - String albumCode = extractValueFromUrl(qrUrl, "/@"); + String[] urlValueList = extractValueFromUrl(qrUrl, "/@"); + String albumCode = urlValueList[1]; - String baseUrl = "http://haru6.mx2.co.kr/base_api?command=albumdn&albumCode="; + String baseUrl = urlValueList[0] + "/base_api?command=albumdn&albumCode="; String imageUrl = baseUrl + albumCode + "&type=photo&file_name=output.jpg&max=10&limit=+24 hours"; + log.info("이미지 url : {}", imageUrl); + // TODO : 추후 비디오 URL 추가 예정 // String videoUrl = baseUrl + albumCode + "&type=video&max=10&limit=+24 hours"; @@ -92,7 +94,7 @@ private Mono getHaruFilmFiles(String qrUrl) { } private Mono getDontLookUpFiles(String qrUrl) { - String imageName = extractValueFromUrl(qrUrl, ".kr/image/"); + String imageName = extractValueFromUrl(qrUrl, ".kr/image/")[1]; String baseUrl = "https://x.dontlxxkup.kr/uploads/"; String imageUrl = baseUrl + imageName; @@ -130,8 +132,8 @@ private Mono getRedirectUri(String url) { }); } - private String extractValueFromUrl(String url, String delimiter) { - return url.split(delimiter)[1]; + private String[] extractValueFromUrl(String url, String delimiter) { + return url.split(delimiter); } private Mono getFileAsByte(String url) {