9router/src/app/api/combos/route.js
decolua 8f81363675 Enhance token refresh functionality across multiple executors
- Updated refreshCredentials methods in various executors (Antigravity, Base, Default, Github, Kiro) to accept optional proxyOptions for improved proxy handling.
- Modified token refresh logic to utilize proxy-aware fetch for better network management.
- Enhanced usage retrieval functions to support proxy options, ensuring seamless integration with proxy configurations.
- Updated ModelSelectModal and ProviderInfoCard components to incorporate kind filtering for improved user experience in model selection.
- Added validation for API keys in the provider validation route, including support for webSearch/webFetch providers.
2026-04-28 17:28:57 +07:00

48 lines
1.5 KiB
JavaScript

import { NextResponse } from "next/server";
import { getCombos, createCombo, getComboByName } from "@/lib/localDb";
export const dynamic = "force-dynamic";
// Validate combo name: only a-z, A-Z, 0-9, -, _
const VALID_NAME_REGEX = /^[a-zA-Z0-9_.\-]+$/;
// GET /api/combos - Get all combos
export async function GET() {
try {
const combos = await getCombos();
return NextResponse.json({ combos });
} catch (error) {
console.log("Error fetching combos:", error);
return NextResponse.json({ error: "Failed to fetch combos" }, { status: 500 });
}
}
// POST /api/combos - Create new combo
export async function POST(request) {
try {
const body = await request.json();
const { name, models, kind } = body;
if (!name) {
return NextResponse.json({ error: "Name is required" }, { status: 400 });
}
// Validate name format
if (!VALID_NAME_REGEX.test(name)) {
return NextResponse.json({ error: "Name can only contain letters, numbers, -, _ and ." }, { status: 400 });
}
// Check if name already exists
const existing = await getComboByName(name);
if (existing) {
return NextResponse.json({ error: "Combo name already exists" }, { status: 400 });
}
const combo = await createCombo({ name, models: models || [], kind: kind || null });
return NextResponse.json(combo, { status: 201 });
} catch (error) {
console.log("Error creating combo:", error);
return NextResponse.json({ error: "Failed to create combo" }, { status: 500 });
}
}