This commit is contained in:
49
packages/server/src/local/utils/mime.ts
Normal file
49
packages/server/src/local/utils/mime.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/** Lightweight MIME type lookup by file extension */
|
||||
const MIME_MAP: Record<string, string> = {
|
||||
// Documents
|
||||
'.pdf': 'application/pdf',
|
||||
'.doc': 'application/msword',
|
||||
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'.xls': 'application/vnd.ms-excel',
|
||||
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'.ppt': 'application/vnd.ms-powerpoint',
|
||||
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'.csv': 'text/csv',
|
||||
'.txt': 'text/plain',
|
||||
'.md': 'text/markdown',
|
||||
'.json': 'application/json',
|
||||
'.xml': 'application/xml',
|
||||
'.yaml': 'text/yaml',
|
||||
'.yml': 'text/yaml',
|
||||
// Images
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.gif': 'image/gif',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.webp': 'image/webp',
|
||||
'.ico': 'image/x-icon',
|
||||
// Audio/Video
|
||||
'.mp3': 'audio/mpeg',
|
||||
'.wav': 'audio/wav',
|
||||
'.mp4': 'video/mp4',
|
||||
'.webm': 'video/webm',
|
||||
// Archives
|
||||
'.zip': 'application/zip',
|
||||
'.tar': 'application/x-tar',
|
||||
'.gz': 'application/gzip',
|
||||
// Code
|
||||
'.js': 'application/javascript',
|
||||
'.ts': 'application/typescript',
|
||||
'.html': 'text/html',
|
||||
'.css': 'text/css',
|
||||
'.py': 'text/x-python',
|
||||
'.rs': 'text/x-rust',
|
||||
'.go': 'text/x-go',
|
||||
'.java': 'text/x-java-source',
|
||||
};
|
||||
|
||||
export function lookup(filename: string): string {
|
||||
const ext = filename.lastIndexOf('.') >= 0 ? filename.slice(filename.lastIndexOf('.')).toLowerCase() : '';
|
||||
return MIME_MAP[ext] ?? 'application/octet-stream';
|
||||
}
|
||||
Reference in New Issue
Block a user