fix: 更新 AssistantConfig 以启用共享功能,并优化本地用户检查逻辑
This commit is contained in:
@@ -390,7 +390,7 @@ export class AssistantConfig {
|
||||
home: '/root/home',
|
||||
proxy: [],
|
||||
share: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
url: 'https://kevisual.cn/ws/proxy',
|
||||
},
|
||||
} as AssistantConfigData;
|
||||
|
||||
@@ -301,11 +301,11 @@ const checkLocalUser = async (opts: { assistantApp: AssistantApp }) => {
|
||||
const config = assistantApp.config.getConfig();
|
||||
const auth = config?.auth || {};
|
||||
const isLogin = await assistantQuery.queryLogin.getToken();
|
||||
logger.log('[assistant] 正在检查本地用户登录状态...', auth, '是否已登录', !!isLogin);
|
||||
logger.log('[assistant] 正在检查本地用户登录状态...', 'user', auth.username, '是否已登录', !!isLogin);
|
||||
|
||||
const saveAuth = (auth: typeof config.auth, opts: { appId?: string, username: string; share: 'protected' | 'private' }) => {
|
||||
auth.username = opts.username;
|
||||
auth.share = opts.share;
|
||||
auth.username = auth.username ?? opts.username;
|
||||
auth.share = auth.share ?? opts.share;
|
||||
const app = config?.app || {};
|
||||
if (!app?.id) {
|
||||
app.id = opts.appId || 'dev-cnb'
|
||||
@@ -333,15 +333,23 @@ const checkLocalUser = async (opts: { assistantApp: AssistantApp }) => {
|
||||
const res = await assistantQuery.queryLogin.loginByCnb({ cnbToken })
|
||||
if (res.code === 200) {
|
||||
const userInfo = await assistantQuery.queryLogin.checkLocalUser()
|
||||
saveAuth(auth, { username: userInfo.username, share: 'protected' })
|
||||
if (!userInfo.username) {
|
||||
saveAuth(auth, { username: userInfo.username, share: 'protected' })
|
||||
}
|
||||
return
|
||||
} else {
|
||||
logger.error('CNB登录失败,无法获取用户信息', res);
|
||||
}
|
||||
}
|
||||
const kevisualToken = useKey('KEVISUAL_TOKEN');
|
||||
if (kevisualToken) {
|
||||
const accessToken = useKey('KEVISUAL_TOKEN');
|
||||
if (accessToken) {
|
||||
logger.info('[cnb]检测到 KEVISUAL_TOKEN,正在尝试使用 KEVISUAL_TOKEN 登录...');
|
||||
const res = await assistantQuery.queryLogin.refreshLoginUser(kevisualToken)
|
||||
const res = await assistantQuery.queryLogin.refreshLoginUser({ accessToken, refreshToken: '' })
|
||||
if (res.code === 200) {
|
||||
if (!auth.username) {
|
||||
const userInfo = await assistantQuery.queryLogin.checkLocalUser()
|
||||
saveAuth(auth, { username: userInfo.username, share: 'protected' })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@ import fs from 'node:fs';
|
||||
import glob from 'fast-glob';
|
||||
import { runCode } from './run.ts';
|
||||
const codeDemoId = '0e700dc8-90dd-41b7-91dd-336ea51de3d2'
|
||||
import { filter } from "@kevisual/js-filter";
|
||||
import { getHash, getStringHash } from '../file-hash.ts';
|
||||
import { AssistantConfig } from '@/lib.ts';
|
||||
import { assistantQuery } from '@/app.ts';
|
||||
import { logger } from '../logger.ts';
|
||||
|
||||
const codeDemo = `// 这是一个示例代码文件
|
||||
import {App} from '@kevisual/router';
|
||||
@@ -47,17 +47,17 @@ type LightCodeFile = {
|
||||
export const initLightCode = async (opts: Opts) => {
|
||||
const token = await assistantQuery.getToken();
|
||||
if (!token) {
|
||||
console.error('[light-code] 当前未登录,无法初始化 light-code');
|
||||
logger.error('[light-code] 当前未登录,无法初始化 light-code');
|
||||
return;
|
||||
}
|
||||
// 注册 light-code 路由
|
||||
const config = opts.config as AssistantInit;
|
||||
const app = opts.router;
|
||||
console.log('初始化 light-code 路由');
|
||||
logger.log('[light-code] 初始化 light-code 路由');
|
||||
const query = config.query;
|
||||
const sync = opts.sync ?? 'remote';
|
||||
if (!config || !app) {
|
||||
console.error('[light-code] initLightCode 缺少必要参数, config 或 app');
|
||||
logger.error('[light-code] initLightCode 缺少必要参数, config 或 app');
|
||||
return;
|
||||
}
|
||||
const lightcodeDir = opts.rootPath;
|
||||
|
||||
Reference in New Issue
Block a user