更新 CNB 配置获取逻辑,修复未授权问题,添加测试文件

This commit is contained in:
xiongxiao
2026-03-13 04:33:16 +08:00
committed by cnb
parent cda1d0dc8f
commit d9fda44e78
4 changed files with 15 additions and 4 deletions

View File

@@ -4,7 +4,9 @@ import { useKey } from '@kevisual/context';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
export const getConfig = async (opts: { token?: string }) => {
const kevisualEnv = useKey('KEVISUAL_ENV')
const baseUrl = kevisualEnv === 'production' ? 'https://kevisual.cn/api/router' : 'https://kevisual.xiongxiao.me/api/router';
const isCNB = useKey('CNB');
let isProduction = kevisualEnv !== 'development' || (isCNB && !kevisualEnv);
const baseUrl = isProduction ? 'https://kevisual.cn/api/router' : 'https://kevisual.xiongxiao.me/api/router';
const res = await fetch(baseUrl, {
method: 'POST',
body: JSON.stringify({
@@ -70,6 +72,8 @@ export class CNBManager {
if (token) {
return this.addCNB({ username, token, cookie })
}
} else {
console.error('获取 CNB 配置失败', username, res)
}
return null
}