--- 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.ts'; import { privateDecrypt } from "node:crypto"; import latestSales from '../../sampleData/latestsales.json'; import chartdata from '../../sampleData/chartdata.json'; const priceData = chartdata; 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, } }); const nearMint = card?.prices.find(price => price.condition === "Near Mint") || null; const calculatedAt = new Date(nearMint?.calculatedAt || 0); function timeAgo(date: any) { if (date==0) return "never"; const seconds = Math.floor((Date.now() - date) / 1000); const intervals = { 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"; } 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]; }; ---