package kr.lunaticbum.back.lun.utils

import org.apache.tomcat.util.http.fileupload.FileUploadException
import java.util.*


val EXTENSIONS_IMAGE = Arrays.asList("bmp", "gif", "jpg", "png", "jpeg")
val EXTENSIONS_VIDEO = Arrays.asList("mp4", "avi", "mov", "mpg", "wmv", "mpeg")

private fun validateFileExtension(fileName: String) {
    var fileName = fileName
    fileName = getFileExtension(fileName.lowercase(Locale.getDefault())) ?: ""
    if (EXTENSIONS_IMAGE.contains(fileName) || EXTENSIONS_VIDEO.contains(fileName)) {
        return
    }
    throw FileUploadException("유효하지않은 파일 형식입니다.")
}
fun getFileExtension(filename: String?): String? {
    if (filename == null) {
        return null
    }
    val dotIndex = filename.lastIndexOf(".")
    if (dotIndex >= 0) {
        return filename.substring(dotIndex + 1)
    }
    return ""
}