mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-23 04:09:49 +00:00
fix(xiaomi-tokenplan): region selector, key validation, multi-connection (#2251)
- Add top-level regions array so Add/Edit modals render region <Select> - EditConnectionModal: load/persist region generically for region-aware providers - validate: accept 403 for xiaomi-tokenplan valid keys, add 8s fetch timeout - Remove single-connection guard for compatible/embedding nodes Co-authored-by: MiQieR <122154116+MiQieR@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
decolua
co-authored by
Cursor
parent
ce6120ce7b
commit
9102c4c6d8
@@ -126,18 +126,11 @@ export async function POST(request) {
|
||||
|
||||
let providerSpecificData = normalizeProviderSpecificData(provider, body, body.providerSpecificData);
|
||||
|
||||
// Compatible/embedding nodes allow exactly one connection each. These guards were
|
||||
// dropped accidentally during the bun:sqlite refactor (v0.4.28); restored to honor
|
||||
// the contract locked in by tests/unit/compatible-provider-connections.test.js (#925).
|
||||
if (isOpenAICompatibleProvider(provider)) {
|
||||
const node = await getProviderNodeById(provider);
|
||||
if (!node) {
|
||||
return NextResponse.json({ error: "OpenAI Compatible node not found" }, { status: 404 });
|
||||
}
|
||||
const existingConnections = await getProviderConnections({ provider });
|
||||
if (existingConnections.length > 0) {
|
||||
return NextResponse.json({ error: "Only one connection is allowed for this OpenAI Compatible node" }, { status: 400 });
|
||||
}
|
||||
providerSpecificData = {
|
||||
prefix: node.prefix,
|
||||
apiType: node.apiType,
|
||||
@@ -149,10 +142,6 @@ export async function POST(request) {
|
||||
if (!node) {
|
||||
return NextResponse.json({ error: "Anthropic Compatible node not found" }, { status: 404 });
|
||||
}
|
||||
const existingConnections = await getProviderConnections({ provider });
|
||||
if (existingConnections.length > 0) {
|
||||
return NextResponse.json({ error: "Only one connection is allowed for this Anthropic Compatible node" }, { status: 400 });
|
||||
}
|
||||
providerSpecificData = {
|
||||
prefix: node.prefix,
|
||||
baseUrl: node.baseUrl,
|
||||
@@ -163,10 +152,6 @@ export async function POST(request) {
|
||||
if (!node) {
|
||||
return NextResponse.json({ error: "Custom Embedding node not found" }, { status: 404 });
|
||||
}
|
||||
const existingConnections = await getProviderConnections({ provider });
|
||||
if (existingConnections.length > 0) {
|
||||
return NextResponse.json({ error: "Only one connection is allowed for this Custom Embedding node" }, { status: 400 });
|
||||
}
|
||||
providerSpecificData = {
|
||||
prefix: node.prefix,
|
||||
baseUrl: node.baseUrl,
|
||||
|
||||
@@ -380,10 +380,13 @@ export async function POST(request) {
|
||||
};
|
||||
const headers = {};
|
||||
if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
|
||||
const res = await fetch(endpoints[provider], { headers });
|
||||
const res = await fetch(endpoints[provider], { headers, signal: AbortSignal.timeout(8000) });
|
||||
// xai returns 400 for bad key, 403 for valid-but-no-credit. Other providers use 401.
|
||||
if (provider === "xai") {
|
||||
isValid = res.status === 200 || res.status === 403;
|
||||
} else if (provider === "xiaomi-tokenplan") {
|
||||
// /models returns 403 for valid keys lacking list permission; only 401 means invalid
|
||||
isValid = res.status !== 401;
|
||||
} else {
|
||||
isValid = res.ok;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user