[feat] move missing image script out of test scripts so it's picked up by git
This commit is contained in:
26
scripts/list-missing-images.ts
Normal file
26
scripts/list-missing-images.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import * as schema from '../src/db/schema.ts';
|
||||||
|
import { db, ClosePool } from '../src/db/index.ts';
|
||||||
|
|
||||||
|
import fs from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
|
async function findMissingImages() {
|
||||||
|
const cards = await db.select().from(schema.tcgcards);
|
||||||
|
const missingImages: string[] = [];
|
||||||
|
for (const card of cards) {
|
||||||
|
const imagePath = path.join(process.cwd(), 'public', 'cards', `${card.productId}.jpg`);
|
||||||
|
try {
|
||||||
|
await fs.access(imagePath);
|
||||||
|
} catch (err) {
|
||||||
|
missingImages.push(`${card.productId}\t${card.productName}\t${card.number}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return missingImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
const missingImages = await findMissingImages();
|
||||||
|
//console.log("Missing Images:", missingImages.join('\n'));
|
||||||
|
|
||||||
|
fs.writeFile(path.join(process.cwd(), 'missing-images.log'), missingImages.join('\n'));
|
||||||
|
|
||||||
|
await ClosePool();
|
||||||
Reference in New Issue
Block a user