parent
f13c221fd6
commit
a8da17162a
|
@ -70,6 +70,9 @@ dependencies {
|
||||||
implementation("org.apache.poi:poi-ooxml:5.2.3")
|
implementation("org.apache.poi:poi-ooxml:5.2.3")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
|
||||||
|
|
||||||
|
// file mimetype check
|
||||||
|
implementation("org.apache.tika:tika-core:3.2.0")
|
||||||
|
|
||||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
runtimeOnly("com.h2database:h2")
|
runtimeOnly("com.h2database:h2")
|
||||||
runtimeOnly("com.mysql:mysql-connector-j")
|
runtimeOnly("com.mysql:mysql-connector-j")
|
||||||
|
|
|
@ -21,6 +21,7 @@ import kr.co.vividnext.sodalive.fcm.FcmEventType
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||||
import kr.co.vividnext.sodalive.utils.generateFileName
|
import kr.co.vividnext.sodalive.utils.generateFileName
|
||||||
|
import kr.co.vividnext.sodalive.utils.validateImage
|
||||||
import org.springframework.beans.factory.annotation.Value
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.context.ApplicationEventPublisher
|
import org.springframework.context.ApplicationEventPublisher
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
|
@ -71,6 +72,8 @@ class CreatorCommunityService(
|
||||||
throw SodaException("오디오 등록을 위해서는 이미지가 필요합니다.")
|
throw SodaException("오디오 등록을 위해서는 이미지가 필요합니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postImage?.let { validateImage(it, request.price > 0) }
|
||||||
|
|
||||||
val post = CreatorCommunity(
|
val post = CreatorCommunity(
|
||||||
content = request.content,
|
content = request.content,
|
||||||
price = request.price,
|
price = request.price,
|
||||||
|
@ -129,6 +132,8 @@ class CreatorCommunityService(
|
||||||
val post = repository.findByIdAndMemberId(id = request.creatorCommunityId, memberId = member.id!!)
|
val post = repository.findByIdAndMemberId(id = request.creatorCommunityId, memberId = member.id!!)
|
||||||
?: throw SodaException("잘못된 요청입니다.")
|
?: throw SodaException("잘못된 요청입니다.")
|
||||||
|
|
||||||
|
postImage?.let { validateImage(it, post.price > 0) }
|
||||||
|
|
||||||
if (request.content != null) {
|
if (request.content != null) {
|
||||||
post.content = request.content
|
post.content = request.content
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package kr.co.vividnext.sodalive.utils
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.common.SodaException
|
||||||
|
import org.apache.tika.Tika
|
||||||
|
import org.springframework.web.multipart.MultipartFile
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 이미지 파일인지 확인하고,
|
||||||
|
* GIF의 경우 외부 조건(gifAllowed)에 따라 허용 여부 판단
|
||||||
|
*/
|
||||||
|
fun validateImage(file: MultipartFile, gifAllowed: Boolean) {
|
||||||
|
val mimeType = Tika().detect(file.bytes)
|
||||||
|
|
||||||
|
if (!mimeType.startsWith("image/")) {
|
||||||
|
throw SodaException("이미지 파일만 업로드할 수 있습니다.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mimeType == "image/gif" && !gifAllowed) {
|
||||||
|
throw SodaException("GIF 파일은 유료 게시물만 업로드 할 수 있습니다.")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue