19 Commits

Author SHA1 Message Date
Zach Harding
85cfd1de64 added the ability to search by artist name 2026-04-07 08:07:47 -04:00
Zach Harding
c03a0b36a0 removed ads, fixed copy image for newer iOS 2026-04-05 13:11:46 -04:00
Zach Harding
5cdf9b1772 ads placement - tbd 2026-04-05 10:17:43 -04:00
Zach Harding
17465b13c1 adsense verification, remove latest sales table, add new search mechanic (weight, synonyms), fix low volatility (NaN%) 2026-04-01 17:43:47 -04:00
Zach Harding
c61cafecdc added /admin for admin panel - limited to users in the admin role (also updated local .env to match prod keys for clerk) 2026-03-28 16:52:53 -04:00
Zach Harding
2b3d5f322e Merge branch 'master' of papi.tkpups.com:tmiller/pokemon 2026-03-25 14:32:43 -04:00
Zach Harding
53cdddb183 correct sort by market price by adding a back a roll-up market price from skus to product ID during sync 2026-03-25 14:31:46 -04:00
35c8bf25f5 [bugfix] update static path on scripts 2026-03-25 13:42:19 -04:00
3f9b1accda [chore] employ static assets directory 2026-03-25 05:34:11 -04:00
03e606e152 [bugfix] missed async await in tcgplayer preload 2026-03-23 21:24:24 -04:00
b871385fba [bugfix] don't close db connection pool in upload api script 2026-03-21 20:52:39 -04:00
4c6922f76b [feat] testing tcgcollector upload 2026-03-21 16:40:04 -04:00
171ce294f4 [chore] refactor common functions into helper script 2026-03-19 22:18:24 -04:00
Zach Harding
023cd87319 fixed backToTop z-index when scrolling on mobile 2026-03-18 20:36:33 -04:00
Zach Harding
04ea65eeeb hotfix for image-grow class 2026-03-18 14:53:10 -04:00
Zach Harding
9d9524e654 Merge branch 'feat/csv-prices' of papi.tkpups.com:tmiller/pokemon 2026-03-18 13:45:57 -04:00
c0120e3e77 [feat] read tcgcollector csv 2026-03-18 13:39:39 -04:00
660da7cded read/write CSV, prices from db 2026-03-18 13:26:42 -04:00
2a17654c74 [chore] sales history schema 2026-03-18 11:14:19 -04:00
25 changed files with 790 additions and 338 deletions

3
.gitignore vendored
View File

