feat(chat-character-image): 캐릭터 이미지

- 등록, 리스트, 상세, 트리거 단어 업데이트, 삭제 기능 추가
This commit is contained in:
2025-08-21 03:33:42 +09:00
parent ca27903e45
commit dd6849b840
9 changed files with 431 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package kr.co.vividnext.sodalive.aws.cloudfront
import com.amazonaws.services.cloudfront.CloudFrontUrlSigner
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import java.nio.file.Files
import java.nio.file.Paths
import java.security.KeyFactory
import java.security.PrivateKey
import java.security.spec.PKCS8EncodedKeySpec
import java.util.Date
/**
* 이미지(CloudFront) 서명 URL 생성기
* - cloud.aws.cloud-front.* 설정을 사용
*/
@Component
class ImageContentCloudFront(
@Value("\${cloud.aws.cloud-front.host}")
private val cloudfrontDomain: String,
@Value("\${cloud.aws.cloud-front.private-key-file-path}")
private val privateKeyFilePath: String,
@Value("\${cloud.aws.cloud-front.key-pair-id}")
private val keyPairId: String
) {
fun generateSignedURL(
resourcePath: String,
expirationTimeMillis: Long
): String {
val privateKey = loadPrivateKey(privateKeyFilePath)
return CloudFrontUrlSigner.getSignedURLWithCannedPolicy(
"$cloudfrontDomain/$resourcePath",
keyPairId,
privateKey,
Date(System.currentTimeMillis() + expirationTimeMillis)
)
}
private fun loadPrivateKey(resourceName: String): PrivateKey {
val path = Paths.get(resourceName)
val bytes = Files.readAllBytes(path)
val keySpec = PKCS8EncodedKeySpec(bytes)
val keyFactory = KeyFactory.getInstance("RSA")
return keyFactory.generatePrivate(keySpec)
}
}