fix: clear commands after entering

This commit is contained in:
2025-01-17 16:54:53 +01:00
parent 6e82d9ca73
commit 6112d007c2
5 changed files with 28 additions and 21 deletions

View File

@ -61,11 +61,17 @@ function parseParams(reqUrl: URL): ImageParams | string {
return "Invalid parameters provided.";
}
}
// Helper function to generate ETag
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("")
}"`;
}
const GET = async (
req: Request,
_ctx: FreshContext,
): Promise<Response> => {
async function GET(req: Request, _ctx: FreshContext): Promise<Response> {
try {
const url = new URL(req.url);
const params = parseParams(url);
@ -85,9 +91,16 @@ const GET = async (
const image = await getImageContent(imageUrl, params);
// Generate ETag based on image content
const eTag = await generateETag(image.content);
// Set caching headers
return new Response(image.content, {
headers: {
"Content-Type": image.mimeType,
"Cache-Control": "public, max-age=31536000, immutable", // Cache for 1 year
"ETag": eTag,
"Last-Modified": new Date().toUTCString(), // Replace with image's actual modified date if available
},
});
} catch (error) {
@ -97,7 +110,7 @@ const GET = async (
headers: { "Content-Type": "text/plain" },
});
}
};
}
export const handler: Handlers = {
GET,