file.ts•582 B
import path from "path";
/**
* 根据文件路径获取 MIME 类型
* @param filePath 文件路径
*/
export function getMimeType(filePath: string): string {
const ext = path.extname(filePath).toLowerCase();
const mimeTypes: Record<string, string> = {
".md": "text/markdown",
".txt": "text/plain",
".json": "application/json",
".js": "text/javascript",
".ts": "text/typescript",
".html": "text/html",
".css": "text/css",
".xml": "text/xml",
".yaml": "text/yaml",
".yml": "text/yaml",
};
return mimeTypes[ext] || "text/plain";
}