-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from YAPP-Github/feature/MAFOO-26
[MAFOO-26] feat: 포토그레이 벤더 추가 및 벤더별 Parser 함수 나누기
- Loading branch information
Showing
10 changed files
with
273 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
photo-service/src/main/java/kr/mafoo/photo/service/vendors/DontLookUpQrVendor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<byte[]> 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) | ||
); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
photo-service/src/main/java/kr/mafoo/photo/service/vendors/HaruFilmQrVendor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<byte[]> 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()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
photo-service/src/main/java/kr/mafoo/photo/service/vendors/LifeFourCutsQrVendor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<byte[]> 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()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
photo-service/src/main/java/kr/mafoo/photo/service/vendors/MyFourCutQrVendor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 MyFourCutQrVendor implements QrVendor { | ||
private final WebClient webClient; | ||
|
||
@Override | ||
public Mono<byte[]> extractImageFromQrUrl(String qrUrl) { | ||
return WebClientUtil | ||
.getBlob(webClient, qrUrl) //just image url | ||
.onErrorMap(e -> new PhotoQrUrlExpiredException()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoGrayQrVendor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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; | ||
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<byte[]> 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 | ||
.onErrorMap(e -> new PhotoQrUrlExpiredException()); | ||
} | ||
|
||
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(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
photo-service/src/main/java/kr/mafoo/photo/service/vendors/PhotoismQrVendor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<byte[]> 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<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"); | ||
|
||
return WebClientUtil.getBlob(webClient, imageUrl); | ||
}); | ||
}) | ||
.onErrorMap(e -> { | ||
e.printStackTrace(); | ||
return new PhotoQrUrlExpiredException(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.