deckhearth/pages/api/public/collections.js
Randall Stillwell afb79c57d9 Major Scanner Improvements
🔧 Gemini AI Integration:
- Added Google Gemini API as default OCR service
- Auto-configures from GEMINI_AI_API_KEY environment variable
- Fixed Puter.js authentication issues
- Enhanced OCR settings with connection testing

🎨 Redesigned Scanner Queue:
- New thumbnail + content layout with checkbox overlay
- Smart quantity management (duplicates increment quantity)
- Complete card information display from database
- Two-row action layout (primary/secondary actions)
- Floating bottom toolbar for bulk actions
- Real card images from database

�� Enhanced User Experience:
- Fixed Canvas2D performance warnings
- Better error handling and fallbacks
- Improved responsive design
- Database confirmation indicators
- Professional card scanning workflow

📱 Mobile Ready:
- Optimized layouts for mobile scanning
- Touch-friendly controls and interactions
- Improved visual feedback and status indicators
2025-07-29 14:19:48 -05:00

63 lines
No EOL
2.1 KiB
JavaScript

import { sql } from '@vercel/postgres';
export default async function handler(req, res) {
// Set CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
// Handle preflight requests
if (req.method === 'OPTIONS') {
res.status(200).end();
return;
}
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}
try {
const { limit = 6 } = req.query;
// Get featured public collections for landing page (no auth required)
const result = await sql`
SELECT DISTINCT
c.*,
u.email as creator_email,
u.username as creator_username,
COUNT(cc.card_id) as card_count,
COALESCE(SUM(cards.market_price * cc.quantity), 0) as total_value
FROM collections c
LEFT JOIN users u ON c.user_id = u.id
LEFT JOIN collection_cards cc ON c.id = cc.collection_id
LEFT JOIN cards ON cc.card_id = cards.id
WHERE c.is_public = true
AND (c.is_system_collection IS NULL OR c.is_system_collection = false)
GROUP BY c.id, u.email, u.username
ORDER BY c.updated_at DESC, c.created_at DESC
LIMIT ${parseInt(limit)}
`;
const collections = result.rows.map(collection => ({
id: collection.id,
slug: collection.slug,
name: collection.name,
description: collection.description,
tcg: collection.tcg || 'MTG',
cardCount: parseInt(collection.card_count) || 0,
value: parseFloat(collection.total_value) || 0,
lastViewed: collection.updated_at,
createdAt: collection.created_at,
isPublic: collection.is_public || false,
tags: collection.tags ? collection.tags.split(',') : [],
creator: collection.creator_username || collection.creator_email,
image: collection.image
}));
res.status(200).json(collections);
} catch (error) {
console.error('Error fetching public collections:', error);
res.status(500).json({ error: 'Internal server error' });
}
}