Spaces:
Sleeping
Sleeping
File size: 1,689 Bytes
a5d1c1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import path from 'node:path';
export const MIME_MAP: Record<string, string> = {
'.md': 'text/markdown',
'.markdown': 'text/markdown',
'.mdx': 'text/markdown',
'.ts': 'text/typescript',
'.tsx': 'text/typescript',
'.mts': 'text/typescript',
'.cts': 'text/typescript',
'.js': 'text/javascript',
'.jsx': 'text/javascript',
'.mjs': 'text/javascript',
'.cjs': 'text/javascript',
'.json': 'application/json',
'.json5': 'application/json',
'.jsonc': 'application/json',
'.py': 'text/x-python',
'.pyi': 'text/x-python',
'.rs': 'text/x-rust',
'.go': 'text/x-go',
'.html': 'text/html',
'.htm': 'text/html',
'.css': 'text/css',
'.scss': 'text/css',
'.sass': 'text/css',
'.less': 'text/css',
'.yaml': 'text/yaml',
'.yml': 'text/yaml',
'.toml': 'text/x-toml',
'.xml': 'application/xml',
'.sh': 'text/x-shellscript',
'.bash': 'text/x-shellscript',
'.zsh': 'text/x-shellscript',
'.ps1': 'text/x-shellscript',
'.txt': 'text/plain',
'.sql': 'text/x-sql',
'.graphql': 'text/plain',
'.gql': 'text/plain',
'.prisma': 'text/plain',
};
const EXACT_FILE_MIME_MAP: Record<string, string> = {
'LICENSE': 'text/plain',
'LICENSE.md': 'text/markdown',
'LICENSE.txt': 'text/plain',
'Makefile': 'text/plain',
'Dockerfile': 'text/plain',
'Containerfile': 'text/plain',
'.env.example': 'text/plain',
};
export function resolveMimeType(filePath: string): string {
const baseName = path.basename(filePath);
if (EXACT_FILE_MIME_MAP[baseName]) {
return EXACT_FILE_MIME_MAP[baseName];
}
const ext = path.extname(filePath).toLowerCase();
if (ext && MIME_MAP[ext]) {
return MIME_MAP[ext];
}
return 'text/plain';
}
|