SPB Git

Repository Public

rebuild-public-pdfs.ts 2.5 KB 58 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Sheet8 * File             : scripts/rebuild-public-pdfs.ts9 * Module           : scripts10 * Repository       : https://git.spboucher.ai/sheet11 * Project Website  : https://sheet.spboucher.ai12 * Created          : 2026-11-1713 * Last Modified    : 2026-11-1714 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import "./_env";44import { sql } from "../src/lib/db";4546/**47 * Queues a fresh reader PDF for every published sheet that allows downloads (after a change to the PDF layout).48 * The worker renders them; the public page then offers the newest one.   tsx scripts/rebuild-public-pdfs.ts49 */50async function main() {51  const rows = await sql<{ id: string; publication_id: string; slug: string }[]>`SELECT id, publication_id, slug FROM sheets WHERE status = 'published' AND allow_download AND deleted_at IS NULL`;52  for (const r of rows) await sql`INSERT INTO export_jobs (sheet_id, publication_id, format, options, is_public) VALUES (${r.id}, ${r.publication_id}, 'pdf', ${sql.json({})}, true)`;53  await sql`SELECT pg_notify('sheet_jobs', 'export')`;54  console.log(`  ${rows.length} reader PDFs queued`);55  await sql.end();56}57main().catch((e) => { console.error(e.message); process.exit(1); });58
Files main
Menu

Theme