@@ -26,6 +26,9 @@ pnpm-debug.log*
# imges from tcgplayer # imges from tcgplayer
public/cards/* public/cards/*
# static assets
/static/
# anything test # anything test
test.* test.*

40
package-lock.json generated
View File

@@ -16,6 +16,7 @@
"bootstrap": "^5.3.8", "bootstrap": "^5.3.8",
"chalk": "^5.6.2", "chalk": "^5.6.2",
"chart.js": "^4.5.1", "chart.js": "^4.5.1",
"csv": "^6.4.1",
"dotenv": "^17.2.4", "dotenv": "^17.2.4",
"drizzle-orm": "^1.0.0-beta.15-859cf75", "drizzle-orm": "^1.0.0-beta.15-859cf75",
"pg": "^8.20.0", "pg": "^8.20.0",
@@ -3091,6 +3092,39 @@
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/csv": {
"version": "6.4.1",
"resolved": "https://registry.npmjs.org/csv/-/csv-6.4.1.tgz",
"integrity": "sha512-ajGosmTGnTwYyGl8STqZDu7R6LkDf3xL39XiOmliV/GufQeVUxHzTKIm4NOBCwmEuujK7B6isxs4Uqt9GcRCvA==",
"license": "MIT",
"dependencies": {
"csv-generate": "^4.5.0",
"csv-parse": "^6.1.0",
"csv-stringify": "^6.6.0",
"stream-transform": "^3.4.0"
},
"engines": {
"node": ">= 0.1.90"
}
},
"node_modules/csv-generate": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/csv-generate/-/csv-generate-4.5.0.tgz",
"integrity": "sha512-aQr/vmOKyBSBHNwYhAoXw1+kUsPnMSwmYgpNoo36rIXoG1ecWILnvPGZeQ6oUjzrWknZAD3+jfpqYOBAl4x15A==",
"license": "MIT"
},
"node_modules/csv-parse": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/csv-parse/-/csv-parse-6.1.0.tgz",
"integrity": "sha512-CEE+jwpgLn+MmtCpVcPtiCZpVtB6Z2OKPTr34pycYYoL7sxdOkXDdQ4lRiw6ioC0q6BLqhc6cKweCVvral8yhw==",
"license": "MIT"
},
"node_modules/csv-stringify": {
"version": "6.6.0",
"resolved": "https://registry.npmjs.org/csv-stringify/-/csv-stringify-6.6.0.tgz",
"integrity": "sha512-YW32lKOmIBgbxtu3g5SaiqWNwa/9ISQt2EcgOq0+RAIFufFp9is6tqNnKahqE5kuKvrnYAzs28r+s6pXJR8Vcw==",
"license": "MIT"
},
"node_modules/debug": { "node_modules/debug": {
"version": "4.4.3", "version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
@@ -7093,6 +7127,12 @@
"integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==", "integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/stream-transform": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/stream-transform/-/stream-transform-3.4.0.tgz",
"integrity": "sha512-QO3OGhKyeIV8p6eRQdG+W6WounFw519zk690hHCNfhgfP9bylVS+NTXsuBc7n+RsGn31UgFPGrWYIgoAbArKEw==",
"license": "MIT"
},
"node_modules/string_decoder": { "node_modules/string_decoder": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",

View File

@@ -17,6 +17,7 @@
"bootstrap": "^5.3.8", "bootstrap": "^5.3.8",
"chalk": "^5.6.2", "chalk": "^5.6.2",
"chart.js": "^4.5.1", "chart.js": "^4.5.1",
"csv": "^6.4.1",
"dotenv": "^17.2.4", "dotenv": "^17.2.4",
"drizzle-orm": "^1.0.0-beta.15-859cf75", "drizzle-orm": "^1.0.0-beta.15-859cf75",
"pg": "^8.20.0", "pg": "^8.20.0",

87
scripts/csvprices.ts Normal file
View File

@@ -0,0 +1,87 @@
import 'dotenv/config';
import { db, ClosePool } from '../src/db/index.ts';
import chalk from 'chalk';
import fs from "fs";
//import path from "node:path";
import { parse, stringify, transform } from 'csv';
import { client } from '../src/db/typesense.ts';
async function PricesFromCSV() {
const inputFilePath = 'scripts/test.tcgcollector.csv';
const outputFilePath = 'scripts/output.csv';
// Create read and write streams
const inputStream = fs.createReadStream(inputFilePath, 'utf8');
const outputStream = fs.createWriteStream(outputFilePath);
// Define the transformation logic
const transformer = transform({ parallel: 1 }, async function(this: any, row: any, callback: any) {
try {
// Specific query bsaed on tcgcollector CSV
const query = String(Object.values(row)[1]);
const setname = String(Object.values(row)[4]).replace(/Wizards of the coast promos/ig,'WoTC Promo');
const cardNumber = String(Object.values(row)[7]);
console.log(`${query} ${cardNumber} : ${setname}`);
// Use Typesense to find the card because we can easily use the combined fields
let cards = await client.collections('cards').documents().search({ q: query, query_by: 'productName', filter_by: `setName:\`${setname}\` && number:${cardNumber}` });
if (cards.hits?.length === 0) {
// Try without card number
cards = await client.collections('cards').documents().search({ q: query, query_by: 'productName', filter_by: `setName:\`${setname}\`` });
}
if (cards.hits?.length === 0) {
// Try without set name
cards = await client.collections('cards').documents().search({ q: query, query_by: 'productName', filter_by: `number:${cardNumber}` });
}
if (cards.hits?.length === 0) {
// I give up, just output the values from the csv
console.log(chalk.red(' - not found'));
const newRow = { ...row };
newRow.Variant = '';
newRow.marketPrice = '';
this.push(newRow);
}
else {
for (const card of cards.hits?.map((hit: any) => hit.document) ?? []) {
console.log(chalk.blue(` - ${card.cardId} : ${card.productName} : ${card.number}`), chalk.yellow(`${card.setName}`), chalk.green(`${card.variant}`));
const variant = await db.query.cards.findFirst({
with: { prices: true, tcgdata: true },
where: { cardId: card.cardId }
});
const newRow = { ...row };
newRow.Variant = variant?.variant;
newRow.marketPrice = variant?.prices.find(p => p.condition === 'Near Mint')?.marketPrice;
this.push(newRow);
}
}
callback();
} catch (error) {
callback(error);
}
});
// Pipe the streams: Read -> Parse -> Transform -> Stringify -> Write
inputStream
.on('error', (error) => console.error('Input stream error:', error))
.pipe(parse({ columns: true, trim: true }))
.on('error', (error) => console.error('Parse error:', error))
.pipe(transformer)
.on('error', (error) => console.error('Transform error:', error))
.pipe(stringify({ header: true }))
.on('error', (error) => console.error('Stringify error:', error))
.pipe(outputStream);
outputStream.on('finish', () => {
console.log(`Successfully written to ${outputFilePath}`);
ClosePool();
});
outputStream.on('error', (error) => {
console.error('An error occurred in the process:', error);
ClosePool();
});
}
await PricesFromCSV();

View File

@@ -1,104 +0,0 @@
import chalk from 'chalk';
import { client } from '../src/db/typesense.ts';
import type { DBInstance } from '../src/db/index.ts';
const DollarToInt = (dollar: any) => {
if (dollar === null) return null;
return Math.round(dollar * 100);
}
// Delete and recreate the 'cards' index
export const createCardCollection = async () => {
try {
await client.collections('cards').delete();
} catch (error) {
// Ignore error, just means collection doesn't exist
}
await client.collections().create({
name: 'cards',
fields: [
{ name: 'id', type: 'string' },
{ name: 'cardId', type: 'int32' },
{ name: 'productId', type: 'int32' },
{ name: 'variant', type: 'string', facet: true },
{ name: 'productName', type: 'string' },
{ name: 'productLineName', type: 'string', facet: true },
{ name: 'rarityName', type: 'string', facet: true },
{ name: 'setName', type: 'string', facet: true },
{ name: 'cardType', type: 'string', facet: true },
{ name: 'energyType', type: 'string', facet: true },
{ name: 'number', type: 'string', sort: true },
{ name: 'Artist', type: 'string' },
{ name: 'sealed', type: 'bool' },
{ name: 'releaseDate', type: 'int32' },
{ name: 'marketPrice', type: 'int32', optional: true, sort: true },
{ name: 'content', type: 'string', token_separators: ['/'] },
{ name: 'sku_id', type: 'string[]', optional: true, reference: 'skus.id', async_reference: true }
],
});
console.log(chalk.green('Collection "cards" created successfully.'));
}
// Delete and recreate the 'skus' index
export const createSkuCollection = async () => {
try {
await client.collections('skus').delete();
} catch (error) {
// Ignore error, just means collection doesn't exist
}
await client.collections().create({
name: 'skus',
fields: [
{ name: 'id', type: 'string' },
{ name: 'condition', type: 'string' },
{ name: 'highestPrice', type: 'int32', optional: true },
{ name: 'lowestPrice', type: 'int32', optional: true },
{ name: 'marketPrice', type: 'int32', optional: true },
]
});
console.log(chalk.green('Collection "skus" created successfully.'));
}
export const upsertCardCollection = async (db:DBInstance) => {
const pokemon = await db.query.cards.findMany({
with: { set: true, tcgdata: true, prices: true },
});
await client.collections('cards').documents().import(pokemon.map(card => {
const marketPrice = card.tcgdata?.marketPrice ? DollarToInt(card.tcgdata.marketPrice) : null;
return {
id: card.cardId.toString(),
cardId: card.cardId,
productId: card.productId,
variant: card.variant,
productName: card.productName,
productLineName: card.productLineName,
rarityName: card.rarityName,
setName: card.set?.setName || "",
cardType: card.cardType || "",
energyType: card.energyType || "",
number: card.number,
Artist: card.artist || "",
sealed: card.sealed,
content: [card.productName, card.productLineName, card.set?.setName || "", card.number, card.rarityName, card.artist || ""].join(' '),
releaseDate: card.tcgdata?.releaseDate ? Math.floor(new Date(card.tcgdata.releaseDate).getTime() / 1000) : 0,
...(marketPrice !== null && { marketPrice }),
sku_id: card.prices.map(price => price.skuId.toString())
};
}), { action: 'upsert' });
console.log(chalk.green('Collection "cards" indexed successfully.'));
}
export const upsertSkuCollection = async (db:DBInstance) => {
const skus = await db.query.skus.findMany();
await client.collections('skus').documents().import(skus.map(sku => ({
id: sku.skuId.toString(),
condition: sku.condition,
highestPrice: DollarToInt(sku.highestPrice),
lowestPrice: DollarToInt(sku.lowestPrice),
marketPrice: DollarToInt(sku.marketPrice),
})), { action: 'upsert' });
console.log(chalk.green('Collection "skus" indexed successfully.'));
}

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) {

187
scripts/pokemon-helper.ts Normal file
View File

@@ -0,0 +1,187 @@
import chalk from 'chalk';
import { client } from '../src/db/typesense.ts';
import type { DBInstance } from '../src/db/index.ts';
import fs from "node:fs/promises";
import { sql } from 'drizzle-orm'
const DollarToInt = (dollar: any) => {
if (dollar === null) return null;
return Math.round(dollar * 100);
}
export const Sleep = (ms: number) => {
return new Promise(resolve => setTimeout(resolve, ms));
}
export const FileExists = async (path: string): Promise<boolean> => {
try {
await fs.access(path);
return true;
} catch {
return false;
}
}
export const GetNumberOrNull = (value: any): number | null => {
const number = Number(value); // Attempt to convert the value to a number
if (Number.isNaN(number)) {
return null; // Return null if the result is NaN
}
return number; // Otherwise, return the number
}
// Delete and recreate the 'cards' index
export const createCardCollection = async () => {
try {
await client.collections('cards').delete();
} catch (error) {
// Ignore error, just means collection doesn't exist
}
await client.collections().create({
name: 'cards',
fields: [
{ name: 'id', type: 'string' },
{ name: 'cardId', type: 'int32' },
{ name: 'productId', type: 'int32' },
{ name: 'variant', type: 'string', facet: true },
{ name: 'productName', type: 'string' },
{ name: 'productLineName', type: 'string', facet: true },
{ name: 'rarityName', type: 'string', facet: true },
{ name: 'setName', type: 'string', facet: true },
{ name: 'setCode', type: 'string' },
{ name: 'cardType', type: 'string', facet: true },
{ name: 'energyType', type: 'string', facet: true },
{ name: 'number', type: 'string', sort: true },
{ name: 'Artist', type: 'string' },
{ name: 'sealed', type: 'bool' },
{ name: 'releaseDate', type: 'int32' },
{ name: 'marketPrice', type: 'int32', optional: true, sort: true },
{ name: 'content', type: 'string', token_separators: ['/'] },
{ name: 'sku_id', type: 'string[]', optional: true, reference: 'skus.id', async_reference: true }
],
});
console.log(chalk.green('Collection "cards" created successfully.'));
}
// Delete and recreate the 'skus' index
export const createSkuCollection = async () => {
try {
await client.collections('skus').delete();
} catch (error) {
// Ignore error, just means collection doesn't exist
}
await client.collections().create({
name: 'skus',
fields: [
{ name: 'id', type: 'string' },
{ name: 'condition', type: 'string' },
{ name: 'highestPrice', type: 'int32', optional: true },
{ name: 'lowestPrice', type: 'int32', optional: true },
{ name: 'marketPrice', type: 'int32', optional: true },
]
});
console.log(chalk.green('Collection "skus" created successfully.'));
}
export const upsertCardCollection = async (db:DBInstance) => {
const pokemon = await db.query.cards.findMany({
with: { set: true, tcgdata: true, prices: true },
});
await client.collections('cards').documents().import(pokemon.map(card => {
// 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 {
id: card.cardId.toString(),
cardId: card.cardId,
productId: card.productId,
variant: card.variant,
productName: card.productName,
productLineName: card.productLineName,
rarityName: card.rarityName,
setName: card.set?.setName || "",
setCode: card.set?.setCode || "",
cardType: card.cardType || "",
energyType: card.energyType || "",
number: card.number,
Artist: card.artist || "",
sealed: card.sealed,
content: [card.productName, card.productLineName, card.set?.setName || "", card.set?.setCode || "", card.number, card.rarityName, card.artist || ""].join(' '),
releaseDate: card.tcgdata?.releaseDate ? Math.floor(new Date(card.tcgdata.releaseDate).getTime() / 1000) : 0,
...(marketPrice !== null && { marketPrice }),
sku_id: card.prices.map(price => price.skuId.toString())
};
}), { action: 'upsert' });
console.log(chalk.green('Collection "cards" indexed successfully.'));
}
export const upsertSkuCollection = async (db:DBInstance) => {
const skus = await db.query.skus.findMany();
await client.collections('skus').documents().import(skus.map(sku => ({
id: sku.skuId.toString(),
condition: sku.condition,
highestPrice: DollarToInt(sku.highestPrice),
lowestPrice: DollarToInt(sku.lowestPrice),
marketPrice: DollarToInt(sku.marketPrice),
})), { action: 'upsert' });
console.log(chalk.green('Collection "skus" indexed successfully.'));
}
export const UpdateVariants = async (db:DBInstance) => {
const updates = await db.execute(sql`update cards as c
set
product_name = a.product_name, product_line_name = a.product_line_name, product_url_name = a.product_url_name, rarity_name = a.rarity_name,
sealed = a.sealed, set_id = a.set_id, card_type = a.card_type, energy_type = a.energy_type, number = a.number, artist = a.artist
from (
select t.product_id, b.variant,
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name,
coalesce(o.rarity_name, t.rarity_name) as rarity_name, coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id,
coalesce(o.card_type, t.card_type) as card_type, coalesce(o.energy_type, t.energy_type) as energy_type,
coalesce(o.number, t.number) as number, coalesce(o.artist, t.artist) as artist
from tcg_cards t
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
left join tcg_overrides o on t.product_id = o.product_id
) a
where c.product_id = a.product_id and c.variant = a.variant and
(
c.product_name is distinct from a.product_name or c.product_line_name is distinct from a.product_line_name or
c.product_url_name is distinct from a.product_url_name or c.rarity_name is distinct from a.rarity_name or
c.sealed is distinct from a.sealed or c.set_id is distinct from a.set_id or c.card_type is distinct from a.card_type or
c.energy_type is distinct from a.energy_type or c."number" is distinct from a."number" or c.artist is distinct from a.artist
)
`);
console.log(`Updated ${updates.rowCount} rows in cards table`);
const inserts = await db.execute(sql`insert into cards (product_id, variant, product_name, product_line_name, product_url_name, rarity_name, sealed, set_id, card_type, energy_type, "number", artist)
select t.product_id, b.variant,
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name, coalesce(o.rarity_name, t.rarity_name) as rarity_name,
coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id, coalesce(o.card_type, t.card_type) as card_type,
coalesce(o.energy_type, t.energy_type) as energy_type, coalesce(o.number, t.number) as number, coalesce(o.artist, t.artist) as artist
from tcg_cards t
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
left join tcg_overrides o on t.product_id = o.product_id
where not exists (select 1 from cards where product_id=t.product_id and variant=b.variant)
`);
console.log(`Inserted ${inserts.rowCount} rows into cards table`);
}

View File

@@ -5,10 +5,11 @@ import { db, ClosePool } from '../src/db/index.ts';
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import path from "node:path"; import path from "node:path";
import chalk from 'chalk'; import chalk from 'chalk';
import * as helper from './pokemon-helper.ts';
//import util from 'util'; //import util from 'util';
async function syncTcgplayer() { async function syncTcgplayer(cardSets:string[] = []) {
const productLines = [ "pokemon", "pokemon-japan" ]; const productLines = [ "pokemon", "pokemon-japan" ];
@@ -29,36 +30,21 @@ async function syncTcgplayer() {
const setNames = data.results[0].aggregations.setName; const setNames = data.results[0].aggregations.setName;
for (const setName of setNames) { for (const setName of setNames) {
console.log(chalk.blue(`Syncing product line "${productLine}" with setName "${setName.urlValue}"...`)); let processSet = true;
await syncProductLine(productLine, "setName", setName.urlValue); if (cardSets.length > 0) {
processSet = cardSets.some(set => setName.value.toLowerCase().includes(set.toLowerCase()));
}
if (processSet) {
console.log(chalk.blue(`Syncing product line "${productLine}" with setName "${setName.urlValue}"...`));
await syncProductLine(productLine, "setName", setName.urlValue);
}
} }
} }
console.log(chalk.green('✓ All TCGPlayer data synchronized successfully!')); console.log(chalk.green('✓ All TCGPlayer data synchronized successfully!'));
} }
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function fileExists(path: string): Promise<boolean> {
try {
await fs.access(path);
return true;
} catch {
return false;
}
}
function getNumberOrNull(value: any): number | null {
const number = Number(value); // Attempt to convert the value to a number
if (Number.isNaN(number)) {
return null; // Return null if the result is NaN
}
return number; // Otherwise, return the number
}
async function syncProductLine(productLine: string, field: string, fieldValue: string) { async function syncProductLine(productLine: string, field: string, fieldValue: string) {
let start = 0; let start = 0;
@@ -123,7 +109,7 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
for (const item of data.results[0].results) { for (const item of data.results[0].results) {
// Check if productId already exists and skip if it does (to avoid hitting the API too much) // Check if productId already exists and skip if it does (to avoid hitting the API too much)
if (allProductIds.has(item.productId)) { if (allProductIds.size > 0 && allProductIds.has(item.productId)) {
continue; continue;
} }
@@ -163,7 +149,7 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
cardTypeB: item.customAttributes.cardTypeB || null, cardTypeB: item.customAttributes.cardTypeB || null,
energyType: detailData.customAttributes.energyType?.[0] || null, energyType: detailData.customAttributes.energyType?.[0] || null,
flavorText: detailData.customAttributes.flavorText || null, flavorText: detailData.customAttributes.flavorText || null,
hp: getNumberOrNull(item.customAttributes.hp), hp: helper.GetNumberOrNull(item.customAttributes.hp),
number: detailData.customAttributes.number || '', number: detailData.customAttributes.number || '',
releaseDate: detailData.customAttributes.releaseDate ? new Date(detailData.customAttributes.releaseDate) : null, releaseDate: detailData.customAttributes.releaseDate ? new Date(detailData.customAttributes.releaseDate) : null,
resistance: item.customAttributes.resistance || null, resistance: item.customAttributes.resistance || null,
@@ -201,7 +187,7 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
cardTypeB: item.customAttributes.cardTypeB || null, cardTypeB: item.customAttributes.cardTypeB || null,
energyType: detailData.customAttributes.energyType?.[0] || null, energyType: detailData.customAttributes.energyType?.[0] || null,
flavorText: detailData.customAttributes.flavorText || null, flavorText: detailData.customAttributes.flavorText || null,
hp: getNumberOrNull(item.customAttributes.hp), hp: helper.GetNumberOrNull(item.customAttributes.hp),
number: detailData.customAttributes.number || '', number: detailData.customAttributes.number || '',
releaseDate: detailData.customAttributes.releaseDate ? new Date(detailData.customAttributes.releaseDate) : null, releaseDate: detailData.customAttributes.releaseDate ? new Date(detailData.customAttributes.releaseDate) : null,
resistance: item.customAttributes.resistance || null, resistance: item.customAttributes.resistance || null,
@@ -218,7 +204,9 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
}, },
}); });
console.log(`item: ${item.setId}\tdetail: ${detailData.setId}`);
console.log(`item: ${item.setCode}\tdetail: ${detailData.setCode}`);
console.log(`item: ${item.setName}\tdetail: ${detailData.setName}`);
// set is... // set is...
await db.insert(schema.sets).values({ await db.insert(schema.sets).values({
setId: detailData.setId, setId: detailData.setId,
@@ -254,8 +242,8 @@ 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 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) {
const buffer = await imageResponse.arrayBuffer(); const buffer = await imageResponse.arrayBuffer();
@@ -267,7 +255,7 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
} }
// be nice to the API and not send too many requests in a short time // be nice to the API and not send too many requests in a short time
await sleep(300); await helper.Sleep(300);
} }
@@ -277,8 +265,21 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
// clear the log file // clear the log file
await fs.rm('missing_images.log', { force: true }); await fs.rm('missing_images.log', { force: true });
let allProductIds = new Set();
const allProductIds = new Set(await db.select({ productId: schema.cards.productId }).from(schema.cards).then(rows => rows.map(row => row.productId))); const args = process.argv.slice(2);
if (args.length === 0) {
allProductIds = new Set(await db.select({ productId: schema.cards.productId }).from(schema.cards).then(rows => rows.map(row => row.productId)));
await syncTcgplayer();
}
else {
await syncTcgplayer(args);
}
// update the card table with new/updated variants
await helper.UpdateVariants(db);
// index the card updates
await helper.upsertCardCollection(db);
await syncTcgplayer();
await ClosePool(); await ClosePool();

View File

@@ -1,10 +1,10 @@
import chalk from 'chalk'; import chalk from 'chalk';
import { db, ClosePool } from '../src/db/index.ts'; import { db, ClosePool } from '../src/db/index.ts';
import * as Indexing from './indexing.ts'; import * as Indexing from './pokemon-helper.ts';
await Indexing.createCardCollection(); //await Indexing.createCardCollection();
await Indexing.createSkuCollection(); //await Indexing.createSkuCollection();
await Indexing.upsertCardCollection(db); await Indexing.upsertCardCollection(db);
await Indexing.upsertSkuCollection(db); await Indexing.upsertSkuCollection(db);
await ClosePool(); await ClosePool();

View File

@@ -3,15 +3,11 @@ import 'dotenv/config';
import chalk from 'chalk'; import chalk from 'chalk';
import { db, ClosePool } from '../src/db/index.ts'; import { db, ClosePool } from '../src/db/index.ts';
import { sql, inArray, eq } from 'drizzle-orm'; import { sql, inArray, eq } from 'drizzle-orm';
import { skus, processingSkus, priceHistory } from '../src/db/schema.ts'; import { skus, processingSkus, priceHistory, salesHistory } from '../src/db/schema.ts';
import { toSnakeCase } from 'drizzle-orm/casing'; import { toSnakeCase } from 'drizzle-orm/casing';
import * as Indexing from './indexing.ts'; import * as helper from './pokemon-helper.ts';
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function resetProcessingTable() { async function resetProcessingTable() {
// Use sql.raw to execute the TRUNCATE TABLE statement // Use sql.raw to execute the TRUNCATE TABLE statement
await db.execute(sql.raw('TRUNCATE TABLE pokemon.processing_skus;')); await db.execute(sql.raw('TRUNCATE TABLE pokemon.processing_skus;'));
@@ -21,6 +17,7 @@ async function resetProcessingTable() {
async function syncPrices() { async function syncPrices() {
const batchSize = 1000; const batchSize = 1000;
// const skuIndex = client.collections('skus'); // const skuIndex = client.collections('skus');
const updatedCards = new Set<number>();
await resetProcessingTable(); await resetProcessingTable();
console.log(chalk.green('Processing table reset and populated with current SKUs.')); console.log(chalk.green('Processing table reset and populated with current SKUs.'));
@@ -60,7 +57,7 @@ async function syncPrices() {
// remove skus from the 'working' processingSkus table // remove skus from the 'working' processingSkus table
await db.delete(processingSkus).where(inArray(processingSkus.skuId, skuIds)); await db.delete(processingSkus).where(inArray(processingSkus.skuId, skuIds));
// be nice to the API and not send too many requests in a short time // be nice to the API and not send too many requests in a short time
await sleep(200); await helper.Sleep(200);
continue; continue;
} }
@@ -103,21 +100,64 @@ async function syncPrices() {
}); });
console.log(chalk.cyan(`${skuRows.length} history rows added.`)); console.log(chalk.cyan(`${skuRows.length} history rows added.`));
} }
for (const productId of skuRows.filter(row => row.calculatedAt != null).map(row => row.productId)) {
updatedCards.add(productId);
}
} }
// remove skus from the 'working' processingSkus table // remove skus from the 'working' processingSkus table
await db.delete(processingSkus).where(inArray(processingSkus.skuId, skuIds)); await db.delete(processingSkus).where(inArray(processingSkus.skuId, skuIds));
// be nice to the API and not send too many requests in a short time // be nice to the API and not send too many requests in a short time
await sleep(200); await helper.Sleep(200);
} }
return updatedCards;
} }
const updateLatestSales = async (updatedCards: Set<number>) => {
for (const productId of updatedCards.values()) {
console.log(`Getting sale history for ${productId}`)
const salesResponse = await fetch(`https://mpapi.tcgplayer.com/v2/product/${productId}/latestsales`,{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36'
},
body: JSON.stringify({ conditions:[], languages:[1], limit:25, listType:"All", variants:[] }),
});
if (!salesResponse.ok) {
console.error('Error fetching sale history:', salesResponse.statusText);
process.exit(1);
}
const salesData = await salesResponse.json();
for (const sale of salesData.data) {
const skuData = await db.query.skus.findFirst({ where: { productId: productId, variant: sale.variant, condition: sale.condition } });
if (skuData) {
await db.insert(salesHistory).values({
skuId: skuData.skuId,
orderDate: new Date(sale.orderDate),
title: sale.title,
customListingId: sale.customListingId,
language: sale.language,
listingType: sale.listingType,
purchasePrice: sale.purchasePrice,
quantity: sale.quantity,
shippingPrice: sale.shippingPrice
}).onConflictDoNothing();
}
}
await helper.Sleep(500);
}
}
const start = Date.now(); const start = Date.now();
await syncPrices(); const updatedCards = await syncPrices();
await Indexing.upsertSkuCollection(db); await helper.upsertSkuCollection(db);
await helper.upsertCardCollection(db);
//console.log(updatedCards);
//console.log(updatedCards.size);
//await updateLatestSales(updatedCards);
await ClosePool(); await ClosePool();
const end = Date.now(); const end = Date.now();
const duration = (end - start) / 1000; const duration = (end - start) / 1000;

View File

@@ -1,47 +0,0 @@
import 'dotenv/config';
import { db, ClosePool } from '../src/db/index.ts';
import { sql } from 'drizzle-orm'
async function syncVariants() {
const updates = await db.execute(sql`update cards as c
set
product_name = a.product_name, product_line_name = a.product_line_name, product_url_name = a.product_url_name, rarity_name = a.rarity_name,
sealed = a.sealed, set_id = a.set_id, card_type = a.card_type, energy_type = a.energy_type, number = a.number, artist = a.artist
from (
select t.product_id, b.variant,
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name,
coalesce(o.rarity_name, t.rarity_name) as rarity_name, coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id,
coalesce(o.card_type, t.card_type) as card_type, coalesce(o.energy_type, t.energy_type) as energy_type,
coalesce(o.number, t.number) as number, coalesce(o.artist, t.artist) as artist
from tcg_cards t
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
left join tcg_overrides o on t.product_id = o.product_id
) a
where c.product_id = a.product_id and c.variant = a.variant and
(
c.product_name is distinct from a.product_name or c.product_line_name is distinct from a.product_line_name or
c.product_url_name is distinct from a.product_url_name or c.rarity_name is distinct from a.rarity_name or
c.sealed is distinct from a.sealed or c.set_id is distinct from a.set_id or c.card_type is distinct from a.card_type or
c.energy_type is distinct from a.energy_type or c."number" is distinct from a."number" or c.artist is distinct from a.artist
)
`);
console.log(`Updated ${updates.rowCount} rows in cards table`);
const inserts = await db.execute(sql`insert into cards (product_id, variant, product_name, product_line_name, product_url_name, rarity_name, sealed, set_id, card_type, energy_type, "number", artist)
select t.product_id, b.variant,
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name, coalesce(o.rarity_name, t.rarity_name) as rarity_name,
coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id, coalesce(o.card_type, t.card_type) as card_type,
coalesce(o.energy_type, t.energy_type) as energy_type, coalesce(o.number, t.number) as number, coalesce(o.artist, t.artist) as artist
from tcg_cards t
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
left join tcg_overrides o on t.product_id = o.product_id
where not exists (select 1 from cards where product_id=t.product_id and variant=b.variant)
`);
console.log(`Inserted ${inserts.rowCount} rows into cards table`);
}
await syncVariants();
await ClosePool();

View File

@@ -163,12 +163,12 @@ html {
.image-grow { .image-grow {
transition: box-shadow 350ms ease, transform 350ms ease; transition: box-shadow 350ms ease, transform 350ms ease;
//box-shadow: 0 2px 4px rgba(0, 0, 0, 0.24); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.24);
&:hover, &:hover,
&:focus { &:focus {
box-shadow: 0 8px 10px rgba(0, 0, 0, 0.2); box-shadow: 0 8px 10px rgba(0, 0, 0, 0.2);
//transform: translateY(-0.9rem) scale(1.02); transform: translateY(-0.9rem) scale(1.02);
} }
} }
@@ -363,6 +363,7 @@ $tiers: (
bottom: 5vh; bottom: 5vh;
right: 5vw; right: 5vw;
display: none; display: none;
z-index: 2;
} }
.top-icon svg { .top-icon svg {
@@ -669,4 +670,4 @@ input[type="search"]::-webkit-search-cancel-button {
background-size: 1rem; background-size: 1rem;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAn0lEQVR42u3UMQrDMBBEUZ9WfQqDmm22EaTyjRMHAlM5K+Y7lb0wnUZPIKHlnutOa+25Z4D++MRBX98MD1V/trSppLKHqj9TTBWKcoUqffbUcbBBEhTjBOV4ja4l4OIAZThEOV6jHO8ARXD+gPPvKMABinGOrnu6gTNUawrcQKNCAQ7QeTxORzle3+sDfjJpPCqhJh7GixZq4rHcc9l5A9qZ+WeBhgEuAAAAAElFTkSuQmCC); background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAn0lEQVR42u3UMQrDMBBEUZ9WfQqDmm22EaTyjRMHAlM5K+Y7lb0wnUZPIKHlnutOa+25Z4D++MRBX98MD1V/trSppLKHqj9TTBWKcoUqffbUcbBBEhTjBOV4ja4l4OIAZThEOV6jHO8ARXD+gPPvKMABinGOrnu6gTNUawrcQKNCAQ7QeTxORzle3+sDfjJpPCqhJh7GixZq4rHcc9l5A9qZ+WeBhgEuAAAAAElFTkSuQmCC);
} }
-------------------------------------------------- */ -------------------------------------------------- */

