test-enhanced-auto.js•4.17 kB
#!/usr/bin/env node
// Test the enhanced server with automatic ImageMagick detection
const EnhancedCalibreRAGServer = require('./server.js');
const fs = require('fs');
async function testEnhancedServerWithAutoDetection() {
try {
console.log('🔍 Testing Enhanced Server with Automatic ImageMagick Detection...');
// Create server instance (this will automatically detect ImageMagick)
const server = new EnhancedCalibreRAGServer();
console.log('\\n📊 Server Status:');
console.log('- Calibre DB Path:', server.calibredbPath);
console.log('- ImageMagick Available:', server.imageMagickAvailable);
if (server.imageMagickAvailable) {
console.log('✅ ImageMagick is configured and ready for OCR!');
} else {
console.log('⚠️ ImageMagick not available - will use pdf-parse only');
}
// Test book search
console.log('\\n📚 Testing book search...');
const searchResults = await server.searchBooksMetadata('title:basic', 3);
console.log(`Found ${searchResults.length} books with "basic" in title`);
if (searchResults.length > 0) {
const book = searchResults[0];
console.log('\\n📖 First book found:');
console.log('- Title:', book.title);
console.log('- Authors:', book.authors);
console.log('- ID:', book.id);
console.log('- Has text format:', book.has_text);
console.log('- Formats:', book.formats ? book.formats.length : 0);
if (book.full_formats && book.full_formats.length > 0) {
console.log('\\n📄 Available formats:');
book.full_formats.forEach((format, idx) => {
const exists = fs.existsSync(format);
const ext = require('path').extname(format).toLowerCase();
console.log(` ${idx + 1}. ${format}`);
console.log(` Extension: ${ext}, Exists: ${exists}`);
});
// Test processing this book
const mockBook = {
id: book.id,
title: book.title,
authors: book.authors,
formats: book.full_formats
};
console.log('\\n🔄 Testing book processing...');
const extractedText = await server.processBookWithOCR(mockBook);
console.log(`📝 Text extraction result: ${extractedText.length} characters`);
if (extractedText.length > 0) {
console.log('✅ Text extraction successful!');
console.log('📄 Sample text (first 200 chars):');
console.log(extractedText.substring(0, 200) + '...');
} else {
console.log('⚠️ No text extracted - may need different approach');
}
}
}
console.log('\\n🎉 Enhanced server test completed!');
// Test adding books to project
console.log('\\n🔄 Testing book addition to RAG project...');
try {
const result = await server.addBooksToProject('basic_structural', [1, 3, 4]);
console.log('📊 Project update result:');
console.log('- Processed books:', result.processed_books);
console.log('- Total chunks:', result.total_chunks);
if (result.total_chunks > 0) {
console.log('🎉 SUCCESS! Books processed and chunks created!');
} else {
console.log('⚠️ No chunks created - investigating...');
}
} catch (projectError) {
console.log('❌ Project test failed:', projectError.message);
}
} catch (error) {
console.error('❌ Enhanced server test failed:', error.message);
console.error('Stack:', error.stack);
}
}
testEnhancedServerWithAutoDetection();