Skip to content

Commit b823782

Browse files
committed
test
1 parent 35daaf4 commit b823782

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ export async function makeContext(pctx, req, env) {
5656
ctx.env = env;
5757
ctx.url = new URL(req.url);
5858
ctx.log = console;
59+
const filename = ctx.url.pathname.split('/').pop() ?? '';
5960
ctx.info = {
61+
filename,
6062
method: req.method.toUpperCase(),
61-
extension: ctx.url.pathname.split('.').pop(),
63+
extension: filename.split('.').pop(),
6264
headers: Object.fromEntries(
6365
[...req.headers.entries()]
6466
.map(([k, v]) => [k.toLowerCase(), v]),
6567
),
6668
};
67-
console.debug('makeContext: ', ctx.url, ctx.url.pathname);
69+
console.debug('makeContext: ', ctx.url, ctx.url.pathname, ctx.info.filename);
6870
ctx.data = await parseData(req);
6971
return ctx;
7072
}

src/routes/content/media.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ export default async function handler(ctx) {
1919
const {
2020
env,
2121
url,
22+
info,
2223
log,
2324
config: { org, site },
2425
} = ctx;
25-
log.debug('handling media: ', url.pathname, ctx.request.url);
26+
log.debug('handling media: ', url.pathname, ctx.request.url, info.filename);
2627

27-
const filename = ctx.request.url.split('/').pop();
28+
const { filename } = info;
2829
const key = `${org}/${site}/media/${filename}`;
2930
log.debug('fetching media: ', key, filename);
3031
const resp = await env.CATALOG_BUCKET.get(key);

src/types.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@ declare global {
251251
/** parsed from body or query params */
252252
data: any;
253253
info: {
254+
filename: string;
254255
method: string;
255-
extension: string;
256+
extension: string | undefined;
256257
headers: Record<string, string>;
257258
}
258259
attributes: {

0 commit comments

Comments
 (0)