#!/usr/bin/env node /** * Check which of the 34 public documents are missing PDFs */ require('dotenv').config(); const { connect, close } = require('../src/utils/db.util'); const Document = require('../src/models/Document.model'); const fs = require('fs').promises; const path = require('path'); const PUBLIC_CATEGORIES = [ 'getting-started', 'technical-reference', 'research-theory', 'advanced-topics', 'case-studies', 'business-leadership', 'archives' ]; async function main() { await connect(); const { MongoClient } = require('mongodb'); const mongoose = require('mongoose'); const { getCollection } = require('../src/utils/db.util'); const collection = await getCollection('documents'); const docs = await collection.find({ category: { $in: PUBLIC_CATEGORIES } }).sort({ category: 1, order: 1 }).toArray(); console.log('\n' + '='.repeat(70)); console.log('PDF AVAILABILITY CHECK - 34 Public Documents'); console.log('='.repeat(70) + '\n'); const pdfDir = '/home/theflow/projects/tractatus/public/downloads'; let missingCount = 0; let presentCount = 0; const missing = []; for (const doc of docs) { const slug = doc.slug; const pdfPath = path.join(pdfDir, `${slug}.pdf`); try { await fs.access(pdfPath); presentCount++; // console.log(`āœ… ${doc.title}`); } catch (err) { missingCount++; missing.push({ title: doc.title, slug, category: doc.category }); console.log(`āŒ MISSING PDF: ${doc.title}`); console.log(` slug: ${slug}`); console.log(` category: ${doc.category}`); console.log(); } } console.log('='.repeat(70)); console.log(`\nšŸ“Š Summary:`); console.log(` āœ… PDFs present: ${presentCount}/${docs.length}`); console.log(` āŒ PDFs missing: ${missingCount}/${docs.length}`); if (missing.length > 0) { console.log(`\nšŸ“‹ Missing PDFs by category:`); const byCategory = {}; missing.forEach(m => { if (!byCategory[m.category]) byCategory[m.category] = []; byCategory[m.category].push(m); }); Object.keys(byCategory).forEach(cat => { console.log(`\n ${cat}: ${byCategory[cat].length} missing`); byCategory[cat].forEach(m => { console.log(` - ${m.slug}`); }); }); } console.log('\n' + '='.repeat(70) + '\n'); await close(); } main();