Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@sentry/cloudflare": "^10.40.0",
"algoliasearch": "^5.49.1",
"hono": "^4.12.4",
"hono": "^4.12.7",
"is-deflate": "^1.0.0",
"is-gzip": "^2.0.0",
"pako": "^2.1.0",
Expand Down
32 changes: 20 additions & 12 deletions src/routes/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,33 @@ const whitelisted = (file: string) =>
* @param ctx Request context.
*/
const handleGetLibraryVersion = async (ctx: Context) => {
// Validate params (Hono already did this, but this keeps TypeScript happy)
const params = ctx.req.param();
if (!params.library || !params.version)
throw new Error('Missing library or version param');

// Get the library
const lib = await library(ctx.req.param('library')).catch((err) => {
const lib = await library(params.library).catch((err) => {
if (err.status === 404) return;
throw err;
});
if (!lib) return notFound(ctx, 'Library');

// Get the version
const version = await libraryVersion(
lib.name,
ctx.req.param('version'),
).catch((err) => {
if (err.status === 404) return;
throw err;
});
const version = await libraryVersion(lib.name, params.version).catch(
(err) => {
if (err.status === 404) return;
throw err;
},
);
if (!version) return notFound(ctx, 'Version');

// Generate the initial filtered response (without SRI data)
const requestedFields = queryCheck(ctx.req.queries('fields'));
const response: LibraryVersionResponse = filter(
{
name: lib.name,
version: ctx.req.param('version'),
version: params.version,
rawFiles: version,
files: version.filter(whitelisted),
},
Expand All @@ -69,11 +73,11 @@ const handleGetLibraryVersion = async (ctx: Context) => {
// Get SRI for version
const latestSriData = await libraryVersionSri(
lib.name,
ctx.req.param('version'),
params.version,
).catch(() => ({}));
response.sri = sriForVersion(
lib.name,
ctx.req.param('version'),
params.version,
version,
latestSriData,
);
Expand All @@ -93,8 +97,12 @@ const handleGetLibraryVersion = async (ctx: Context) => {
* @param ctx Request context.
*/
const handleGetLibrary = async (ctx: Context) => {
// Validate params (Hono already did this, but this keeps TypeScript happy)
const params = ctx.req.param();
if (!params.library) throw new Error('Missing library or version param');

// Get the library
const lib = await library(ctx.req.param('library')).catch((err) => {
const lib = await library(params.library).catch((err) => {
if (err.status === 404) return;
throw err;
});
Expand Down