var-proxy/src/module/get-content-type.ts
2024-10-07 22:52:51 +08:00

20 lines
539 B
TypeScript

import path from 'path';
// 获取文件的 content-type
export const getContentType = (filePath: string) => {
const extname = path.extname(filePath);
const contentType = {
'.txt': 'text/plain',
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.wav': 'audio/wav',
'.mp4': 'video/mp4',
};
return contentType[extname] || 'application/octet-stream';
};