clone

push a directory of html from the terminal and get a four-character url back. a deno cli on cloudflare

feat/source-stable-push
nzip / shared / mediatypes.ts
mediatypes.ts 1.5K
1// Extension → content-type. Resolved at push time by the CLI and stored in the2// manifest; the Worker never guesses.34const TYPES: Record<string, string> = {5 html: "text/html; charset=utf-8",6 htm: "text/html; charset=utf-8",7 css: "text/css; charset=utf-8",8 js: "text/javascript; charset=utf-8",9 mjs: "text/javascript; charset=utf-8",10 json: "application/json; charset=utf-8",11 map: "application/json; charset=utf-8",12 txt: "text/plain; charset=utf-8",13 md: "text/markdown; charset=utf-8",14 xml: "application/xml; charset=utf-8",15 svg: "image/svg+xml",16 png: "image/png",17 jpg: "image/jpeg",18 jpeg: "image/jpeg",19 gif: "image/gif",20 webp: "image/webp",21 avif: "image/avif",22 ico: "image/x-icon",23 woff: "font/woff",24 woff2: "font/woff2",25 ttf: "font/ttf",26 otf: "font/otf",27 mp3: "audio/mpeg",28 wav: "audio/wav",29 ogg: "audio/ogg",30 mp4: "video/mp4",31 webm: "video/webm",32 pdf: "application/pdf",33 wasm: "application/wasm",34 csv: "text/csv; charset=utf-8",35 webmanifest: "application/manifest+json",36};3738/**39 * Resolves the media type stored in a manifest from a file path's extension.40 *41 * @param path File path whose final extension should be inspected.42 * @returns A known media type, or `application/octet-stream` for unknown and43 * extensionless paths.44 */45export function contentTypeFor(path: string): string {46 const dot = path.lastIndexOf(".");47 const ext = dot === -1 ? "" : path.slice(dot + 1).toLowerCase();48 return TYPES[ext] ?? "application/octet-stream";49}