INNER CODE UNIT · TypeScript

getOgImage

Hash-Studios/Prism · infra/cloudflare/worker/src/index.ts:249

async function getOgImage(pathname: string, method: string, env: Env): Promise<Response> {
  const codePart = pathname.replace('/og/', '').trim();
  if (!codePart.endsWith('.png')) {
    return new Response('Not found', { status: 404 });
  }

  const code = codePart.replace('.png', '').trim();
  if (!SHORT_CODE_REGEX.test(code)) {
    return new Response('Invalid code', { status: 400 });
  }

  const record = await readLinkRecord(code, env);
  if (record == null) {
    return new Response('Not found', { status: 404 });
  }

  const fromStorage = await fetchOgImageFromStorage(code, record, env);
  if (fromStorage != null) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…