import { SITE_URL } from '../lib/schema.js'; const BASE_URL = process.env.TEST_URL || SITE_URL; console.log(`\n🚀 Starting OG Image Verification for ${BASE_URL}\n`); const routes = [ '/de/opengraph-image', '/en/opengraph-image', '/de/blog/opengraph-image', '/de/api/og/product?slug=nay2y', '/en/api/og/product?slug=medium-voltage-cables', ]; async function verifyImage(path: string): Promise { const url = `${BASE_URL}${path}`; const start = Date.now(); try { const response = await fetch(url); const duration = Date.now() - start; console.log(`Checking ${url}...`); if (response.status !== 200) { throw new Error(`Status: ${response.status}`); } const contentType = response.headers.get('content-type'); if (!contentType?.includes('image/png')) { throw new Error(`Content-Type: ${contentType}`); } const buffer = await response.arrayBuffer(); const bytes = new Uint8Array(buffer); // PNG Signature: 89 50 4E 47 0D 0A 1A 0A if (bytes[0] !== 0x89 || bytes[1] !== 0x50 || bytes[2] !== 0x4e || bytes[3] !== 0x47) { throw new Error('Invalid PNG signature'); } if (bytes.length < 10000) { throw new Error(`Image too small (${bytes.length} bytes), likely blank`); } console.log(` ✅ OK (${bytes.length} bytes, ${duration}ms)`); return true; } catch (error: unknown) { const message = error instanceof Error ? error.message : String(error); console.error(` ❌ FAILED: ${message}`); return false; } } async function run() { let allOk = true; for (const route of routes) { const ok = await verifyImage(route); if (!ok) allOk = false; } if (allOk) { console.log('\n✨ All OG images verified successfully!\n'); process.exit(0); } else { console.error('\n⚠️ Some OG images failed verification.\n'); process.exit(1); } } run();