feat(subtitle): 업로드와 BOT 콜백 및 자막 응답을 연동한다
This commit is contained in:
@@ -43,15 +43,20 @@ import kr.co.vividnext.sodalive.utils.generateFileName
|
||||
import kr.co.vividnext.sodalive.v2.creatorname.application.CreatorLocalizedNameService
|
||||
import kr.co.vividnext.sodalive.v2.home.following.application.HomeFollowingNewsPublishService
|
||||
import kr.co.vividnext.sodalive.v2.recommendation.application.CreatorContentViewHistoryService
|
||||
import kr.co.vividnext.sodalive.v2.subtitle.application.SubtitleJobService
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.cache.annotation.Cacheable
|
||||
import org.springframework.context.ApplicationEventPublisher
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.PlatformTransactionManager
|
||||
import org.springframework.transaction.TransactionDefinition
|
||||
import org.springframework.transaction.annotation.Propagation
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.transaction.support.TransactionSynchronization
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
import org.springframework.transaction.support.TransactionTemplate
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
import java.text.SimpleDateFormat
|
||||
import java.time.LocalDateTime
|
||||
@@ -93,6 +98,8 @@ class AudioContentService(
|
||||
private val contentThemeTranslationRepository: ContentThemeTranslationRepository,
|
||||
private val homeFollowingNewsPublishService: HomeFollowingNewsPublishService,
|
||||
private val memberContentPreferenceService: MemberContentPreferenceService,
|
||||
private val subtitleJobService: SubtitleJobService,
|
||||
transactionManager: PlatformTransactionManager,
|
||||
|
||||
@Value("\${cloud.aws.s3.content-bucket}")
|
||||
private val audioContentBucket: String,
|
||||
@@ -104,6 +111,9 @@ class AudioContentService(
|
||||
private val coverImageHost: String
|
||||
) {
|
||||
private val log = LoggerFactory.getLogger(javaClass)
|
||||
private val registrationTransaction = TransactionTemplate(transactionManager).apply {
|
||||
propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun audioContentLike(request: PutAudioContentLikeRequest, member: Member): PutAudioContentLikeResponse {
|
||||
@@ -220,7 +230,7 @@ class AudioContentService(
|
||||
pinContent?.isActive = false
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
fun createAudioContent(
|
||||
contentFile: MultipartFile?,
|
||||
coverImage: MultipartFile?,
|
||||
@@ -245,7 +255,7 @@ class AudioContentService(
|
||||
return createAudioContent(contentFile, coverImage, request, releaseDate, member)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
fun createAudioContent(
|
||||
contentFile: MultipartFile?,
|
||||
coverImage: MultipartFile?,
|
||||
@@ -260,115 +270,118 @@ class AudioContentService(
|
||||
throw SodaException(messageKey = "content.error.content_required")
|
||||
}
|
||||
|
||||
validatePreviewTime(request.previewStartTime, request.previewEndTime)
|
||||
val registration = requireNotNull(
|
||||
registrationTransaction.execute {
|
||||
validatePreviewTime(request.previewStartTime, request.previewEndTime)
|
||||
|
||||
// 테마 체크
|
||||
val theme = themeQueryRepository.findThemeByIdAndActive(id = request.themeId)
|
||||
?: throw SodaException(messageKey = "content.error.invalid_theme")
|
||||
// 테마 체크
|
||||
val theme = themeQueryRepository.findThemeByIdAndActive(id = request.themeId)
|
||||
?: throw SodaException(messageKey = "content.error.invalid_theme")
|
||||
|
||||
if ((request.themeId == 12L || request.themeId == 13L || request.themeId == 14L) && request.price < 5) {
|
||||
throw SodaException(messageKey = "content.error.alarm_theme_price_min")
|
||||
}
|
||||
if ((request.themeId == 12L || request.themeId == 13L || request.themeId == 14L) && request.price < 5) {
|
||||
throw SodaException(messageKey = "content.error.alarm_theme_price_min")
|
||||
}
|
||||
|
||||
if (request.price in 1..4) throw SodaException(messageKey = "content.error.minimum_price")
|
||||
if (request.price in 1..4) throw SodaException(messageKey = "content.error.minimum_price")
|
||||
|
||||
val isFullDetailVisible = if (request.price >= 50) {
|
||||
request.isFullDetailVisible
|
||||
} else {
|
||||
true
|
||||
}
|
||||
val isFullDetailVisible = if (request.price >= 50) {
|
||||
request.isFullDetailVisible
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
||||
val purchaseOption = if (request.themeId == 12L || request.themeId == 13L || request.themeId == 14L) {
|
||||
PurchaseOption.BUY_ONLY
|
||||
} else {
|
||||
request.purchaseOption
|
||||
}
|
||||
val purchaseOption = if (request.themeId == 12L || request.themeId == 13L || request.themeId == 14L) {
|
||||
PurchaseOption.BUY_ONLY
|
||||
} else {
|
||||
request.purchaseOption
|
||||
}
|
||||
|
||||
val isOnlyRental = if (
|
||||
(request.limited != null && request.limited > 0) ||
|
||||
purchaseOption == PurchaseOption.BUY_ONLY
|
||||
) {
|
||||
false
|
||||
} else if (request.purchaseOption == PurchaseOption.RENT_ONLY) {
|
||||
true
|
||||
} else {
|
||||
request.isOnlyRental
|
||||
}
|
||||
val isOnlyRental = if (
|
||||
(request.limited != null && request.limited > 0) ||
|
||||
purchaseOption == PurchaseOption.BUY_ONLY
|
||||
) {
|
||||
false
|
||||
} else if (request.purchaseOption == PurchaseOption.RENT_ONLY) {
|
||||
true
|
||||
} else {
|
||||
request.isOnlyRental
|
||||
}
|
||||
|
||||
// DB에 값 추가
|
||||
val audioContent = AudioContent(
|
||||
title = request.title.trim(),
|
||||
detail = request.detail.trim(),
|
||||
languageCode = request.languageCode,
|
||||
price = if (request.price > 0) {
|
||||
request.price
|
||||
} else {
|
||||
0
|
||||
},
|
||||
releaseDate = releaseDate,
|
||||
limited = request.limited,
|
||||
remaining = request.limited,
|
||||
isAdult = request.isAdult,
|
||||
purchaseOption = purchaseOption,
|
||||
isGeneratePreview = request.isGeneratePreview,
|
||||
isOnlyRental = isOnlyRental,
|
||||
isPointAvailable = request.isPointAvailable,
|
||||
isCommentAvailable = request.isCommentAvailable,
|
||||
isFullDetailVisible = isFullDetailVisible
|
||||
)
|
||||
audioContent.theme = theme
|
||||
audioContent.member = member
|
||||
repository.save(audioContent)
|
||||
|
||||
// 태그 분리, #추가, 등록
|
||||
if (request.tags.isNotBlank()) {
|
||||
val tags = request.tags
|
||||
.replace("#", " #")
|
||||
.split(" ")
|
||||
.asSequence()
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotBlank() }
|
||||
.map {
|
||||
val tag = if (!it.startsWith("#")) {
|
||||
"#$it"
|
||||
// DB에 값 추가
|
||||
val audioContent = AudioContent(
|
||||
title = request.title.trim(),
|
||||
detail = request.detail.trim(),
|
||||
languageCode = request.languageCode,
|
||||
price = if (request.price > 0) {
|
||||
request.price
|
||||
} else {
|
||||
it
|
||||
}
|
||||
0
|
||||
},
|
||||
releaseDate = releaseDate,
|
||||
limited = request.limited,
|
||||
remaining = request.limited,
|
||||
isAdult = request.isAdult,
|
||||
purchaseOption = purchaseOption,
|
||||
isGeneratePreview = request.isGeneratePreview,
|
||||
isOnlyRental = isOnlyRental,
|
||||
isPointAvailable = request.isPointAvailable,
|
||||
isCommentAvailable = request.isCommentAvailable,
|
||||
isFullDetailVisible = isFullDetailVisible
|
||||
)
|
||||
audioContent.theme = theme
|
||||
audioContent.member = member
|
||||
repository.save(audioContent)
|
||||
|
||||
val hashTag = hashTagRepository.findByTag(tag)
|
||||
?: hashTagRepository.save(HashTag(tag))
|
||||
// 태그 분리, #추가, 등록
|
||||
if (request.tags.isNotBlank()) {
|
||||
val tags = request.tags
|
||||
.replace("#", " #")
|
||||
.split(" ")
|
||||
.asSequence()
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotBlank() }
|
||||
.map {
|
||||
val tag = if (!it.startsWith("#")) {
|
||||
"#$it"
|
||||
} else {
|
||||
it
|
||||
}
|
||||
|
||||
val audioContentHashTag = AudioContentHashTag()
|
||||
audioContentHashTag.audioContent = audioContent
|
||||
audioContentHashTag.hashTag = hashTag
|
||||
val hashTag = hashTagRepository.findByTag(tag)
|
||||
?: hashTagRepository.save(HashTag(tag))
|
||||
|
||||
audioContentHashTag
|
||||
}.toList()
|
||||
val audioContentHashTag = AudioContentHashTag()
|
||||
audioContentHashTag.audioContent = audioContent
|
||||
audioContentHashTag.hashTag = hashTag
|
||||
|
||||
audioContent.audioContentHashTags.addAll(tags)
|
||||
}
|
||||
audioContentHashTag
|
||||
}.toList()
|
||||
|
||||
var metadata = ObjectMetadata()
|
||||
metadata.contentLength = coverImage.size
|
||||
audioContent.audioContentHashTags.addAll(tags)
|
||||
}
|
||||
|
||||
// 커버 이미지 파일명 생성
|
||||
val coverImageFileName = generateFileName(prefix = "${audioContent.id}-cover")
|
||||
val metadata = ObjectMetadata()
|
||||
metadata.contentLength = coverImage.size
|
||||
|
||||
// 커버 이미지 업로드
|
||||
val coverImagePath = s3Uploader.upload(
|
||||
inputStream = coverImage.inputStream,
|
||||
bucket = coverImageBucket,
|
||||
filePath = "audio_content_cover/${audioContent.id}/$coverImageFileName",
|
||||
metadata = metadata
|
||||
// 커버 이미지 파일명 생성
|
||||
val coverImageFileName = generateFileName(prefix = "${audioContent.id}-cover")
|
||||
|
||||
// 커버 이미지 업로드
|
||||
val coverImagePath = s3Uploader.upload(
|
||||
inputStream = coverImage.inputStream,
|
||||
bucket = coverImageBucket,
|
||||
filePath = "audio_content_cover/${audioContent.id}/$coverImageFileName",
|
||||
metadata = metadata
|
||||
)
|
||||
|
||||
audioContent.coverImage = coverImagePath
|
||||
audioContent to subtitleJobService.register(audioContent, contentFile.originalFilename)
|
||||
}
|
||||
)
|
||||
|
||||
audioContent.coverImage = coverImagePath
|
||||
|
||||
// 콘텐츠 파일명 생성
|
||||
val contentFileName = generateFileName(prefix = "${audioContent.id}-content")
|
||||
val (audioContent, subtitleJob) = registration
|
||||
|
||||
// 콘텐츠 파일 업로드
|
||||
metadata = ObjectMetadata()
|
||||
val metadata = ObjectMetadata()
|
||||
metadata.contentLength = contentFile.size
|
||||
metadata.addUserMetadata(
|
||||
"generate_preview",
|
||||
@@ -384,38 +397,45 @@ class AudioContentService(
|
||||
metadata.addUserMetadata("preview_end_time", request.previewEndTime)
|
||||
}
|
||||
|
||||
val contentPath = s3Uploader.upload(
|
||||
inputStream = contentFile.inputStream,
|
||||
bucket = audioContentBucket,
|
||||
filePath = "input/${audioContent.id}/$contentFileName",
|
||||
metadata = metadata
|
||||
)
|
||||
|
||||
audioContent.content = contentPath
|
||||
|
||||
// 언어 코드가 지정되지 않은 경우, 파파고 언어 감지 API를 통해 비동기로 언어를 식별한다.
|
||||
if (audioContent.languageCode.isNullOrBlank()) {
|
||||
val papagoQuery = listOf(
|
||||
request.title.trim(),
|
||||
request.detail.trim(),
|
||||
request.tags.trim()
|
||||
)
|
||||
.filter { it.isNotBlank() }
|
||||
.joinToString(" ")
|
||||
|
||||
applicationEventPublisher.publishEvent(
|
||||
LanguageDetectEvent(
|
||||
id = audioContent.id!!,
|
||||
query = papagoQuery
|
||||
try {
|
||||
contentFile.inputStream.use { inputStream ->
|
||||
s3Uploader.upload(
|
||||
inputStream = inputStream,
|
||||
bucket = audioContentBucket,
|
||||
filePath = subtitleJob.sourceKey,
|
||||
metadata = metadata
|
||||
)
|
||||
)
|
||||
} else {
|
||||
applicationEventPublisher.publishEvent(
|
||||
LanguageTranslationEvent(
|
||||
id = audioContent.id!!,
|
||||
targetType = LanguageTranslationTargetType.CONTENT
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
subtitleJobService.recordUploadError(subtitleJob.jobId)
|
||||
throw exception
|
||||
}
|
||||
|
||||
registrationTransaction.executeWithoutResult {
|
||||
// 언어 코드가 지정되지 않은 경우, 파파고 언어 감지 API를 통해 비동기로 언어를 식별한다.
|
||||
if (audioContent.languageCode.isNullOrBlank()) {
|
||||
val papagoQuery = listOf(
|
||||
request.title.trim(),
|
||||
request.detail.trim(),
|
||||
request.tags.trim()
|
||||
)
|
||||
)
|
||||
.filter { it.isNotBlank() }
|
||||
.joinToString(" ")
|
||||
|
||||
applicationEventPublisher.publishEvent(
|
||||
LanguageDetectEvent(
|
||||
id = audioContent.id!!,
|
||||
query = papagoQuery
|
||||
)
|
||||
)
|
||||
} else {
|
||||
applicationEventPublisher.publishEvent(
|
||||
LanguageTranslationEvent(
|
||||
id = audioContent.id!!,
|
||||
targetType = LanguageTranslationTargetType.CONTENT
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return CreateAudioContentResponse(contentId = audioContent.id!!)
|
||||
@@ -481,8 +501,9 @@ class AudioContentService(
|
||||
|
||||
@Transactional
|
||||
fun uploadComplete(contentId: Long, content: String, duration: String) {
|
||||
val keyFileName = content.split("/").last()
|
||||
if (!keyFileName.startsWith(contentId.toString())) throw SodaException(messageKey = "common.error.invalid_request")
|
||||
val registeredOutputMatches = subtitleJobService.matchesOutput(contentId, content)
|
||||
val validOutput = registeredOutputMatches ?: content.substringAfterLast("/").startsWith(contentId.toString())
|
||||
if (!validOutput) throw SodaException(messageKey = "common.error.invalid_request")
|
||||
|
||||
val audioContent = repository.findByIdOrNull(contentId)
|
||||
?: throw SodaException(messageKey = "common.error.invalid_request")
|
||||
@@ -978,7 +999,19 @@ class AudioContentService(
|
||||
nextContent = nextContent,
|
||||
buyerList = buyerList,
|
||||
isAvailableUsePoint = audioContent.isPointAvailable && audioContent.price > 0,
|
||||
translated = translated
|
||||
translated = translated,
|
||||
subtitle = if (
|
||||
(isExistsAudioContent || creatorId == member.id || audioContent.price <= 0) &&
|
||||
(audioContent.releaseDate == null || audioContent.releaseDate!! <= LocalDateTime.now() || creatorId == member.id)
|
||||
) {
|
||||
subtitleJobService.subtitle(
|
||||
audioContent,
|
||||
langContext.lang,
|
||||
1000 * 60 * 60 * ((audioContent.duration ?: "00:00:00").split(":")[0].toLong() + 2)
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1302,16 +1335,25 @@ class AudioContentService(
|
||||
contentId = audioContent.id!!
|
||||
)
|
||||
|
||||
val contentUrl = if (isExistsAudioContent) {
|
||||
audioContentCloudFront.generateSignedURL(
|
||||
resourcePath = audioContent.content!!,
|
||||
expirationTime = 1000 * 60 * 60 * (audioContent.duration!!.split(":")[0].toLong() + 2)
|
||||
return if (isExistsAudioContent) {
|
||||
val expirationTime = 1000 * 60 * 60 * (audioContent.duration!!.split(":")[0].toLong() + 2)
|
||||
GenerateUrlResponse(
|
||||
contentUrl = audioContentCloudFront.generateSignedURL(
|
||||
resourcePath = audioContent.content!!,
|
||||
expirationTime = expirationTime
|
||||
),
|
||||
subtitle = if (
|
||||
audioContent.releaseDate == null || audioContent.releaseDate!! <= LocalDateTime.now() ||
|
||||
audioContent.member!!.id == member.id
|
||||
) {
|
||||
subtitleJobService.subtitle(audioContent, langContext.lang, expirationTime)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
)
|
||||
} else {
|
||||
""
|
||||
GenerateUrlResponse("")
|
||||
}
|
||||
|
||||
return GenerateUrlResponse(contentUrl)
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
|
||||
Reference in New Issue
Block a user