mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 22:02:08 +03:00
7.1 — Consolidated rate-limit routes - Merged rate-limit/ and rate-limits/ into rate-limits/route.js - GET returns connections + overview + lockouts + cacheStats (unified) - POST handles toggle protection - Old rate-limit/ now redirects 308 → rate-limits/ - Updated frontend fetch URL in providers/[id]/page.js 7.2 — Zod schema for provider constants - New: src/shared/validation/providerSchema.js - Validates FREE_PROVIDERS, OAUTH_PROVIDERS, APIKEY_PROVIDERS at module load - Catches config drift (invalid colors, missing fields) at startup 7.3 — TailwindCSS error pages - Converted not-found.js inline styles → Tailwind classes - Converted global-error.js inline styles → Tailwind classes - Replaced JS hover handlers with Tailwind hover: utilities 7.4 — Fixed GitHub link in privacy page - decolua/omniroute → diegosouzapw/OmniRoute 7.5 — Already completed in Phase 5 Tests: 295 pass | Build: success
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
import { NextResponse } from "next/server";
|
|
import { getAllModelLockouts } from "@omniroute/open-sse/services/accountFallback.js";
|
|
import { getCacheStats } from "@omniroute/open-sse/services/signatureCache.js";
|
|
import { getProviderConnections, updateProviderConnection } from "@/lib/localDb";
|
|
import {
|
|
enableRateLimitProtection,
|
|
disableRateLimitProtection,
|
|
getRateLimitStatus,
|
|
getAllRateLimitStatus,
|
|
} from "@omniroute/open-sse/services/rateLimitManager.js";
|
|
|
|
/**
|
|
* GET /api/rate-limits — Consolidated rate-limit status
|
|
*
|
|
* Returns:
|
|
* - Per-connection rate-limit status (protection toggle, current state)
|
|
* - Global overview (all providers)
|
|
* - Model lockouts
|
|
* - Signature cache stats
|
|
*/
|
|
export async function GET() {
|
|
try {
|
|
const connections = await getProviderConnections();
|
|
const statuses = connections.map((conn) => ({
|
|
connectionId: conn.id,
|
|
provider: conn.provider,
|
|
name: conn.name || conn.email || conn.id.slice(0, 8),
|
|
rateLimitProtection: !!conn.rateLimitProtection,
|
|
...getRateLimitStatus(conn.provider, conn.id),
|
|
}));
|
|
|
|
const lockouts = getAllModelLockouts();
|
|
const cacheStats = getCacheStats();
|
|
|
|
return NextResponse.json({
|
|
connections: statuses,
|
|
overview: getAllRateLimitStatus(),
|
|
lockouts,
|
|
cacheStats,
|
|
});
|
|
} catch (error) {
|
|
console.error("[API ERROR] /api/rate-limits GET:", error);
|
|
return NextResponse.json({ error: "Failed to get rate limit status" }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* POST /api/rate-limits — Toggle rate limit protection for a connection
|
|
* Body: { connectionId: string, enabled: boolean }
|
|
*/
|
|
export async function POST(request) {
|
|
try {
|
|
const { connectionId, enabled } = await request.json();
|
|
|
|
if (!connectionId) {
|
|
return NextResponse.json({ error: "Missing connectionId" }, { status: 400 });
|
|
}
|
|
|
|
// Update in-memory state
|
|
if (enabled) {
|
|
enableRateLimitProtection(connectionId);
|
|
} else {
|
|
disableRateLimitProtection(connectionId);
|
|
}
|
|
|
|
// Persist to database
|
|
await updateProviderConnection(connectionId, {
|
|
rateLimitProtection: !!enabled,
|
|
});
|
|
|
|
return NextResponse.json({ success: true, connectionId, enabled: !!enabled });
|
|
} catch (error) {
|
|
console.error("[API ERROR] /api/rate-limits POST:", error);
|
|
return NextResponse.json({ error: "Failed to toggle rate limit" }, { status: 500 });
|
|
}
|
|
}
|