import { Resvg } from '@cf-wasm/resvg/workerd'; import handler from './.open-next/worker.js'; async function rasterizeSvg(svg) { const renderer = await Resvg.async(svg); try { const image = renderer.render(); try { return image.asPng(); } finally { image.free(); } } finally { renderer.free(); } } export default { fetch(request, env, ctx) { if (env.LUMEN_DATA_PAUSED === 'true') { const { pathname } = new URL(request.url); const readOnly = request.method === 'GET' || request.method === 'HEAD'; const studioAction = pathname.startsWith('/admin/') || pathname === '/admin'; const appApi = pathname.startsWith('/api/'); if ((!readOnly && (appApi || studioAction)) || pathname.startsWith('/api/cron/')) { return new Response('The studio is updating. Try again shortly.', { status: 503, headers: { 'Cache-Control': 'no-store', 'Retry-After': '30' }, }); } } return handler.fetch(request, { ...env, rasterizeSvg }, ctx); }, async scheduled(_event, env, ctx) { // Turn this on after the previous scheduler has stopped. if (env.CLOUDFLARE_CRON_ACTIVE !== 'true' || env.LUMEN_DATA_PAUSED === 'true') return; if (!env.CRON_SECRET) throw new Error('Cart-reminder cron secret is missing'); const request = new Request('https://lumengesso.com/api/cron/cart-reminders', { headers: { Authorization: `Bearer ${env.CRON_SECRET}` }, }); const result = await handler.fetch(request, env, ctx); if (!result.ok) throw new Error(`Cart reminder returned ${result.status}`); const { considered, due, sent, failed } = await result.json(); console.info('[cart reminders] tick completed', { considered, due, sent, failed }); }, };