View File

@@ -112,6 +112,9 @@ import BackToTop from "./BackToTop.astro"
// ── Global helpers ──────────────────────────────────────────────────────── // ── Global helpers ────────────────────────────────────────────────────────
window.copyImage = async function(img) { window.copyImage = async function(img) {
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
try { try {
const canvas = document.createElement("canvas"); const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d"); const ctx = canvas.getContext("2d");
@@ -127,10 +130,17 @@ import BackToTop from "./BackToTop.astro"
clean.src = img.src; clean.src = img.src;
}); });
const blob = await new Promise((resolve, reject) => {
canvas.toBlob(b => b ? resolve(b) : reject(new Error('toBlob failed')), 'image/png');
});
if (isIOS) {
const file = new File([blob], 'card.png', { type: 'image/png' });
await navigator.share({ files: [file] });
return;
}
if (navigator.clipboard && navigator.clipboard.write) { if (navigator.clipboard && navigator.clipboard.write) {
const blob = await new Promise((resolve, reject) => {
canvas.toBlob(b => b ? resolve(b) : reject(new Error('toBlob failed')), 'image/png');
});
await navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]); await navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]);
showCopyToast('📋 Image copied!', '#198754'); showCopyToast('📋 Image copied!', '#198754');
} else { } else {
@@ -149,6 +159,7 @@ import BackToTop from "./BackToTop.astro"
} }
} }
} catch (err) { } catch (err) {
if (err.name === 'AbortError') return;
console.error('Failed:', err); console.error('Failed:', err);
showCopyToast('❌ Copy failed', '#dc3545'); showCopyToast('❌ Copy failed', '#dc3545');
} }
@@ -388,5 +399,11 @@ import BackToTop from "./BackToTop.astro"
currentCardId = null; currentCardId = null;
updateNavButtons(null); updateNavButtons(null);
}); });
// ── AdSense re-init on infinite scroll ───────────────────────────────────
document.addEventListener('htmx:afterSwap', () => {
(window.adsbygoogle = window.adsbygoogle || []).push({});
});
})(); })();
</script> </script>

