mirror of
https://github.com/tiennm99/store-scraper-bot.git
synced 2026-05-25 21:59:03 +00:00
eb0f79be82
- remove MONGODB_URI from .env.example (Atlas migration done; deleted from Vercel cloud env too) - trim .env.deploy.example to vars actually consumed by deploy scripts (Upstash creds were only needed by the now-deleted migration script) - README config table: drop ENV / SOURCE_COMMIT / SCHEDULE_CHECK_APP_TIME (never read by code; Java-era leftovers) - check-secret-leaks: drop MONGODB_URI; add UPSTASH/KV/CRON tokens; widen scan roots to include api/ - add scripts/list-upstash-keys.js read-only ops helper
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// One-shot inspector: lists every Redis key the bot can see.
|
|
// Run via: node --env-file=.env.deploy scripts/list-upstash-keys.js
|
|
// Read-only.
|
|
|
|
import { Redis } from '@upstash/redis';
|
|
|
|
const url = process.env.UPSTASH_REDIS_REST_URL ?? process.env.KV_REST_API_URL;
|
|
const token = process.env.UPSTASH_REDIS_REST_TOKEN ?? process.env.KV_REST_API_TOKEN;
|
|
const prefix = process.env.KEY_PREFIX ?? 'store-scraper-bot:';
|
|
|
|
if (!url || !token) {
|
|
console.error('Upstash credentials not found in env');
|
|
process.exit(1);
|
|
}
|
|
|
|
const redis = new Redis({ url, token });
|
|
|
|
let cursor = 0;
|
|
const keys = [];
|
|
do {
|
|
const [next, batch] = await redis.scan(cursor, { match: '*', count: 100 });
|
|
cursor = Number(next);
|
|
keys.push(...batch);
|
|
} while (cursor !== 0);
|
|
|
|
keys.sort();
|
|
|
|
const inPrefix = keys.filter((k) => k.startsWith(prefix));
|
|
const orphan = keys.filter((k) => !k.startsWith(prefix));
|
|
|
|
console.log(`KEY_PREFIX: ${prefix}`);
|
|
console.log(`Total keys: ${keys.length}`);
|
|
console.log(`In-prefix: ${inPrefix.length}`);
|
|
console.log(`Orphan: ${orphan.length}`);
|
|
console.log();
|
|
console.log('In-prefix keys:');
|
|
for (const k of inPrefix) console.log(` ${k}`);
|
|
if (orphan.length) {
|
|
console.log();
|
|
console.log('Orphan keys (NOT under KEY_PREFIX):');
|
|
for (const k of orphan) console.log(` ${k}`);
|
|
}
|