package cn.com.capcloud.core.util;

/**
 * @CreateTime: 2021-12-28 09:55
 * @Description:
 */
public enum FileExtContentTypeTool {
    TEXT("txt", "text/plain"),
    ZIP("zip", "application/zip"),
    PDF("pdf", "application/pdf"),
    DOC("doc", "application/msword"),
    DOCX("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
    XLS("xls", "application/vnd.ms-excel"),
    XLSX("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
    CSV("csv", "text/csv"),
    PNG("png", "image/png"),
    JPG("jpg", "image/jpe"),
    JPEG("jpeg", "image/jpeg"),
    GIF("gif", "image/gif"),
    MP4("mp4", "video/mpeg4"),
    MOV("mov", "video/quicktime"),
    ;


    private String fileExt;

    private String contentType;

    FileExtContentTypeTool(String fileExt, String contentType) {
        this.fileExt = fileExt;
        this.contentType = contentType;
    }

    public String getFileExt() {
        return fileExt;
    }

    public String getContentType() {
        return contentType;
    }

    public static String getByFileExt(String fileExt) {
        if (fileExt == null) {
            return null;
        }
        for (FileExtContentTypeTool fileExtContentTypeTool : FileExtContentTypeTool.values()) {
            if (fileExt.equalsIgnoreCase(fileExtContentTypeTool.getFileExt())){
                return fileExtContentTypeTool.getContentType();
            }
        }
        return null;
    }

}
