feat: 커뮤니티 글 등록/수정
- 유료 글에서만 gif를 등록할 수 있도록 수정
This commit is contained in:
@@ -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 파일은 유료 게시물만 업로드 할 수 있습니다.")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user