navidocs/server/check-doc-status.js
ggq-admin d461c5742f Fix search, add PDF text selection, clean duplicates, implement auto-fill
This commit addresses multiple critical fixes and adds new functionality
for the NaviDocs local testing environment (port 8083):

Search Fixes:
- Fixed search to use backend /api/search instead of direct Meilisearch
- Resolves network accessibility issue when accessing from external IPs
- Search now works from http://172.29.75.55:8083/search

PDF Text Selection:
- Added PDF.js text layer for selectable text
- Imported pdf_viewer.css for proper text layer styling
- Changed text layer opacity to 1 for better interaction
- Added user-select: text for improved text selection
- Pink selection highlight (rgba(255, 92, 178, 0.3))

Database Cleanup:
- Created cleanup scripts to remove 20 duplicate documents
- Removed 753 orphaned entries from Meilisearch index
- Cleaned 17 document folders from filesystem
- Kept only newest version of each document
- Scripts: clean-duplicates.js, clean-meilisearch-orphans.js

Auto-Fill Feature:
- New /api/upload/quick-ocr endpoint for first-page OCR
- Automatically extracts metadata from PDFs on file selection
- Detects: boat make, model, year, name, and document title
- Checks both OCR text and filename for boat name
- Auto-fills upload form with extracted data
- Shows loading indicator during metadata extraction
- Graceful fallback to filename if OCR fails

Tenant Management:
- Updated organization ID to use boat name as tenant
- Falls back to "Liliane 1" for single-tenant setup
- Each boat becomes a unique tenant in the system

Files Changed:
- client/src/views/DocumentView.vue - Text layer implementation
- client/src/composables/useSearch.js - Backend API integration
- client/src/components/UploadModal.vue - Auto-fill feature
- server/routes/quick-ocr.js - OCR endpoint (new)
- server/index.js - Route registration
- server/scripts/* - Cleanup utilities (new)

Testing:
All features tested on local deployment at http://172.29.75.55:8083
- Backend: http://localhost:8001
- Frontend: http://localhost:8083
- Meilisearch: http://localhost:7700

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-20 01:35:06 +02:00

62 lines
1.9 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Database from 'better-sqlite3';
const db = new Database('./db/navidocs.db');
const docs = db.prepare(`
SELECT id, title, status, pageCount, imagesExtracted, imageCount, createdAt
FROM documents
ORDER BY createdAt DESC
LIMIT 3
`).all();
console.log('\n=== Latest Documents ===\n');
docs.forEach(doc => {
console.log(`ID: ${doc.id}`);
console.log(`Title: ${doc.title}`);
console.log(`Status: ${doc.status}`);
console.log(`Pages: ${doc.pageCount}`);
console.log(`Images: ${doc.imageCount} (extracted: ${doc.imagesExtracted})`);
const date = new Date(doc.createdAt);
console.log(`Created: ${date.toISOString()}`);
console.log('---');
});
// Check the document that was processing
const doc = db.prepare(`
SELECT * FROM documents WHERE id = '18f29f59-d2ca-4b01-95c8-004e8db3982e'
`).get();
if (doc) {
console.log('\n=== Document 18f29f59 Status ===');
console.log(`Status: ${doc.status}`);
console.log(`Page Count: ${doc.pageCount}`);
console.log(`Images Extracted: ${doc.imagesExtracted}`);
console.log(`Image Count: ${doc.imageCount}`);
// Count actual pages
const pageCount = db.prepare(`
SELECT COUNT(*) as count FROM document_pages WHERE document_id = ?
`).get(doc.id);
// Count actual images
const imageCount = db.prepare(`
SELECT COUNT(*) as count FROM document_images WHERE documentId = ?
`).get(doc.id);
console.log(`\nActual pages in DB: ${pageCount.count}`);
console.log(`Actual images in DB: ${imageCount.count}`);
// Update status if needed
if (doc.status !== 'indexed' && pageCount.count === 100) {
console.log('\n⚠ Document is complete but status is not "indexed". Fixing...');
db.prepare(`
UPDATE documents
SET status = 'indexed',
imagesExtracted = 1,
imageCount = ?
WHERE id = ?
`).run(imageCount.count, doc.id);
console.log('✅ Status updated to "indexed"');
}
}
db.close();