()
| 13 | import { generateIllustration } from '../services/illustration-generator.js'; |
| 14 | |
| 15 | async function main() { |
| 16 | const dbConfig = getDatabaseConfig(); |
| 17 | if (!dbConfig) { |
| 18 | console.error('DATABASE_URL is required'); |
| 19 | process.exit(1); |
| 20 | } |
| 21 | if (!process.env.GEMINI_API_KEY) { |
| 22 | console.error('GEMINI_API_KEY is required'); |
| 23 | process.exit(1); |
| 24 | } |
| 25 | |
| 26 | initializeDatabase(dbConfig); |
| 27 | const pool = getPool(); |
| 28 | |
| 29 | try { |
| 30 | // Find published perspectives without an illustration |
| 31 | const { rows } = await pool.query<{ |
| 32 | id: string; |
| 33 | slug: string; |
| 34 | title: string; |
| 35 | category: string | null; |
| 36 | excerpt: string | null; |
| 37 | }>( |
| 38 | `SELECT id, slug, title, category, excerpt |
| 39 | FROM perspectives |
| 40 | WHERE status = 'published' AND illustration_id IS NULL |
| 41 | ORDER BY published_at DESC` |
| 42 | ); |
| 43 | |
| 44 | if (rows.length === 0) { |
| 45 | console.log('All published perspectives already have illustrations.'); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | console.log(`Found ${rows.length} perspectives without illustrations:\n`); |
| 50 | for (const p of rows) { |
| 51 | console.log(` - ${p.title} (${p.slug})`); |
| 52 | } |
| 53 | console.log(); |
| 54 | |
| 55 | for (const perspective of rows) { |
| 56 | console.log(`Generating illustration for: ${perspective.title}`); |
| 57 | |
| 58 | try { |
| 59 | const { imageBuffer, promptUsed, c2pa } = await generateIllustration({ |
| 60 | title: perspective.title, |
| 61 | category: perspective.category || undefined, |
| 62 | excerpt: perspective.excerpt || undefined, |
| 63 | }); |
| 64 | |
| 65 | const illustration = await illustrationDb.createIllustration({ |
| 66 | perspective_id: perspective.id, |
| 67 | image_data: imageBuffer, |
| 68 | prompt_used: promptUsed, |
| 69 | status: 'generated', |
| 70 | c2pa_signed_at: c2pa?.signedAt, |
| 71 | c2pa_manifest_digest: c2pa?.manifestDigest, |
| 72 | }); |
no test coverage detected