- Redesigned card display with 2.5:3.5 aspect ratio and image-only view - Added infinite scroll to replace pagination - Implemented authentic card back placeholders for MTG, Pokemon, and Lorcana - Added rarity-based particle effects with tiered intensity (mythic/enchanted/rare/uncommon) - Enhanced hover details panel with structured card information - Fixed search functionality with debouncing and Enter key support - Improved filter system with working TCG, rarity, set, and price filters - Added favorite system for cards in both hover and detail views - Updated card detail page with comprehensive metadata and actions - Fixed API filtering with proper Vercel Postgres implementation - Added particle animations and rarity glow effects - Improved overall UX with better visual hierarchy and interactions
88 lines
No EOL
2.6 KiB
JavaScript
88 lines
No EOL
2.6 KiB
JavaScript
import { sql } from '@vercel/postgres';
|
|
|
|
export default async function handler(req, res) {
|
|
if (req.method !== 'POST') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
try {
|
|
const { setCode } = req.body;
|
|
|
|
if (!setCode) {
|
|
return res.status(400).json({ error: 'Set code is required' });
|
|
}
|
|
|
|
// Fetch cards from Scryfall API
|
|
const response = await fetch(`https://api.scryfall.com/cards/search?q=set:${setCode}`);
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Scryfall API error: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
const cards = data.data || [];
|
|
|
|
let importedCount = 0;
|
|
let skippedCount = 0;
|
|
|
|
for (const card of cards) {
|
|
try {
|
|
// Check if card already exists
|
|
const existingCard = await sql`
|
|
SELECT id FROM cards WHERE scryfall_id = ${card.id}
|
|
`;
|
|
|
|
if (existingCard.rows.length > 0) {
|
|
skippedCount++;
|
|
continue;
|
|
}
|
|
|
|
// Extract price data
|
|
let currentPrice = null;
|
|
let marketPrice = null;
|
|
|
|
if (card.prices) {
|
|
currentPrice = card.prices.usd ? parseFloat(card.prices.usd) : null;
|
|
marketPrice = card.prices.usd_foil ? parseFloat(card.prices.usd_foil) : null;
|
|
}
|
|
|
|
// Insert card into database
|
|
await sql`
|
|
INSERT INTO cards (
|
|
name, set_name, set_code, card_number, rarity, game,
|
|
mana_cost, cmc, card_type, colors, oracle_text,
|
|
power, toughness, image_url, stock_image_url,
|
|
current_price, market_price, scryfall_id, verified
|
|
) VALUES (
|
|
${card.name}, ${card.set_name}, ${card.set}, ${card.collector_number},
|
|
${card.rarity}, 'MTG', ${card.mana_cost || null}, ${card.cmc || null},
|
|
${card.type_line}, ${JSON.stringify(card.colors || [])},
|
|
${card.oracle_text || null}, ${card.power || null}, ${card.toughness || null},
|
|
${card.image_uris?.normal || null}, ${card.image_uris?.art_crop || null},
|
|
${currentPrice}, ${marketPrice}, ${card.id}, true
|
|
)
|
|
`;
|
|
|
|
importedCount++;
|
|
} catch (error) {
|
|
console.error(`Error importing card ${card.name}:`, error);
|
|
skippedCount++;
|
|
}
|
|
}
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
message: `Import completed for set ${setCode}`,
|
|
imported: importedCount,
|
|
skipped: skippedCount,
|
|
total: cards.length
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('Card import error:', error);
|
|
res.status(500).json({
|
|
error: 'Import failed',
|
|
details: error.message
|
|
});
|
|
}
|
|
}
|