mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-24 16:12:23 +03:00
⭐4 — Suporte de backend nativo Bun + Dockerfile.bun multi-stage + fallback dinâmico de driver SQLite (better-sqlite3 prioritário sob Bun, bun:sqlite fallback; Node preservado) + correção de estabilidade do DAST CI smoke.
Validado a fundo (worktree board sobre tip): bun-support 4/4, typecheck:core limpo, dashboard-typecheck OK (220 dentro do baseline), open-sse-typecheck OK (5 pré-existentes), gate de runtime OK sob Node, changelog-integrity OK, file-size/complexity/cognitive/dead-code OK. Verificado que o driver preserva a cadeia Node/falback conforme AGENTS.md; teste bun-support presente. Baselines de typecheck removidos são ratchet honesto (erros não existem mais).
OBS: destravei 2 base-reds do tip neste turno (push direto 7ffa3ef): movi o changelog fragment da #11050 da seção inválida breaking/ para fixes/, e rebaselinei AddApiKeyModal 1067->1073 (crescimento da #11056). Sem isso a #11039 e o resto da fila ficariam vermelhos.
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
export const dynamic = "force-dynamic";
|
|
import { isAuthenticated } from "@/shared/utils/apiAuth";
|
|
import {
|
|
listSemanticCacheEntries,
|
|
deleteSemanticCacheBySignature,
|
|
deleteSemanticCacheByModel,
|
|
} from "@/lib/db/semanticCache";
|
|
import { sanitizeErrorMessage } from "@omniroute/open-sse/utils/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 page = Math.max(1, parseInt(searchParams.get("page") || "1", 10));
|
|
const limit = Math.min(100, Math.max(1, parseInt(searchParams.get("limit") || "20", 10)));
|
|
const search = searchParams.get("search") || "";
|
|
const model = searchParams.get("model") || "";
|
|
const sortBy = searchParams.get("sortBy") || "created_at";
|
|
const sortOrder = searchParams.get("sortOrder") || "desc";
|
|
|
|
const { entries, total } = listSemanticCacheEntries({ page, limit, search, model, sortBy, sortOrder });
|
|
|
|
return NextResponse.json({
|
|
entries,
|
|
pagination: {
|
|
page,
|
|
limit,
|
|
total,
|
|
totalPages: Math.ceil(total / limit),
|
|
},
|
|
});
|
|
} catch (error) {
|
|
return NextResponse.json({ error: sanitizeErrorMessage(error) }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
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");
|
|
const model = searchParams.get("model");
|
|
|
|
if (signature) {
|
|
const { deleted } = deleteSemanticCacheBySignature(signature);
|
|
return NextResponse.json({ ok: true, deleted });
|
|
}
|
|
|
|
if (model) {
|
|
const { deleted } = deleteSemanticCacheByModel(model);
|
|
return NextResponse.json({ ok: true, deleted });
|
|
}
|
|
|
|
return NextResponse.json({ error: "Provide signature or model parameter" }, { status: 400 });
|
|
} catch (error) {
|
|
return NextResponse.json({ error: sanitizeErrorMessage(error) }, { status: 500 });
|
|
}
|
|
}
|