INNER CODE UNIT · TypeScript
generateAndPersistOgImage
Hash-Studios/Prism · infra/cloudflare/worker/src/index.ts:725
async function generateAndPersistOgImage(code: string, record: LinkRecord, env: Env): Promise<OgStorageType | null> {
const pngBytes = await renderOgImageWithBrowserRendering(code, record, env);
if (pngBytes == null) {
return null;
}
const objectKey = ogObjectKey(code, record.version);
if (env.OG_IMAGES != null) {
await env.OG_IMAGES.put(objectKey, pngBytes, {
httpMetadata: {
contentType: 'image/png',
cacheControl: 'public, max-age=31536000, immutable',
},
});
return 'r2';
}
const kvPayload = toBase64(pngBytes);