3 Commits

5 changed files with 13 additions and 4 deletions

View File

@@ -12,7 +12,7 @@ async function findMissingImages() {
.where(sql`${schema.tcgcards.sealed} = false`); .where(sql`${schema.tcgcards.sealed} = false`);
const missingImages: string[] = []; const missingImages: string[] = [];
for (const card of cards) { for (const card of cards) {
const imagePath = path.join(process.cwd(), 'public', 'cards', `${card.productId}.jpg`); const imagePath = path.join(process.cwd(), 'static', 'cards', `${card.productId}.jpg`);
try { try {
await fs.access(imagePath); await fs.access(imagePath);
} catch (err) { } catch (err) {

View File

@@ -94,7 +94,15 @@ export const upsertCardCollection = async (db:DBInstance) => {
with: { set: true, tcgdata: true, prices: true }, with: { set: true, tcgdata: true, prices: true },
}); });
await client.collections('cards').documents().import(pokemon.map(card => { await client.collections('cards').documents().import(pokemon.map(card => {
const marketPrice = card.tcgdata?.marketPrice ? DollarToInt(card.tcgdata.marketPrice) : null; // Use the NM SKU price matching the card's variant (kept fresh by syncPrices)
// Fall back to any NM sku, then to tcgdata price
const nmSku = card.prices.find(p => p.condition === 'Near Mint' && p.variant === card.variant)
?? card.prices.find(p => p.condition === 'Near Mint');
const marketPrice = nmSku?.marketPrice
? DollarToInt(nmSku.marketPrice)
: card.tcgdata?.marketPrice
? DollarToInt(card.tcgdata.marketPrice)
: null;
return { return {
id: card.cardId.toString(), id: card.cardId.toString(),

View File

@@ -242,7 +242,7 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
} }
// get image if it doesn't already exist // get image if it doesn't already exist
const imagePath = path.join(process.cwd(), 'public', 'cards', `${item.productId}.jpg`); const imagePath = path.join(process.cwd(), 'static', 'cards', `${item.productId}.jpg`);
if (!await helper.FileExists(imagePath)) { if (!await helper.FileExists(imagePath)) {
const imageResponse = await fetch(`https://tcgplayer-cdn.tcgplayer.com/product/${item.productId}_in_1000x1000.jpg`); const imageResponse = await fetch(`https://tcgplayer-cdn.tcgplayer.com/product/${item.productId}_in_1000x1000.jpg`);
if (imageResponse.ok) { if (imageResponse.ok) {

View File

@@ -154,6 +154,7 @@ const updateLatestSales = async (updatedCards: Set<number>) => {
const start = Date.now(); const start = Date.now();
const updatedCards = await syncPrices(); const updatedCards = await syncPrices();
await helper.upsertSkuCollection(db); await helper.upsertSkuCollection(db);
await helper.upsertCardCollection(db);
//console.log(updatedCards); //console.log(updatedCards);
//console.log(updatedCards.size); //console.log(updatedCards.size);
//await updateLatestSales(updatedCards); //await updateLatestSales(updatedCards);