/** * @copyright NHCarrigan * @license Naomi's Public License * @author Naomi Carrigan */ import { extname } from "node:path"; /** * MIME type mapping for file extensions. */ /* eslint-disable @typescript-eslint/naming-convention -- File extensions */ /* eslint-disable stylistic/key-spacing -- Alignment for readability */ const mimeTypes: Record = { ".7z": "application/x-7z-compressed", ".aac": "audio/aac", ".avi": "video/x-msvideo", ".bmp": "image/bmp", ".css": "text/css", ".csv": "text/csv", ".doc": "application/msword", ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", ".eot": "application/vnd.ms-fontobject", ".flac": "audio/flac", ".gif": "image/gif", ".gz": "application/gzip", ".htm": "text/html", ".html": "text/html", ".ico": "image/x-icon", ".jpeg": "image/jpeg", ".jpg": "image/jpeg", ".js": "text/javascript", ".json": "application/json", ".md": "text/markdown", ".mkv": "video/x-matroska", ".mov": "video/quicktime", ".mp3": "audio/mpeg", ".mp4": "video/mp4", ".ogg": "audio/ogg", ".otf": "font/otf", ".pdf": "application/pdf", ".png": "image/png", ".ppt": "application/vnd.ms-powerpoint", ".pptx": // eslint-disable-next-line stylistic/max-len -- Big boi string. "application/vnd.openxmlformats-officedocument.presentationml.presentation", ".rar": "application/x-rar-compressed", ".svg": "image/svg+xml", ".tar": "application/x-tar", ".tif": "image/tiff", ".tiff": "image/tiff", ".ttf": "font/ttf", ".txt": "text/plain", ".wav": "audio/wav", ".webm": "video/webm", ".webp": "image/webp", ".woff": "font/woff", ".woff2": "font/woff2", ".xls": "application/vnd.ms-excel", ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ".xml": "application/xml", ".zip": "application/zip", }; /* eslint-enable @typescript-eslint/naming-convention -- File extensions */ /* eslint-enable stylistic/key-spacing -- Alignment for readability */ /** * Gets the MIME type for a file based on its extension. * @param filePath - The file name or path. * @returns The MIME type, or undefined if unknown. */ export const getMimeType = (filePath: string): string | undefined => { const extension = extname(filePath).toLowerCase(); return mimeTypes[extension]; };