Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(cache): address code review issues

oyi775437d691b5ff
diff --git a/src/app/api/cache/entries/route.ts b/src/app/api/cache/entries/route.ts
index 26f30b02a9..97ff51ca9a 100644
--- a/src/app/api/cache/entries/route.ts
+++ b/src/app/api/cache/entries/route.ts
@@ -1,5 +1,6 @@
import { NextRequest, NextResponse } from "next/server";
import { getDbInstance } from "@/lib/db/core";
+import { isAuthenticated } from "@/shared/utils/apiAuth";
interface CacheEntry {
id: string;
@@ -12,6 +13,10 @@ interface CacheEntry {
}
export async function GET(req: NextRequest) {
+ if (!(await isAuthenticated(req))) {
+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+ }
+
try {
const { searchParams } = new URL(req.url);
const page = Math.max(1, parseInt(searchParams.get("page") || "1", 10));
@@ -71,6 +76,10 @@ export async function GET(req: NextRequest) {
}
export async function DELETE(req: NextRequest) {
+ if (!(await isAuthenticated(req))) {
+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+ }
+
try {
const { searchParams } = new URL(req.url);
const signature = searchParams.get("signature");
diff --git a/src/app/api/cache/route.ts b/src/app/api/cache/route.ts
index d1bca53891..dd7364f929 100644
--- a/src/app/api/cache/route.ts
+++ b/src/app/api/cache/route.ts
@@ -9,15 +9,21 @@ import {
} from "@/lib/semanticCache";
import { getIdempotencyStats } from "@/lib/idempotencyLayer";
import { getCacheMetrics, getCacheTrend } from "@/lib/db/settings";
+import { isAuthenticated } from "@/shared/utils/apiAuth";
function errorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
export async function GET(req: NextRequest) {
+ if (!(await isAuthenticated(req))) {
+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+ }
+
try {
const { searchParams } = new URL(req.url);
- const trendHours = parseInt(searchParams.get("trendHours") || "24", 10);
+ const rawHours = parseInt(searchParams.get("trendHours") || "24", 10);
+ const trendHours = Math.min(720, Math.max(1, Number.isNaN(rawHours) ? 24 : rawHours));
const cacheStats = getCacheStats();
const idempotencyStats = getIdempotencyStats();
@@ -36,6 +42,10 @@ export async function GET(req: NextRequest) {
}
export async function DELETE(req: NextRequest) {
+ if (!(await isAuthenticated(req))) {
+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+ }
+
try {
const { searchParams } = new URL(req.url);
const model = searchParams.get("model");
diff --git a/src/lib/db/settings.ts b/src/lib/db/settings.ts
index 333d71379f..5173e81e14 100644
--- a/src/lib/db/settings.ts
+++ b/src/lib/db/settings.ts
@@ -630,7 +630,7 @@ export async function getCacheMetrics() {
totalCachedTokens: totalsRow?.totalCachedTokens || 0,
totalCacheCreationTokens: totalsRow?.totalCacheCreationTokens || 0,
tokensSaved,
- estimatedCostSaved: 0, // Would need pricing data to calculate
+ estimatedCostSaved,
byProvider,
byStrategy,
lastUpdated: new Date().toISOString(),