Add content type to registry using filenames
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Fabian Stamm 2020-10-21 02:40:55 +02:00
parent c9bd5c7d18
commit 6b88be1b18
2 changed files with 19 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import {
extractPackagePath,
getAbsolutePackageVersion,
getFile,
getContentType,
} from "../utils.ts";
import db from "../db.ts";
@ -54,6 +55,8 @@ export default function raw(g: ABC.Group) {
if (!result) return E404();
ctx.response.headers.set("e-tag", result.etag);
let contentType = getContentType(filepath);
if (contentType) ctx.response.headers.set("Content-Type", contentType);
return result.data;
});
}

View File

@ -1,4 +1,4 @@
import { ABC, Base64 } from "./deps.ts";
import { ABC, Base64, Path } from "./deps.ts";
import config from "./config.ts";
const packageNameRegex = /^[@]?[a-zA-Z][\d\w\-\_]*$/g.compile();
@ -156,3 +156,18 @@ export async function getFile(
throw err;
}
}
const exts = new Map<string, string>();
exts.set(".js", "text/javascript");
exts.set(".mjs", "text/javascript");
exts.set(".json", "application/json");
exts.set(".jsonld", "application/ld+json");
exts.set(".css", "text/css");
exts.set(".html", "text/html");
exts.set(".htm", "text/html");
export function getContentType(filename: string) {
const ext = Path.extname(filename);
return exts.get(ext);
}