#!/usr/bin/env node const sqlite3 = require('sqlite3').verbose(); const fs = require('fs'); const path = require('path'); // Connect to the database const dbPath = '/app/data/photo_sharing.db'; console.log(`Connecting to database at: ${dbPath}`); const db = new sqlite3.Database(dbPath, sqlite3.OPEN_READONLY, (err) => { if (err) { console.error('Error opening database:', err.message); process.exit(1); } console.log('Connected to the SQLite database.\n'); }); // Query for photos with IDs 1688 and 1689 where event_id = 12 const query = ` SELECT p.id, p.filename, p.path, p.thumbnail_path, p.event_id, e.slug as event_slug, e.is_active, e.is_archived FROM photos p JOIN events e ON p.event_id = e.id WHERE p.id IN (1688, 1689) AND p.event_id = 12 `; console.log('Executing query to get photo details with event information...\n'); db.all(query, [], (err, rows) => { if (err) { console.error('Error executing query:', err.message); db.close(); process.exit(1); } console.log(`Found ${rows.length} photo(s):\n`); if (rows.length === 0) { console.log('No photos found matching the criteria.'); } else { rows.forEach((row) => { console.log('=== Photo ID:', row.id, '==='); console.log('Filename:', row.filename); console.log('DB Path:', row.path); console.log('DB Thumbnail Path:', row.thumbnail_path); console.log('Event ID:', row.event_id); console.log('Event Slug:', row.event_slug); console.log('Event is_active:', row.is_active); console.log('Event is_archived:', row.is_archived); // Check file existence const storageBase = '/app/storage'; const eventStatusDir = row.is_active ? 'active' : 'archived'; // Check full image path const fullImagePath1 = path.join(storageBase, row.path); const fullImagePath2 = path.join(storageBase, 'events', eventStatusDir, row.path); console.log('\nChecking full image paths:'); console.log(` Path 1: ${fullImagePath1} - ${fs.existsSync(fullImagePath1) ? 'EXISTS' : 'NOT FOUND'}`); console.log(` Path 2: ${fullImagePath2} - ${fs.existsSync(fullImagePath2) ? 'EXISTS' : 'NOT FOUND'}`); // Check thumbnail path const thumbnailPath = path.join(storageBase, row.thumbnail_path); console.log('\nChecking thumbnail path:'); console.log(` ${thumbnailPath} - ${fs.existsSync(thumbnailPath) ? 'EXISTS' : 'NOT FOUND'}`); console.log('\n---\n'); }); } // Close the database connection db.close((err) => { if (err) { console.error('Error closing database:', err.message); } else { console.log('Database connection closed.'); } }); });