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 75eb8b1 commit c147371
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
23 changes: 2 additions & 21 deletions src/main/java/fairytale/tbd/domain/faceSwap/util/CryptoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import javax.crypto.spec.SecretKeySpec;
import java.util.Arrays;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

import javax.xml.bind.DatatypeConverter;

import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -64,27 +66,6 @@ public static String generateAesDecrypt(String dataEncrypt, String clientId, Str
return null;
}
}

// Encryption algorithm
public static String generateAesEncrypt(String data, String clientId, String clientSecret) {
try {
byte[] keyBytes = clientSecret.getBytes(StandardCharsets.UTF_8);
byte[] ivBytes = clientId.getBytes(StandardCharsets.UTF_8);

SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);

byte[] encryptedBytes = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));
return DatatypeConverter.printHexBinary(encryptedBytes).toLowerCase();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}

// Example usage
public String getURL(WebhookRequestDTO.RequestDTO webhookRequestDTO){
String newSignature = generateMsgSignature(clientId, webhookRequestDTO.getTimestamp(), webhookRequestDTO.getNonce(), webhookRequestDTO.getDataEncrypt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.RequiredArgsConstructor;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -80,11 +81,11 @@ public ApiResponse<Map<String, String>> test(@RequestBody FaceSwapRequestDto.Fac
}

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

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

0 comments on commit c147371

Please sign in to comment.