Compare commits

...

2 Commits

Author SHA1 Message Date
48f2695367 fix: 修改未登录状态下的返回值,提供更明确的错误信息 2025-12-15 23:06:21 +08:00
7d4bc37c09 update 2025-12-15 23:02:06 +08:00
6 changed files with 48 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
export type ProxyInfo = {
/**
* 代理路径, 比如/root/center, 匹配的路径
* 代理路径, 比如/root/home, 匹配的路径
*/
path?: string;
/**

View File

@@ -2,7 +2,7 @@ import { LocalProxy, LocalProxyOpts } from './index.ts';
import http from 'node:http';
import { fileProxy } from './proxy/file-proxy.ts';
const localProxy = new LocalProxy({});
let home = '/root/center';
let home = '/root/home';
export const initProxy = (data: LocalProxyOpts & { home?: string }) => {
localProxy.pagesDir = data.pagesDir || '';
localProxy.watch = data.watch ?? false;

View File

@@ -1,6 +1,6 @@
export type ProxyInfo = {
/**
* 代理路径, 比如/root/center, 匹配的路径
* 代理路径, 比如/root/home, 匹配的路径
*/
path?: string;
/**

View File

@@ -10,6 +10,7 @@ export type AssistantInitOptions = {
path?: string;
init?: boolean;
};
const randomId = () => Math.random().toString(36).substring(2, 8);
/**
* 助手初始化类
* @class AssistantInit
@@ -41,6 +42,7 @@ export class AssistantInit extends AssistantConfig {
this.createEnvConfig();
this.createOtherConfig();
this.initPnpm();
this.initIgnore();
}
get query() {
if (!this.#query) {
@@ -153,10 +155,46 @@ export class AssistantInit extends AssistantConfig {
create,
};
}
initIgnore() {
const gitignorePath = path.join(this.configDir, '.gitignore');
let content = '';
if (checkFileExists(gitignorePath, true)) {
content = fs.readFileSync(gitignorePath, 'utf-8');
}
const ignoreLines = [
'node_modules',
'.DS_Store',
'dist',
'pack-dist',
'cache-file',
'build',
'apps/**/node_modules/',
'pages/**/node_modules/',
'.env',
'!.env*development',
'.pnpm-store',
'.vite',
'.astro'
];
let updated = false;
ignoreLines.forEach((line) => {
if (!content.includes(line)) {
content += `\n${line}`;
updated = true;
}
});
if (updated) {
fs.writeFileSync(gitignorePath, content.trim() + '\n');
console.log(chalk.green('.gitignore 文件更新成功'));
}
}
protected getDefaultInitAssistantConfig() {
const id = randomId();
return {
id,
description: '助手配置文件',
home: '/root/center',
docs: "https://kevisual.cn/root/cli-docs/",
home: '/root/home',
proxy: [],
apiProxyList: [],
share: {

View File

@@ -58,7 +58,7 @@ export const proxyRoute = async (req: http.IncomingMessage, res: http.ServerResp
return res.end(`Not Found [${proxyApi.path}] rootPath`);
}
return fileProxy(req, res, {
path: proxyApi.path, // 代理路径, 比如/root/center
path: proxyApi.path, // 代理路径, 比如/root/home
rootPath: proxyApi.rootPath,
...proxyApi,
indexPath: _indexPath, // 首页路径

View File

@@ -79,10 +79,10 @@ const showMe = async (show = true) => {
const localToken = storage.getItem('token');
if (!token && !localToken) {
console.log('请先登录');
return;
return { code: 40400, message: '请先登录' };
}
let me = await queryLogin.getMe(token);
if (me.code === 401) {
if (me?.code === 401) {
me = await queryLogin.getMe();
}
if (show) {
@@ -113,6 +113,9 @@ const command = new Command('me')
res = await showMe(false);
isRefresh = true;
}
if (res.code === 40400) {
return
}
if (res.code === 200) {
if (isRefresh) {
console.log(chalk.green('refresh token success'), '\n');