mirror of
https://github.com/tiennm99/store-scraper-bot.git
synced 2026-10-11 03:13:50 +00:00
Refactors source to be Worker-shaped. No live deploy yet — sister deploy plan
runs Atlas provisioning + smoke later.
- wrangler.toml with nodejs_compat_v2, daily UTC 0 cron (= 7am Asia/Ho_Chi_Minh)
- package.json: drop node-telegram-bot-api, node-cron, dotenv, pino,
pino-pretty; add wrangler devDep; bump to 0.2.0
- src/bot/telegram-api.js: raw fetch wrapper for Telegram Bot API
- src/bot/dispatch.js: per-message dispatcher extracted from polling loop
- src/repository/mongodb.js: memoized MongoClient per warm isolate, typed
MongoUnavailable error, fast-fail timeouts
- src/repository/store.js: factory binding env once
- All 4 repositories converted to factory shape
- src/api/{apple,google}-scraper.js: take store instead of importing repos
- src/index.js: Worker entry exporting { fetch, scheduled }; webhook validates
X-Telegram-Bot-Api-Secret-Token; ack-then-waitUntil pattern
- src/scheduler/scheduler.js: trimmed; runDailyCheck only (no node-cron)
- src/config.js, src/logger.js: env-driven, console.log JSON output
- scripts/register-webhook.js: setWebhook + setMyCommands; --dry-run supported
- scripts/check-secret-leaks.js: lint blocks console.log(env.<SECRET>)
- plans/260426-2015-cloudflare-worker-code-port: this code port plan
- plans/260426-2327-cloudflare-deploy-and-smoke: sister deploy plan
Validated via node --check on all 32 source files; lint clean. Real deploy
gates (bundle size, cold-start CPU) run in deploy plan.
28 lines
742 B
JavaScript
28 lines
742 B
JavaScript
import { getCollection } from './mongodb.js';
|
|
import { isGoogleAppExpired } from '../models/google-app.js';
|
|
|
|
export function createGoogleAppRepository(env, appCacheSeconds) {
|
|
function collection() {
|
|
return getCollection('google_app', env);
|
|
}
|
|
|
|
async function get(appId) {
|
|
const c = await collection();
|
|
return c.findOne({ _id: appId });
|
|
}
|
|
|
|
async function save(entry) {
|
|
const c = await collection();
|
|
await c.replaceOne({ _id: entry._id }, entry, { upsert: true });
|
|
}
|
|
|
|
async function getCached(appId) {
|
|
const entry = await get(appId);
|
|
if (!entry) return null;
|
|
if (isGoogleAppExpired(entry, Date.now(), appCacheSeconds * 1000)) return null;
|
|
return entry;
|
|
}
|
|
|
|
return { get, save, getCached };
|
|
}
|