diff --git a/src/index.ts b/src/index.ts index d0c683d..c80269a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -355,6 +355,16 @@ async function start() { logger.info(`Loaded ${getAllKeys().length} API keys`); const server = app.listen(PORT, () => logger.info(`DocFast API running on :${PORT}`)); + // Run database cleanup 30 seconds after startup (non-blocking) + setTimeout(async () => { + try { + logger.info("Running scheduled database cleanup..."); + await cleanupStaleData(); + } catch (err) { + logger.error({ err }, "Startup cleanup failed (non-fatal)"); + } + }, 30_000); + let shuttingDown = false; const shutdown = async (signal: string) => { if (shuttingDown) return; diff --git a/src/middleware/pdfRateLimit.ts b/src/middleware/pdfRateLimit.ts index e01d061..e34d64a 100644 --- a/src/middleware/pdfRateLimit.ts +++ b/src/middleware/pdfRateLimit.ts @@ -7,6 +7,13 @@ interface RateLimitEntry { resetTime: number; } +interface RateLimitResult { + allowed: boolean; + limit: number; + remaining: number; + resetTime: number; // Unix timestamp in milliseconds +} + // Per-key rate limits (requests per minute) const FREE_RATE_LIMIT = 10; const PRO_RATE_LIMIT = 30;