feat: 更新获取配置接口,增加动态获取访问地址功能
This commit is contained in:
@@ -381,13 +381,22 @@ export class AssistantConfig {
|
||||
protected getDefaultInitAssistantConfig() {
|
||||
const id = randomId();
|
||||
const isCNB = !!useKey('CNB');
|
||||
let kevisualUrl = 'https://kevisual.cn';
|
||||
if (isCNB) {
|
||||
const uri = getCNBUrl();
|
||||
if (uri) {
|
||||
kevisualUrl = uri;
|
||||
} else {
|
||||
kevisualUrl = 'http://kevisual.cn';
|
||||
}
|
||||
}
|
||||
return {
|
||||
app: {
|
||||
url: 'https://kevisual.cn',
|
||||
url: kevisualUrl,
|
||||
id,
|
||||
},
|
||||
description: '助手配置文件',
|
||||
docs: "https://kevisual.cn/root/cli/docs/",
|
||||
docs: `${kevisualUrl}/root/cli/docs/`,
|
||||
home: isCNB ? '/root/cli-center' : '/root/home',
|
||||
proxy: [],
|
||||
share: {
|
||||
@@ -414,3 +423,13 @@ export const parseIfJson = (content: string) => {
|
||||
export * from './args.ts';
|
||||
|
||||
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
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { app, assistantConfig } from '@/app.ts';
|
||||
import { reload } from '../../module/reload-server.ts';
|
||||
import { useKey } from '@kevisual/context';
|
||||
import { getCNBUrl } from '@/lib.ts';
|
||||
|
||||
app
|
||||
.route({
|
||||
@@ -29,13 +31,15 @@ app
|
||||
app.route({
|
||||
path: 'config',
|
||||
key: 'getId',
|
||||
description: '获取appId',
|
||||
description: '获取appId和访问地址',
|
||||
|
||||
}).define(async (ctx) => {
|
||||
const config = assistantConfig.getCacheAssistantConfig();
|
||||
const appId = config?.app?.id || null;
|
||||
let kevisualUrl = getCNBUrl() || 'https://kevisual.cn';
|
||||
ctx.body = {
|
||||
id: appId,
|
||||
url: kevisualUrl,
|
||||
}
|
||||
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user