feat: refactor whole bunch of stuff

This commit is contained in:
Max Richter
2025-11-02 19:03:11 +01:00
parent 81ebc8f5e0
commit e6b90cb785
56 changed files with 753 additions and 360 deletions

View File

@@ -63,8 +63,8 @@ function parseParams(reqUrl: URL): ImageParams | string {
async function generateETag(content: ArrayBuffer): Promise<string> {
const hashBuffer = await crypto.subtle.digest("SHA-256", content);
return `"${Array.from(new Uint8Array(hashBuffer))
.map((b) => b.toString(16).padStart(2, "0"))
.join("")
.map((b) => b.toString(16).padStart(2, "0"))
.join("")
}"`;
}
@@ -80,13 +80,9 @@ async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
});
}
const imageUrl = params.image.startsWith("resources")
? `https://marka.max-richter.dev/${params.image.replace(/^\//, "")}`
: params.image;
log.debug("Processing image request:", { params });
log.debug("Processing image request:", { imageUrl, params });
const image = await getImageContent(imageUrl, params);
const image = await getImageContent(params.image, params);
// Generate ETag based on image content
const eTag = await generateETag(image.content);