Skip to content

Commit

Permalink
Merge pull request #31 from YAPP-Github/feature/#30
Browse files Browse the repository at this point in the history
fix: ํ•˜๋ฃจํ•„๋ฆ„ QR ์‚ฌ์ง„ ์ €์žฅ ๋„๋ฉ”์ธ ํ˜•์‹ ์˜ค๋ฅ˜ ์ˆ˜์ •
  • Loading branch information
gmkim20713 authored Jul 13, 2024
2 parents db2b913 + 15b6fe1 commit 53c770b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
23 changes: 11 additions & 12 deletions photo-service/src/main/java/kr/mafoo/photo/domain/BrandType.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -30,3 +28,4 @@ public static BrandType matchBrandType(String qrUrl) {
return null;
}
}

20 changes: 11 additions & 9 deletions photo-service/src/main/java/kr/mafoo/photo/service/QrService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,19 @@ private Mono<byte[]> getLifeFourCutsFiles(String qrUrl) {
private Mono<byte[]> 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<String, Object> content = (LinkedHashMap<String, Object>) responseBody.get("content");
LinkedHashMap<String, Object> fileInfo = (LinkedHashMap<String, Object>) content.get("fileInfo");
LinkedHashMap<String, Object> picFile = (LinkedHashMap<String, Object>) fileInfo.get("picFile");
String imageUrl = (String) picFile.get("path");
String imageUrl = (String) fileInfo.get("picFile.path");

return getFileAsByte(imageUrl);
});
Expand All @@ -79,11 +78,14 @@ private Mono<byte[]> getPhotoismFiles(String qrUrl) {
}

private Mono<byte[]> 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";

Expand All @@ -92,7 +94,7 @@ private Mono<byte[]> getHaruFilmFiles(String qrUrl) {
}

private Mono<byte[]> 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;
Expand Down Expand Up @@ -130,8 +132,8 @@ private Mono<String> 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<byte[]> getFileAsByte(String url) {
Expand Down

0 comments on commit 53c770b

Please sign in to comment.