fix: clear commands after entering
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user