View File

@@ -0,0 +1,7 @@
<div class="d-none d-xl-block sticky-top mt-5" style="top: 70px;">
<ins class="adsbygoogle"
style="display:block"
data-ad-format="autorelaxed"
data-ad-client="ca-pub-1140571217687341"
data-ad-slot="8889263515"></ins>
</div>

View File

@@ -8,12 +8,19 @@ export const relations = defineRelations(schema, (r) => ({
to: r.skus.skuId, to: r.skus.skuId,
}), }),
}, },
salesHistory: {
sku: r.one.skus({
from: r.salesHistory.skuId,
to: r.skus.skuId,
}),
},
skus: { skus: {
card: r.one.cards({ card: r.one.cards({
from: [r.skus.productId, r.skus.variant], from: [r.skus.productId, r.skus.variant],
to: [r.cards.productId, r.cards.variant], to: [r.cards.productId, r.cards.variant],
}), }),
history: r.many.priceHistory(), history: r.many.priceHistory(),
latestSales: r.many.salesHistory(),
}, },
cards: { cards: {
prices: r.many.skus(), prices: r.many.skus(),

View File

@@ -97,7 +97,7 @@ export const skus = pokeSchema.table('skus', {
priceCount: integer(), priceCount: integer(),
}, },
(table) => [ (table) => [
index('idx_product_id_condition').on(table.productId, table.variant), index('idx_product_id_condition').on(table.productId, table.variant, table.condition),
]); ]);
export const priceHistory = pokeSchema.table('price_history', { export const priceHistory = pokeSchema.table('price_history', {
@@ -109,6 +109,21 @@ export const priceHistory = pokeSchema.table('price_history', {
primaryKey({ name: 'pk_price_history', columns: [table.skuId, table.calculatedAt] }) primaryKey({ name: 'pk_price_history', columns: [table.skuId, table.calculatedAt] })
]); ]);
export const salesHistory = pokeSchema.table('sales_history',{
skuId: integer().notNull(),
orderDate: timestamp().notNull(),
title: varchar({ length: 255 }),
customListingId: varchar({ length: 255 }),
language: varchar({ length: 100 }),
listingType: varchar({ length: 100 }),
purchasePrice: decimal({ precision: 10, scale: 2 }),
quantity: integer(),
shippingPrice: decimal({ precision: 10, scale: 2 })
},
(table) => [
primaryKey({ name: 'pk_sales_history', columns: [table.skuId, table.orderDate] })
]);
export const processingSkus = pokeSchema.table('processing_skus', { export const processingSkus = pokeSchema.table('processing_skus', {
skuId: integer().primaryKey(), skuId: integer().primaryKey(),
}); });

View File

@@ -16,6 +16,7 @@ const { title } = Astro.props;
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="htmx-config" content='{"historyCacheSize": 50}'/> <meta name="htmx-config" content='{"historyCacheSize": 50}'/>
<meta name="google-adsense-account" content="ca-pub-1140571217687341">
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />
<title>{title}</title> <title>{title}</title>
@@ -42,4 +43,4 @@ const { title } = Astro.props;
<script src="../assets/js/main.js"></script> <script src="../assets/js/main.js"></script>
<script>import '../assets/js/priceChart.js';</script> <script>import '../assets/js/priceChart.js';</script>
</body> </body>
</html> </html>

View File

@@ -1,17 +1,45 @@
// src/middleware.ts import { clerkMiddleware, createRouteMatcher, clerkClient } from '@clerk/astro/server';
import { clerkMiddleware, createRouteMatcher } from '@clerk/astro/server';
import type { AstroMiddlewareRequest, AstroMiddlewareResponse } from 'astro';
const isProtectedRoute = createRouteMatcher([ const isProtectedRoute = createRouteMatcher(['/pokemon']);
'/pokemon', const isAdminRoute = createRouteMatcher(['/admin']);
]);
export const onRequest = clerkMiddleware((auth, context) => { const TARGET_ORG_ID = "org_3Baav9czkRLLlC7g89oJWqRRulK";
const { isAuthenticated, redirectToSignIn } = auth()
export const onRequest = clerkMiddleware(async (auth, context) => {
const { isAuthenticated, userId, redirectToSignIn } = auth();
if (!isAuthenticated && isProtectedRoute(context.request)) { if (!isAuthenticated && isProtectedRoute(context.request)) {
// Add custom logic to run before redirecting return redirectToSignIn();
return redirectToSignIn()
} }
});
if (isAdminRoute(context.request)) {
if (!isAuthenticated || !userId) {
return redirectToSignIn();
}
try {
const client = await clerkClient(context); // pass context here
const memberships = await client.organizations.getOrganizationMembershipList({
organizationId: TARGET_ORG_ID,
});
console.log("Total memberships found:", memberships.data.length);
console.log("Current userId:", userId);
console.log("Memberships:", JSON.stringify(memberships.data.map(m => ({
userId: m.publicUserData?.userId,
role: m.role,
})), null, 2));
const userMembership = memberships.data.find(
(m) => m.publicUserData?.userId === userId
);
if (!userMembership || userMembership.role !== "org:admin") {
return context.redirect("/");
}
} catch (e) {
console.error("Clerk membership check failed:", e);
return context.redirect("/");
}
}
});

18
src/pages/admin.astro Normal file
View File

@@ -0,0 +1,18 @@
---
export const prerender = false;
import Layout from '../layouts/Main.astro';
import NavItems from '../components/NavItems.astro';
import NavBar from '../components/NavBar.astro';
import Footer from '../components/Footer.astro';
---
<Layout title="Admin Panel">
<NavBar slot="navbar">
<NavItems slot="navItems" />
</NavBar>
<div class="row mb-4" slot="page">
<div class="col-12">
<h1>Admin Panel</h1>
</div>
</div>
<Footer slot="footer" />
</Layout>

95
src/pages/api/upload.ts Normal file
View File

@@ -0,0 +1,95 @@
// src/pages/api/upload.ts
import type { APIRoute } from 'astro';
import { parse, stringify, transform } from 'csv';
import { Readable } from 'stream';
import { client } from '../../db/typesense';
import chalk from 'chalk';
import { db, ClosePool } from '../../db/index';
// Define the transformation logic
const transformer = transform({ parallel: 1 }, async function(this: any, row: any, callback: any) {
try {
// Specific query bsaed on tcgcollector CSV
const query = String(Object.values(row)[1]);
const setname = String(Object.values(row)[4]).replace(/Wizards of the coast promos/ig,'WoTC Promo');
const cardNumber = String(Object.values(row)[7]);
console.log(`${query} ${cardNumber} : ${setname}`);
// Use Typesense to find the card because we can easily use the combined fields
let cards = await client.collections('cards').documents().search({ q: query, query_by: 'productName', filter_by: `setName:\`${setname}\` && number:${cardNumber}` });
if (cards.hits?.length === 0) {
// Try without card number
cards = await client.collections('cards').documents().search({ q: query, query_by: 'productName', filter_by: `setName:\`${setname}\`` });
}
if (cards.hits?.length === 0) {
// Try without set name
cards = await client.collections('cards').documents().search({ q: query, query_by: 'productName', filter_by: `number:${cardNumber}` });
}
if (cards.hits?.length === 0) {
// I give up, just output the values from the csv
console.log(chalk.red(' - not found'));
const newRow = { ...row };
newRow.Variant = '';
newRow.marketPrice = '';
this.push(newRow);
}
else {
for (const card of cards.hits?.map((hit: any) => hit.document) ?? []) {
console.log(chalk.blue(` - ${card.cardId} : ${card.productName} : ${card.number}`), chalk.yellow(`${card.setName}`), chalk.green(`${card.variant}`));
const variant = await db.query.cards.findFirst({
with: { prices: true, tcgdata: true },
where: { cardId: card.cardId }
});
const newRow = { ...row };
newRow.Variant = variant?.variant;
newRow.marketPrice = variant?.prices.find(p => p.condition === 'Near Mint')?.marketPrice;
this.push(newRow);
}
}
callback();
} catch (error) {
callback(error);
}
});
export const POST: APIRoute = async ({ request }) => {
try {
const formData = await request.formData();
const file = formData.get('file') as File;
const inputStream = Readable.from(file.stream());
if (!file) {
return new Response('No file uploaded', { status: 400 });
}
// Pipe the streams: Read -> Parse -> Transform -> Stringify -> Write
const outputStream = inputStream
.on('error', (error) => console.error('Input stream error:', error))
.pipe(parse({ columns: true, trim: true }))
.on('error', (error) => console.error('Parse error:', error))
.pipe(transformer)
.on('error', (error) => console.error('Transform error:', error))
.pipe(stringify({ header: true }))
.on('error', (error) => console.error('Stringify error:', error));
// outputStream.on('finish', () => {
// ClosePool();
// }).on('error', (error) => {
// ClosePool();
// });
return new Response(outputStream as any, {
headers: {
'Content-Type': 'text/csv',
'Content-Disposition': 'attachment; filename=transformed.csv',
},
});
} catch (error) {
console.error('Error processing CSV stream:', error);
return new Response('Internal Server Error', { status: 500 });
}
};

View File

@@ -4,7 +4,7 @@ import Layout from '../layouts/Main.astro';
import NavItems from '../components/NavItems.astro'; import NavItems from '../components/NavItems.astro';
import NavBar from '../components/NavBar.astro'; import NavBar from '../components/NavBar.astro';
import Footer from '../components/Footer.astro'; import Footer from '../components/Footer.astro';
import { Show, SignInButton, SignUpButton, SignOutButton } from '@clerk/astro/components' import { Show, SignInButton, SignUpButton, SignOutButton, GoogleOneTap, UserAvatar, UserButton, UserProfile } from '@clerk/astro/components'
--- ---
<Layout title="Rigid's App Thing"> <Layout title="Rigid's App Thing">
<NavBar slot="navbar"> <NavBar slot="navbar">
@@ -16,31 +16,41 @@ import { Show, SignInButton, SignUpButton, SignOutButton } from '@clerk/astro/co
<p class="text-secondary">(working title)</p> <p class="text-secondary">(working title)</p>
</div> </div>
<div class="col-12 col-md-6 mb-2"> <div class="col-12 col-md-6 mb-2">
<h2 class="mt-3">Welcome!</h2> <h2 class="mt-3">The Pokémon card tracker you actually want.</h2>
<p class="mt-2"> <p class="mt-2">
You've been selected to participate in the closed beta! This single page web application is meant to elevate condition/variant data for the Pokemon TCG. In future iterations, we will add vendor inventory/collection management features, as well. Browse real market prices and condition data across 70,000+ cards! No more
juggling multiple tabs or guessing what your cards are worth.
</p> </p>
<p class="my-2"> <p class="my-2">
After the closed beta is complete, the app will move into a more open beta. Feel free to play "Who's that Pokémon?" with the random Pokémon generator <a href="/404">here</a>. Refresh the page to see a new Pokémon! We're now open to everyone. Create a free account to get started —
collection and inventory management tools are coming soon as part of a
premium plan.
</p> </p>
<Show when="signed-in"> <Show when="signed-in">
<a href="/pokemon" class="btn btn-warning mt-2">Take me to the cards</a> <a href="/pokemon" class="btn btn-warning mt-2">Take me to the cards!</a>
</Show> </Show>
</div> </div>
<div class="col-12 col-md-6 d-flex justify-content-end align-items-start mt-3"> <div class="col-12 col-md-6 d-flex justify-content-end align-items-start mt-3">
<div class="d-flex gap-3"> <div class="d-flex gap-3 mx-auto">
<Show when="signed-out"> <Show when="signed-out">
<SignInButton asChild mode="modal"> <div class="card border p-5 w-100">
<button class="btn btn-success">Sign In</button>
</SignInButton>
<SignUpButton asChild mode="modal"> <SignUpButton asChild mode="modal">
<button class="btn btn-dark">Request Access</button> <button class="btn btn-success w-100 mb-2">Create free account</button>
</SignUpButton> </SignUpButton>
<SignInButton asChild mode="modal">
<p class="text-center text-secondary my-2">Already have an account?</p>
<button class="btn btn-outline-light w-100">Sign in</button>
</SignInButton>
<p class="text-center h6 text-light mt-2 mb-0">Free to join!</p>
</div>
<GoogleOneTap />
</Show> </Show>
<Show when="signed-in"> <Show when="signed-in">
<div class="w-100">
<SignOutButton asChild> <SignOutButton asChild>
<button class="btn btn-danger">Sign Out</button> <button class="btn btn-danger mt-2 ms-auto float-end">Sign Out</button>
</SignOutButton> </SignOutButton>
</div>
</Show> </Show>
</div> </div>
</div> </div>

26
src/pages/myprices.astro Normal file
View File

@@ -0,0 +1,26 @@
---
import Layout from '../layouts/Main.astro';
import NavItems from '../components/NavItems.astro';
import NavBar from '../components/NavBar.astro';
import Footer from '../components/Footer.astro';
---
<Layout title="Rigid's App Thing">
<NavBar slot="navbar">
<NavItems slot="navItems" />
</NavBar>
<div class="row mb-4" slot="page">
<div class="col-12">
<h1>Rigid's App Thing</h1>
<p class="text-secondary">(working title)</p>
</div>
<div class="col-12">
<!-- src/components/FileUploader.astro -->
<form action="/api/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" accept=".csv" required />
<button type="submit">Upload CSV</button>
</form>
</div>
</div>
<Footer slot="footer" />
</Layout>

View File

@@ -46,14 +46,41 @@ const calculatedAt = (() => {
const dates = card.prices const dates = card.prices
.map(p => p.calculatedAt) .map(p => p.calculatedAt)
.filter(d => d) .filter(d => d)
.map(d => new Date(d)); .map(d => new Date(d!));
if (!dates.length) return null; if (!dates.length) return null;
return new Date(Math.max(...dates.map(d => d.getTime()))); return new Date(Math.max(...dates.map(d => d.getTime())));
})(); })();
// ── Fetch price history + compute volatility ────────────────────────────── // ── Spread-based volatility (high - low) / low ────────────────────────────
// Log-return volatility was unreliable because marketPrice is a smoothed daily
// value, not transaction-driven. The 30-day high/low spread is a more honest
// proxy for price movement over the period.
const volatilityByCondition: Record<string, { label: string; spread: number }> = {};
for (const price of card?.prices ?? []) {
const condition = price.condition;
const low = Number(price.lowestPrice);
const high = Number(price.highestPrice);
const market = Number(price.marketPrice);
if (!low || !high || !market || market <= 0) {
volatilityByCondition[condition] = { label: '—', spread: 0 };
continue;
}
const spread = (high - low) / market;
const label = spread >= 0.50 ? 'High'
: spread >= 0.25 ? 'Medium'
: 'Low';
volatilityByCondition[condition] = { label, spread: Math.round(spread * 100) / 100 };
}
// ── Price history for chart ───────────────────────────────────────────────
const cardSkus = card?.prices?.length const cardSkus = card?.prices?.length
? await db.select().from(skus).where(eq(skus.cardId, cardId)) ? await db.select().from(skus).where(eq(skus.productId, card.productId))
: []; : [];
const skuIds = cardSkus.map(s => s.skuId); const skuIds = cardSkus.map(s => s.skuId);
@@ -72,41 +99,6 @@ const historyRows = skuIds.length
.orderBy(priceHistory.calculatedAt) .orderBy(priceHistory.calculatedAt)
: []; : [];
// Rolling 30-day cutoff for volatility calculation
const thirtyDaysAgo = new Date(Date.now() - 30 * 86_400_000);
const byCondition: Record<string, number[]> = {};
for (const row of historyRows) {
if (row.marketPrice == null) continue;
if (!row.calculatedAt) continue;
if (new Date(row.calculatedAt) < thirtyDaysAgo) continue;
const price = Number(row.marketPrice);
if (price <= 0) continue;
if (!byCondition[row.condition]) byCondition[row.condition] = [];
byCondition[row.condition].push(price);
}
function computeVolatility(prices: number[]): { label: string; monthlyVol: number } {
if (prices.length < 2) return { label: '—', monthlyVol: 0 };
const returns: number[] = [];
for (let i = 1; i < prices.length; i++) {
returns.push(Math.log(prices[i] / prices[i - 1]));
}
const mean = returns.reduce((a, b) => a + b, 0) / returns.length;
const variance = returns.reduce((sum, r) => sum + (r - mean) ** 2, 0) / (returns.length - 1);
const monthlyVol = Math.sqrt(variance) * Math.sqrt(30);
const label = monthlyVol >= 0.30 ? 'High'
: monthlyVol >= 0.15 ? 'Medium'
: 'Low';
return { label, monthlyVol: Math.round(monthlyVol * 100) / 100 };
}
const volatilityByCondition: Record<string, { label: string; monthlyVol: number }> = {};
for (const [condition, prices] of Object.entries(byCondition)) {
volatilityByCondition[condition] = computeVolatility(prices);
}
// ── Price history for chart (full history, not windowed) ──────────────────
const priceHistoryForChart = historyRows.map(row => ({ const priceHistoryForChart = historyRows.map(row => ({
condition: row.condition, condition: row.condition,
calculatedAt: row.calculatedAt calculatedAt: row.calculatedAt
@@ -115,29 +107,11 @@ const priceHistoryForChart = historyRows.map(row => ({
marketPrice: row.marketPrice, marketPrice: row.marketPrice,
})).filter(r => r.calculatedAt !== null); })).filter(r => r.calculatedAt !== null);
// ── Determine which range buttons to show ────────────────────────────────
const now = Date.now();
const oldestDate = historyRows.length
? Math.min(...historyRows
.filter(r => r.calculatedAt)
.map(r => new Date(r.calculatedAt!).getTime()))
: now;
const dataSpanDays = (now - oldestDate) / 86_400_000;
const showRanges = {
'1m': dataSpanDays >= 1,
'3m': dataSpanDays >= 60,
'6m': dataSpanDays >= 180,
'1y': dataSpanDays >= 365,
'all': dataSpanDays >= 400,
};
const conditionOrder = ["Near Mint", "Lightly Played", "Moderately Played", "Heavily Played", "Damaged"]; const conditionOrder = ["Near Mint", "Lightly Played", "Moderately Played", "Heavily Played", "Damaged"];
const conditionAttributes = (price: any) => { const conditionAttributes = (price: any) => {
const condition: string = price?.condition || "Near Mint"; const condition: string = price?.condition || "Near Mint";
const vol = volatilityByCondition[condition] ?? { label: '—', monthlyVol: 0 }; const vol = volatilityByCondition[condition] ?? { label: '—', spread: 0 };
const volatilityClass = (() => { const volatilityClass = (() => {
switch (vol.label) { switch (vol.label) {
@@ -150,7 +124,7 @@ const conditionAttributes = (price: any) => {
const volatilityDisplay = vol.label === '—' const volatilityDisplay = vol.label === '—'
? '—' ? '—'
: `${vol.label} (${(vol.monthlyVol * 100).toFixed(0)}%)`; : `${vol.label} (${(vol.spread * 100).toFixed(0)}%)`;
return { return {
"Near Mint": { label: "nav-nm", volatility: volatilityDisplay, volatilityClass, class: "show active" }, "Near Mint": { label: "nav-nm", volatility: volatilityDisplay, volatilityClass, class: "show active" },
@@ -190,9 +164,6 @@ const altSearchUrl = (card: any) => {
<!-- Card image column --> <!-- Card image column -->
<div class="col-sm-12 col-md-3"> <div class="col-sm-12 col-md-3">
<div class="position-relative mt-1"> <div class="position-relative mt-1">
<!-- card-image-wrap gives the modal image shimmer effects
without the hover lift/scale that image-grow has in main.scss -->
<div <div
class="card-image-wrap rounded-4" class="card-image-wrap rounded-4"
data-energy={card?.energyType} data-energy={card?.energyType}
@@ -201,11 +172,11 @@ const altSearchUrl = (card: any) => {
data-name={card?.productName} data-name={card?.productName}
> >
<img <img
src={`/cards/${card?.productId}.jpg`} src={`/static/cards/${card?.productId}.jpg`}
class="card-image w-100 img-fluid rounded-4" class="card-image w-100 img-fluid rounded-4"
alt={card?.productName} alt={card?.productName}
crossorigin="anonymous" crossorigin="anonymous"
onerror="this.onerror=null; this.src='/cards/default.jpg'; this.closest('.image-grow, .card-image-wrap')?.setAttribute('data-default','true')" onerror="this.onerror=null; this.src='/static/cards/default.jpg'; this.closest('.image-grow, .card-image-wrap')?.setAttribute('data-default','true')"
onclick="copyImage(this); dataLayer.push({'event': 'copiedImage'});" onclick="copyImage(this); dataLayer.push({'event': 'copiedImage'});"
/> />
</div> </div>
@@ -270,11 +241,11 @@ const altSearchUrl = (card: any) => {
<p class="mb-0 mt-1">${price.marketPrice}</p> <p class="mb-0 mt-1">${price.marketPrice}</p>
</div> </div>
<div class="alert alert-dark rounded p-2 flex-fill d-flex flex-column mb-0"> <div class="alert alert-dark rounded p-2 flex-fill d-flex flex-column mb-0">
<h6 class="mb-auto">Lowest Price</h6> <h6 class="mb-auto">Low Price <span class="small p text-secondary">(30 day)</span></h6>
<p class="mb-0 mt-1">${price.lowestPrice}</p> <p class="mb-0 mt-1">${price.lowestPrice}</p>
</div> </div>
<div class="alert alert-dark rounded p-2 flex-fill d-flex flex-column mb-0"> <div class="alert alert-dark rounded p-2 flex-fill d-flex flex-column mb-0">
<h6 class="mb-auto">Highest Price</h6> <h6 class="mb-auto">High Price <span class="small p text-secondary">(30 day)</span></h6>
<p class="mb-0 mt-1">${price.highestPrice}</p> <p class="mb-0 mt-1">${price.highestPrice}</p>
</div> </div>
<div class={`alert rounded p-2 flex-fill d-flex flex-column mb-0 ${attributes?.volatilityClass}`}> <div class={`alert rounded p-2 flex-fill d-flex flex-column mb-0 ${attributes?.volatilityClass}`}>
@@ -289,14 +260,14 @@ const altSearchUrl = (card: any) => {
data-bs-trigger="hover focus click" data-bs-trigger="hover focus click"
data-bs-html="true" data-bs-html="true"
data-bs-title={` data-bs-title={`
<div class='tooltip-heading fw-bold mb-1'>Monthly Volatility</div> <div class='tooltip-heading fw-bold mb-1'>30-Day Price Spread</div>
<div class='small'> <div class='small'>
<p class="mb-1"> <p class="mb-1">
<strong>What this measures:</strong> how much the market price tends to move day-to-day, <strong>What this measures:</strong> how wide the gap between the 30-day low and high is,
scaled up to a monthly expectation. relative to the market price.
</p> </p>
<p class="mb-0"> <p class="mb-0">
A card with <strong>30% volatility</strong> typically swings ±30% over a month. A card with <strong>50%+ spread</strong> has seen significant price swings over the past month.
</p> </p>
</div> </div>
`} `}
@@ -310,7 +281,7 @@ const altSearchUrl = (card: any) => {
<!-- Table only — chart is outside the tab panes --> <!-- Table only — chart is outside the tab panes -->
<div class="w-100"> <div class="w-100">
<div class="alert alert-dark rounded p-2 mb-0 table-responsive"> <div class="alert alert-dark rounded p-2 mb-0 table-responsive d-none">
<h6>Latest Verified Sales</h6> <h6>Latest Verified Sales</h6>
<table class="table table-sm mb-0"> <table class="table table-sm mb-0">
<caption class="small">Filtered to remove mismatched language variants</caption> <caption class="small">Filtered to remove mismatched language variants</caption>
@@ -357,11 +328,11 @@ const altSearchUrl = (card: any) => {
</canvas> </canvas>
</div> </div>
<div class="btn-group btn-group-sm d-flex flex-row gap-1 justify-content-end mt-2" role="group" aria-label="Time range"> <div class="btn-group btn-group-sm d-flex flex-row gap-1 justify-content-end mt-2" role="group" aria-label="Time range">
{showRanges['1m'] && <button type="button" class="btn btn-dark price-range-btn active" data-range="1m">1M</button>} <button type="button" class="btn btn-dark price-range-btn active" data-range="1m">1M</button>
{showRanges['3m'] && <button type="button" class="btn btn-dark price-range-btn" data-range="3m">3M</button>} <button type="button" class="btn btn-dark price-range-btn" data-range="3m">3M</button>
{showRanges['6m'] && <button type="button" class="btn btn-dark price-range-btn" data-range="6m">6M</button>} <button type="button" class="btn btn-dark price-range-btn" data-range="6m">6M</button>
{showRanges['1y'] && <button type="button" class="btn btn-dark price-range-btn" data-range="1y">1Y</button>} <button type="button" class="btn btn-dark price-range-btn" data-range="1y">1Y</button>
{showRanges['all'] && <button type="button" class="btn btn-dark price-range-btn" data-range="all">All</button>} <button type="button" class="btn btn-dark price-range-btn" data-range="all">All</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -48,15 +48,53 @@ const languageFilter = language === 'en' ? " && productLineName:=`Pokemon`"
// synonyms alone (e.g. terms that need to match across multiple set names) // synonyms alone (e.g. terms that need to match across multiple set names)
// and rewrites them into a direct filter, clearing the query so it doesn't // and rewrites them into a direct filter, clearing the query so it doesn't
// also try to text-match against card names. // also try to text-match against card names.
const EREADER_SETS = ['Expedition Base Set', 'Aquapolis', 'Skyridge', 'Battle-e'];
const EREADER_RE = /^(e-?reader|e reader)$/i; const ALIAS_FILTERS = [
// ── Era / set groupings ───────────────────────────────────────────────
{ re: /^(e-?reader|e reader)$/i, field: 'setName',
values: ['Expedition Base Set', 'Aquapolis', 'Skyridge', 'Battle-e'] },
{ re: /^neo$/i, field: 'setName',
values: ['Neo Genesis', 'Neo Discovery', 'Neo Revelation', 'Neo Destiny'] },
{ re: /^(wotc|wizards)$/i, field: 'setName',
values: ['Base Set', 'Jungle', 'Fossil', 'Base Set 2', 'Team Rocket',
'Gym Heroes', 'Gym Challenge', 'Neo Genesis', 'Neo Discovery',
'Neo Revelation', 'Neo Destiny', 'Expedition Base Set',
'Aquapolis', 'Skyridge', 'Battle-e'] },
{ re: /^(sun\s*(&|and)\s*moon|s(&|and)m|sm)$/i, field: 'setName',
values: ['Sun & Moon', 'Guardians Rising', 'Burning Shadows', 'Crimson Invasion',
'Ultra Prism', 'Forbidden Light', 'Celestial Storm', 'Dragon Majesty',
'Lost Thunder', 'Team Up', 'Unbroken Bonds', 'Unified Minds',
'Hidden Fates', 'Cosmic Eclipse', 'Detective Pikachu'] },
{ re: /^(sword\s*(&|and)\s*shield|s(&|and)s|swsh)$/i, field: 'setName',
values: ['Sword & Shield', 'Rebel Clash', 'Darkness Ablaze', 'Vivid Voltage',
'Battle Styles', 'Chilling Reign', 'Evolving Skies', 'Fusion Strike',
'Brilliant Stars', 'Astral Radiance', 'Pokemon GO', 'Lost Origin',
'Silver Tempest', 'Crown Zenith'] },
// ── Card type shorthands ──────────────────────────────────────────────
{ re: /^trainers?$/i, field: 'cardType', values: ['Trainer'] },
{ re: /^supporters?$/i, field: 'cardType', values: ['Supporter'] },
{ re: /^stadiums?$/i, field: 'cardType', values: ['Stadium'] },
{ re: /^items?$/i, field: 'cardType', values: ['Item'] },
{ re: /^(energys?|energies)$/i, field: 'cardType', values: ['Energy'] },
// ── Rarity shorthands ─────────────────────────────────────────────────
{ re: /^promos?$/i, field: 'rarityName', values: ['Promo'] },
];
let resolvedQuery = query; let resolvedQuery = query;
let queryFilter = ''; let queryFilter = '';
if (EREADER_RE.test(query.trim())) { for (const alias of ALIAS_FILTERS) {
resolvedQuery = ''; if (alias.re.test(query.trim())) {
queryFilter = `setName:=[${EREADER_SETS.map(s => '`' + s + '`').join(',')}]`; resolvedQuery = '';
queryFilter = `${alias.field}:=[${alias.values.map(s => '`' + s + '`').join(',')}]`;
break;
}
} }
const filters = Array.from(formData.entries()) const filters = Array.from(formData.entries())
@@ -118,7 +156,10 @@ if (start === 0) {
const searchRequests = { searches: searchArray }; const searchRequests = { searches: searchArray };
const commonSearchParams = { const commonSearchParams = {
q: resolvedQuery, q: resolvedQuery,
query_by: 'content,setName,productLineName,rarityName,energyType,cardType' query_by: 'content,setName,setCode,productName,Artist',
query_by_weights: '10,6,8,9,8',
num_typos: '2,1,0,1,2',
prefix: 'true,true,false,false,false',
}; };
// use typesense to search for cards matching the query and return the productIds of the results // use typesense to search for cards matching the query and return the productIds of the results
@@ -276,39 +317,46 @@ const facets = searchResults.results.slice(1).map((result: any) => {
} }
{pokemon.length === 0 && ( {pokemon.length === 0 && (
<div id="notfound" hx-swap-oob="true"> <div id="notfound" class="mt-4 h6" hx-swap-oob="true">
Pokemon not found No cards found! Please modify your search and try again.
</div> </div>
)} )}
{pokemon.map((card:any) => ( {pokemon.map((card: any, i: number) => (
<div class="col">
<div class="inventory-button position-relative float-end shadow-filter text-center d-none">
<div class="inventory-label pt-2">+/-</div>
</div>
<div class="card-trigger position-relative" data-card-id={card.cardId} hx-get={`/partials/card-modal?cardId=${card.cardId}`} hx-target="#cardModal" hx-trigger="click" data-bs-toggle="modal" data-bs-target="#cardModal" onclick="const cardTitle = this.querySelector('#cardImage').getAttribute('alt'); dataLayer.push({'event': 'virtualPageview', 'pageUrl': this.getAttribute('hx-get'), 'pageTitle': cardTitle, 'previousUrl': '/pokemon'});">
<div class="image-grow rounded-4 card-image" data-energy={card.energyType} data-rarity={card.rarityName} data-variant={card.variant} data-name={card.productName}><img src={`/cards/${card.productId}.jpg`} alt={card.productName} id="cardImage" loading="lazy" decoding="async" class="img-fluid rounded-4 mb-2 w-100" onerror="this.onerror=null; this.src='/cards/default.jpg'; this.closest('.image-grow')?.setAttribute('data-default','true')"/><span class="position-absolute top-50 start-0 d-inline medium-icon"><FirstEditionIcon edition={card?.variant} /></span></div>
</div>
<div class="row row-cols-5 gx-1 price-row mb-2">
{conditionOrder.map((condition) => (
<div class="col price-label ps-1">
{ conditionShort(condition) }
<br />{formatPrice(condition, card.skus)}
</div>
))}
</div>
<div class="h5 my-0">{card.productName}</div>
<div class="d-flex flex-row lh-1 mt-1 justify-content-between">
<div class="text-secondary flex-grow-1 d-none d-lg-flex">{card.setName}</div>
<div class="text-body-tertiary">{card.number}</div>
<span class="ps-2 small-icon"><RarityIcon rarity={card.rarityName} /></span>
</div>
<div class="text-body-tertiary">{card.variant}</div><span class="d-none">{card.productId}</span>
</div>
<div class="col equal-height-col">
<div class="inventory-button position-relative float-end shadow-filter text-center d-none">
<div class="inventory-label pt-2">+/-</div>
</div>
<div class="card-trigger position-relative" data-card-id={card.cardId} hx-get={`/partials/card-modal?cardId=${card.cardId}`} hx-target="#cardModal" hx-trigger="click" data-bs-toggle="modal" data-bs-target="#cardModal" onclick="const cardTitle = this.querySelector('#cardImage').getAttribute('alt'); dataLayer.push({'event': 'virtualPageview', 'pageUrl': this.getAttribute('hx-get'), 'pageTitle': cardTitle, 'previousUrl': '/pokemon'});">
<div class="image-grow rounded-4 card-image h-100" data-energy={card.energyType} data-rarity={card.rarityName} data-variant={card.variant} data-name={card.productName}>
<img src={`/static/cards/${card.productId}.jpg`} alt={card.productName} id="cardImage" loading="lazy" decoding="async" class="img-fluid rounded-4 mb-2 w-100" onerror="this.onerror=null; this.src='/static/cards/default.jpg'; this.closest('.image-grow')?.setAttribute('data-default','true')"/>
<span class="position-absolute top-50 start-0 d-inline medium-icon"><FirstEditionIcon edition={card?.variant} /></span>
<div class="holo-shine"></div>
<div class="holo-glare"></div>
</div>
</div>
<div class="row row-cols-5 gx-1 price-row mb-2">
{conditionOrder.map((condition) => (
<div class="col price-label ps-1">
{conditionShort(condition)}
<br />{formatPrice(condition, card.skus)}
</div>
))}
</div>
<div class="h5 my-0">{card.productName}</div>
<div class="d-flex flex-row lh-1 mt-1 justify-content-between">
<div class="text-secondary flex-grow-1"><span class="d-none d-lg-flex">{card.setName}</span><span class="d-flex d-lg-none">{card.setCode}</span></div>
<div class="text-body-tertiary">{card.number}</div>
<span class="ps-2 small-icon"><RarityIcon rarity={card.rarityName} /></span>
</div>
<div class="text-body-tertiary">{card.variant}</div>
<span class="d-none">{card.productId}</span>
</div>
</>
))} ))}
{start + 20 < totalHits && {start + 20 < totalHits &&
<div hx-post="/partials/cards" hx-trigger="revealed" hx-include="#searchform" hx-target="#cardGrid" hx-swap="beforeend" hx-on--after-request="afterUpdate(event)"> <div hx-post="/partials/cards" hx-trigger="revealed" hx-include="#searchform" hx-target="#cardGrid" hx-swap="beforeend" hx-on--after-request="afterUpdate(event)">
Loading... Loading...
</div> </div>
} }

View File

@@ -1,5 +1,5 @@
{ {
"extends": "astro/tsconfigs/strict", "extends": "astro/tsconfigs/strict",
"include": [".astro/types.d.ts", "**/*"], "include": [".astro/types.d.ts", "src/**/*"],
"exclude": ["dist"] "exclude": ["dist"]
} }