feat : 첨부파일 동영상 여부 확인 로직 추가
parent
9207d84b80
commit
a7d6f5f5bb
@ -0,0 +1,48 @@
|
||||
package com.worker.util.common.commEnum;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public enum FileKind {
|
||||
IMAGE(1, "jpg","jpeg","png","gif","bmp","webp","tiff","svg","heic","heif"),
|
||||
VIDEO(2, "mp4","mov","m4v","avi","mkv","wmv","webm","flv","mpeg","mpg","3gp"),
|
||||
OTHER(0);
|
||||
|
||||
private static final Map<String, FileKind> EXT_KIND = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (FileKind kind : values()) {
|
||||
for (String ext : kind.extensions) {
|
||||
EXT_KIND.put(ext, kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final int code; // 1=IMAGE, 2=VIDEO, 0=OTHER
|
||||
private final Set<String> extensions;
|
||||
|
||||
FileKind(int code, String... extensions) {
|
||||
this.code = code;
|
||||
this.extensions = Set.of(extensions);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static FileKind fromFileName(String fileNameOrPath) {
|
||||
if (fileNameOrPath == null || fileNameOrPath.isBlank()) return OTHER;
|
||||
int dot = fileNameOrPath.lastIndexOf('.');
|
||||
if (dot > -1 && dot < fileNameOrPath.length() - 1) {
|
||||
String ext = fileNameOrPath.substring(dot + 1).toLowerCase(Locale.ROOT);
|
||||
return EXT_KIND.getOrDefault(ext, OTHER);
|
||||
}
|
||||
return OTHER;
|
||||
}
|
||||
|
||||
public static int codeFromFileName(String fileNameOrPath) {
|
||||
return fromFileName(fileNameOrPath).getCode();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue