* fix: cap per-user audit capacity Block new audits before a user exceeds the temporary 100k audit footprint cap. Surface a clear delete-old-audits message in the audit launch UI. * fix: reserve audit capacity with Drizzle * fix: add Ireland keyword location support * feat: expand keyword country defaults * test: add keyword location smoke test * test: load keyword smoke test env locally * chore: remove keyword location smoke test * refactor: simplify keyword location state * fix: preserve explicit keyword location params
36 lines
753 B
TypeScript
36 lines
753 B
TypeScript
import type { PsiStrategy } from "@/server/lib/audit/types";
|
|
|
|
export const MAX_USER_AUDIT_USAGE = 100_000;
|
|
|
|
export function clampAuditMaxPages(maxPages?: number) {
|
|
return Math.min(Math.max(maxPages ?? 50, 10), 10_000);
|
|
}
|
|
|
|
export function getEstimatedAuditCapacity(input: {
|
|
maxPages?: number;
|
|
psiStrategy?: PsiStrategy;
|
|
}) {
|
|
const pagesTotal = clampAuditMaxPages(input.maxPages);
|
|
const psiStrategy = input.psiStrategy ?? "auto";
|
|
|
|
let psiTotal = 0;
|
|
switch (psiStrategy) {
|
|
case "all":
|
|
psiTotal = pagesTotal * 2;
|
|
break;
|
|
case "auto":
|
|
psiTotal = 20;
|
|
break;
|
|
case "manual":
|
|
case "none":
|
|
psiTotal = 0;
|
|
break;
|
|
}
|
|
|
|
return {
|
|
pagesTotal,
|
|
psiTotal,
|
|
total: pagesTotal + psiTotal,
|
|
};
|
|
}
|