--- import ebay from "/vendors/ebay.svg?raw"; import SetIcon from '../../components/SetIcon.astro'; import EnergyIcon from '../../components/EnergyIcon.astro'; import RarityIcon from '../../components/RarityIcon.astro'; import { db } from '../../db/index'; import { privateDecrypt } from "node:crypto"; export const partial = true; export const prerender = false; const searchParams = Astro.url.searchParams; const cardId = Number(searchParams.get('cardId')) || 0; // query the database for the card with the given productId and return the card data as json const card = await db.query.cards.findFirst({ where: { cardId: Number(cardId) }, with: { prices: true, set: true, } }); function timeAgo(date: Date | null) { if (!date) return "Not applicable"; const seconds = Math.floor((Date.now() - date.getTime()) / 1000); const intervals: Record = { year: 31536000, month: 2592000, day: 86400, hour: 3600, minute: 60 }; for (const [unit, value] of Object.entries(intervals)) { const count = Math.floor(seconds / value); if (count >= 1) return `${count} ${unit}${count > 1 ? "s" : ""} ago`; } return "just now"; } // Get the most recent calculatedAt across all prices const calculatedAt = (() => { if (!card?.prices?.length) return null; // Extract all valid calculatedAt timestamps const dates = card.prices .map(p => p.calculatedAt) .filter(d => d) // remove null/undefined .map(d => new Date(d)); if (!dates.length) return null; // Return the most recent one return new Date(Math.max(...dates.map(d => d.getTime()))); })(); const conditionOrder = ["Near Mint", "Lightly Played", "Moderately Played", "Heavily Played", "Damaged"]; const conditionAttributes = (price: any) => { const volatility = (() => { const current = price?.marketPrice; const low = price?.lowestPrice; const high = price?.highestPrice; if (current === null || low === null || high === null) return "—"; const range = Number(high) - Number(low); if (range <= 0) return "Low"; const position = (Number(current) - Number(low)) / range; if (position > 0.75) return "High"; if (position > 0.46) return "Medium"; return "Low"; })(); const volatilityClass = volatility === "High" ? "alert-danger" : volatility === "Medium" ? "alert-warning" : volatility === "Low" ? "alert-success" : ""; const condition: string = price?.condition || "Near Mint"; return { "Near Mint": { label: "nav-nm", volatility: volatility, volatilityClass: volatilityClass, class:"show active" }, "Lightly Played": { label: "nav-lp", volatility: volatility, volatilityClass: volatilityClass }, "Moderately Played": { label: "nav-mp", volatility: volatility, volatilityClass: volatilityClass }, "Heavily Played": { label: "nav-hp", volatility: volatility, volatilityClass: volatilityClass }, "Damaged": { label: "nav-dmg", volatility: volatility, volatilityClass: volatilityClass}, }[condition]; }; const ebaySearchUrl = (card: any) => { return `https://www.ebay.com/sch/i.html?_nkw=${encodeURIComponent(card?.productUrlName)}+${encodeURIComponent(card?.set?.setUrlName)}+${card?.number}&LH_Sold=1&Graded=No&_dcat=183454${card?.productId}`; }; ---