🏗️ User Settings System: - Create comprehensive Settings page with tabbed interface - Move OCR configuration from modal to dedicated settings tab - Add API endpoints for user preferences (GET/PUT) - Store settings in database user_preferences table with ocr_settings column - Add Settings link to navbar user dropdown ⚙️ Settings Features: - General tab: default view, items per page, theme, animations - AI OCR tab: service selection, API keys, confidence threshold - Privacy tab: public collections/decks defaults - Real-time API key testing for OpenAI and Ollama - Persistent storage in database instead of localStorage 🔄 Integration: - Remove old OCRSettings modal from Scanner page - Add Settings route to App.tsx routing - Update navbar with Settings link in user dropdown - Prepare for AI OCR service to read from user preferences Next: Update AI OCR service to use saved user preferences instead of localStorage
65 lines
No EOL
1.7 KiB
JavaScript
65 lines
No EOL
1.7 KiB
JavaScript
const { Pool } = require('pg');
|
|
|
|
const pool = new Pool({
|
|
connectionString: process.env.DATABASE_URL,
|
|
ssl: process.env.NODE_ENV === 'production' ? { rejectUnauthorized: false } : false,
|
|
});
|
|
|
|
export default async function handler(req, res) {
|
|
if (req.method !== 'POST') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
const client = await pool.connect();
|
|
|
|
try {
|
|
console.log('Updating user_preferences schema to add OCR settings...');
|
|
|
|
// Check if ocr_settings column already exists
|
|
const columnCheck = await client.query(`
|
|
SELECT EXISTS (
|
|
SELECT FROM information_schema.columns
|
|
WHERE table_schema = 'public'
|
|
AND table_name = 'user_preferences'
|
|
AND column_name = 'ocr_settings'
|
|
);
|
|
`);
|
|
|
|
if (columnCheck.rows[0].exists) {
|
|
return res.status(200).json({
|
|
success: true,
|
|
message: 'OCR settings column already exists',
|
|
already_updated: true
|
|
});
|
|
}
|
|
|
|
// Add ocr_settings column
|
|
await client.query(`
|
|
ALTER TABLE user_preferences
|
|
ADD COLUMN ocr_settings JSONB DEFAULT '{
|
|
"preferred_service": "openai",
|
|
"openai_api_key": "",
|
|
"ollama_url": "http://localhost:11434",
|
|
"auto_add_to_collection": false,
|
|
"confidence_threshold": 80
|
|
}'::jsonb;
|
|
`);
|
|
|
|
console.log('✅ OCR settings column added to user_preferences table');
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
message: 'User preferences schema updated successfully with OCR settings'
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('Schema update failed:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Schema update failed',
|
|
details: error.message
|
|
});
|
|
} finally {
|
|
client.release();
|
|
}
|
|
}
|