()
| 15 | ]; |
| 16 | |
| 17 | async function main() { |
| 18 | for (const id of IDS) { |
| 19 | const { rows } = await pool.query('SELECT title, category, excerpt FROM perspectives WHERE id = $1', [id]); |
| 20 | if (!rows[0]) { console.log(`SKIP ${id} - not found`); continue; } |
| 21 | const { title, category, excerpt } = rows[0]; |
| 22 | console.log(`Generating: ${title.slice(0, 60)}...`); |
| 23 | try { |
| 24 | const { imageBuffer, promptUsed } = await generateIllustration({ title, category, excerpt }); |
| 25 | const hex = '\\x' + imageBuffer.toString('hex'); |
| 26 | const ins = await pool.query( |
| 27 | `INSERT INTO perspective_illustrations (perspective_id, image_data, prompt_used, status, approved_at) |
| 28 | VALUES ($1, $2, $3, 'approved', NOW()) RETURNING id`, |
| 29 | [id, hex, promptUsed] |
| 30 | ); |
| 31 | const illId = ins.rows[0].id; |
| 32 | await pool.query('UPDATE perspectives SET illustration_id = $1 WHERE id = $2', [illId, id]); |
| 33 | console.log(` OK: ${illId} (${(imageBuffer.length / 1024).toFixed(0)} KB)`); |
| 34 | } catch (e: any) { |
| 35 | console.log(` FAIL: ${e.message}`); |
| 36 | } |
| 37 | } |
| 38 | await pool.end(); |
| 39 | } |
| 40 | main(); |
no test coverage detected