Add content type to registry using filenames
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c9bd5c7d18
commit
6b88be1b18
@ -4,6 +4,7 @@ import {
|
|||||||
extractPackagePath,
|
extractPackagePath,
|
||||||
getAbsolutePackageVersion,
|
getAbsolutePackageVersion,
|
||||||
getFile,
|
getFile,
|
||||||
|
getContentType,
|
||||||
} from "../utils.ts";
|
} from "../utils.ts";
|
||||||
import db from "../db.ts";
|
import db from "../db.ts";
|
||||||
|
|
||||||
@ -54,6 +55,8 @@ export default function raw(g: ABC.Group) {
|
|||||||
if (!result) return E404();
|
if (!result) return E404();
|
||||||
|
|
||||||
ctx.response.headers.set("e-tag", result.etag);
|
ctx.response.headers.set("e-tag", result.etag);
|
||||||
|
let contentType = getContentType(filepath);
|
||||||
|
if (contentType) ctx.response.headers.set("Content-Type", contentType);
|
||||||
return result.data;
|
return result.data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ABC, Base64 } from "./deps.ts";
|
import { ABC, Base64, Path } from "./deps.ts";
|
||||||
import config from "./config.ts";
|
import config from "./config.ts";
|
||||||
|
|
||||||
const packageNameRegex = /^[@]?[a-zA-Z][\d\w\-\_]*$/g.compile();
|
const packageNameRegex = /^[@]?[a-zA-Z][\d\w\-\_]*$/g.compile();
|
||||||
@ -156,3 +156,18 @@ export async function getFile(
|
|||||||
throw err;
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user