feat: 更新获取配置接口,增加动态获取访问地址功能

This commit is contained in:
2026-02-28 04:33:24 +08:00
parent acd88fb815
commit 73d0fb9730
2 changed files with 28 additions and 5 deletions

View File

@@ -381,13 +381,22 @@ export class AssistantConfig {
protected getDefaultInitAssistantConfig() { protected getDefaultInitAssistantConfig() {
const id = randomId(); const id = randomId();
const isCNB = !!useKey('CNB'); const isCNB = !!useKey('CNB');
let kevisualUrl = 'https://kevisual.cn';
if (isCNB) {
const uri = getCNBUrl();
if (uri) {
kevisualUrl = uri;
} else {
kevisualUrl = 'http://kevisual.cn';
}
}
return { return {
app: { app: {
url: 'https://kevisual.cn', url: kevisualUrl,
id, id,
}, },
description: '助手配置文件', description: '助手配置文件',
docs: "https://kevisual.cn/root/cli/docs/", docs: `${kevisualUrl}/root/cli/docs/`,
home: isCNB ? '/root/cli-center' : '/root/home', home: isCNB ? '/root/cli-center' : '/root/home',
proxy: [], proxy: [],
share: { share: {
@@ -413,4 +422,14 @@ export const parseIfJson = (content: string) => {
export * from './args.ts'; export * from './args.ts';
const randomId = () => Math.random().toString(36).substring(2, 8); const randomId = () => Math.random().toString(36).substring(2, 8);
export const getCNBUrl = () => {
const isCNB = !!useKey('CNB');
const uri = useKey('CNB_VSCODE_PROXY_URI') as string;
if (!isCNB) return null
if (uri) {
return uri.replace('{{port}}', '51515');
}
return null
}

View File

@@ -1,5 +1,7 @@
import { app, assistantConfig } from '@/app.ts'; import { app, assistantConfig } from '@/app.ts';
import { reload } from '../../module/reload-server.ts'; import { reload } from '../../module/reload-server.ts';
import { useKey } from '@kevisual/context';
import { getCNBUrl } from '@/lib.ts';
app app
.route({ .route({
@@ -29,13 +31,15 @@ app
app.route({ app.route({
path: 'config', path: 'config',
key: 'getId', key: 'getId',
description: '获取appId', description: '获取appId和访问地址',
}).define(async (ctx) => { }).define(async (ctx) => {
const config = assistantConfig.getCacheAssistantConfig(); const config = assistantConfig.getCacheAssistantConfig();
const appId = config?.app?.id || null; const appId = config?.app?.id || null;
let kevisualUrl = getCNBUrl() || 'https://kevisual.cn';
ctx.body = { ctx.body = {
id: appId, id: appId,
url: kevisualUrl,
} }
}).addTo(app); }).addTo(app);