Enforce Pro plan limit of 5,000 PDFs/month
Some checks failed
Deploy to Production / Deploy to Server (push) Has been cancelled
Some checks failed
Deploy to Production / Deploy to Server (push) Has been cancelled
This commit is contained in:
parent
b98e8bc253
commit
c903860917
5 changed files with 31 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ import logger from "../services/logger.js";
|
|||
import pool from "../services/db.js";
|
||||
|
||||
const FREE_TIER_LIMIT = 100;
|
||||
const PRO_TIER_LIMIT = 2500;
|
||||
|
||||
// In-memory cache, periodically synced to PostgreSQL
|
||||
let usage = new Map<string, { count: number; monthKey: string }>();
|
||||
|
|
@ -44,6 +45,15 @@ export function usageMiddleware(req: any, res: any, next: any): void {
|
|||
const monthKey = getMonthKey();
|
||||
|
||||
if (isProKey(key)) {
|
||||
const record = usage.get(key);
|
||||
if (record && record.monthKey === monthKey && record.count >= PRO_TIER_LIMIT) {
|
||||
res.status(429).json({
|
||||
error: "Pro tier limit reached (2,500/month). Contact support for higher limits.",
|
||||
limit: PRO_TIER_LIMIT,
|
||||
used: record.count,
|
||||
});
|
||||
return;
|
||||
}
|
||||
trackUsage(key, monthKey);
|
||||
next();
|
||||
return;
|
||||
|
|
@ -55,7 +65,7 @@ export function usageMiddleware(req: any, res: any, next: any): void {
|
|||
error: "Free tier limit reached",
|
||||
limit: FREE_TIER_LIMIT,
|
||||
used: record.count,
|
||||
upgrade: "Upgrade to Pro for unlimited conversions: https://docfast.dev/pricing",
|
||||
upgrade: "Upgrade to Pro for 2,500 PDFs/month: https://docfast.dev/pricing",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue