Skip to content

Commit

Permalink
✨ FEAT. webhook 복호화 기능, 응답 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaa committed May 7, 2024
1 parent 21579c9 commit 75eb8b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fairytale.tbd.domain.faceSwap.service;

import fairytale.tbd.domain.faceSwap.util.CryptoUtils;
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapRequestDto;
import fairytale.tbd.domain.faceSwap.web.dto.WebhookRequestDTO;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
Expand Down Expand Up @@ -37,6 +39,8 @@ public class FaceSwapApiServiceImpl implements FaceSwapApiService{

private final ObjectMapper objectMapper;

private final CryptoUtils cryptoUtils;

@Override
@Transactional
public Map<String, String> getFaceSwapImg(FaceSwapRequestDto.FaceSwapRequest faceSwapRequest) throws IOException{
Expand Down Expand Up @@ -135,5 +139,9 @@ public String getToken() {
throw new RuntimeException(e);
}
}

public String getSwapImageURL(WebhookRequestDTO.RequestDTO webhookRequestDTO){
return cryptoUtils.getURL(webhookRequestDTO);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import fairytale.tbd.domain.faceSwap.web.dto.WebhookRequestDTO;

@Component
public class CryptoUtils {

Expand Down Expand Up @@ -84,10 +86,10 @@ public static String generateAesEncrypt(String data, String clientId, String cli
}

// Example usage
public String getURL(String timestamp, String nonce, String msgEncrypt, String signature){
String newSignature = generateMsgSignature(clientId, timestamp, nonce, msgEncrypt);
if (signature.equals(newSignature)) {
String result = generateAesDecrypt(msgEncrypt, clientId, clientSecret);
public String getURL(WebhookRequestDTO.RequestDTO webhookRequestDTO){
String newSignature = generateMsgSignature(clientId, webhookRequestDTO.getTimestamp(), webhookRequestDTO.getNonce(), webhookRequestDTO.getDataEncrypt());
if (webhookRequestDTO.getSignature().equals(newSignature)) {
String result = generateAesDecrypt(webhookRequestDTO.getDataEncrypt(), clientId, clientSecret);
return result;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class FaceSwapRestController {
private final PhotoUploadServiceImpl photoUploadService;
private final FaceDetectApiServiceImpl faceDetectApiService;
private final FaceSwapApiServiceImpl faceSwapApiService;
private final CryptoUtils cryptoUtils;


@PostMapping("/uploadImg")
public ApiResponse<FaceDetectResponseDto> uploadImg(@LoginUser User user, @ModelAttribute MultipartFile file) throws IOException{
Expand Down Expand Up @@ -80,7 +80,11 @@ public ApiResponse<Map<String, String>> test(@RequestBody FaceSwapRequestDto.Fac
}

@PostMapping("/webhook")
public void webhook(@RequestBody WebhookRequestDTO.RequestDTO request){
public ApiResponse<String> webhook(@RequestBody WebhookRequestDTO.RequestDTO request){
LOGGER.info("request = {}", request);

String swapResult = faceSwapApiService.getSwapImageURL(request);
LOGGER.info("swapResult = {}", swapResult);
return ApiResponse.onSuccess("thank you");
}
}

0 comments on commit 75eb8b1

Please sign in to comment.