Vectrum
Sign In
19 lines · 640 Bytes · TypeScript
export const IMAGE_TYPES: Record<string, string> = {
  png: "image/png",
  jpg: "image/jpeg",
  jpeg: "image/jpeg",
  gif: "image/gif",
  webp: "image/webp",
  avif: "image/avif",
  ico: "image/x-icon",
  svg: "image/svg+xml",
  bmp: "image/bmp",
};

export function contentTypeFor(filename: string, binary: boolean) {
  const ext = filename.split(".").pop()?.toLowerCase() ?? "";
  if (ext in IMAGE_TYPES) return IMAGE_TYPES[ext];
  if (ext === "pdf") return "application/pdf";
  // Everything else is served as plain text so repository HTML/JS never executes.
  return binary ? "application/octet-stream" : "text/plain; charset=utf-8";
}