MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / main

Function main

server/src/scripts/generate-perspective-heroes.ts:15–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13import { generateIllustration } from '../services/illustration-generator.js';
14
15async 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 });

Callers 1

Calls 5

getDatabaseConfigFunction · 0.85
initializeDatabaseFunction · 0.85
getPoolFunction · 0.85
generateIllustrationFunction · 0.85
closeDatabaseFunction · 0.85

Tested by

no test coverage detected