From d56c4c15f2040db2dafbbe75430579bcbd222418 Mon Sep 17 00:00:00 2001 From: xion Date: Sun, 23 Mar 2025 12:17:06 +0800 Subject: [PATCH] fix: update login error --- package.json | 4 ++-- pnpm-lock.yaml | 25 +++++++------------------ src/command/login.ts | 12 ++++++++++-- src/command/ls-token.ts | 2 +- src/command/me.ts | 19 ------------------- src/index.ts | 1 - src/module/query.ts | 15 ++++----------- submodules/kevisual-query-login | 2 +- 8 files changed, 25 insertions(+), 55 deletions(-) delete mode 100644 src/command/me.ts diff --git a/package.json b/package.json index c4b15b3..4ba1b31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/envision-cli", - "version": "0.0.33", + "version": "0.0.34", "description": "envision command tools", "main": "dist/app.mjs", "type": "module", @@ -33,7 +33,7 @@ ], "author": "abearxiong", "devDependencies": { - "@kevisual/query": "0.0.13", + "@kevisual/query": "0.0.15", "@kevisual/query-login": "workspace:*", "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-commonjs": "^28.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bda333a..ce2a907 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,8 +37,8 @@ importers: version: 6.2.2(@types/node@22.13.11) devDependencies: '@kevisual/query': - specifier: 0.0.13 - version: 0.0.13(encoding@0.1.13)(ws@8.18.0) + specifier: 0.0.15 + version: 0.0.15(encoding@0.1.13)(ws@8.18.0) '@kevisual/query-login': specifier: workspace:* version: link:submodules/kevisual-query-login @@ -118,8 +118,8 @@ importers: specifier: ^0.0.1 version: 0.0.1(rollup@4.36.0)(tslib@2.8.1)(typescript@5.8.2) '@kevisual/query': - specifier: ^0.0.12 - version: 0.0.12(encoding@0.1.13)(ws@8.18.0) + specifier: ^0.0.15 + version: 0.0.15(encoding@0.1.13)(ws@8.18.0) dotenv: specifier: ^16.4.7 version: 16.4.7 @@ -447,11 +447,8 @@ packages: '@kevisual/load@0.0.6': resolution: {integrity: sha512-+3YTFehRcZ1haGel5DKYMUwmi5i6f2psyaPZlfkKU/cOXgkpwoG9/BEqPCnPjicKqqnksEpixVRkyHJ+5bjLVA==} - '@kevisual/query@0.0.12': - resolution: {integrity: sha512-/1lZJhNCdcNG4a2Nncl55XC/nha5+GZiJPQdP77lufv2dnZfcssA7NHSZ2Ubh0Pm0HWV22IiGfQMiaYl2pkK1Q==} - - '@kevisual/query@0.0.13': - resolution: {integrity: sha512-gSEIDiCvwSaLLAFZv4vam4wSrMsaCuQ3VGjE3kwRwZ8urlVH1TOA+NUO908A22p9m1Iij7Y1Q/JlfSJi2QzuKQ==} + '@kevisual/query@0.0.15': + resolution: {integrity: sha512-DK41qvyOiJMmlj70QyVP/48M0gszA39DdnBLtgU94YwAe6OqKrr9tYXHLjZrOROmUVMezIIBQuWMLedSAvb54A==} '@kevisual/router@0.0.9': resolution: {integrity: sha512-qPyC2GVJ7iOIdJCCKNDsWMAKOQeSJW9HBpL5ZWKHTbi+t4jJBGTzIlXmjKeMHRd0lr/Qq1imQvlkSh4hlrbodA==} @@ -2244,15 +2241,7 @@ snapshots: dependencies: eventemitter3: 5.0.1 - '@kevisual/query@0.0.12(encoding@0.1.13)(ws@8.18.0)': - dependencies: - openai: 4.88.0(encoding@0.1.13)(ws@8.18.0) - transitivePeerDependencies: - - encoding - - ws - - zod - - '@kevisual/query@0.0.13(encoding@0.1.13)(ws@8.18.0)': + '@kevisual/query@0.0.15(encoding@0.1.13)(ws@8.18.0)': dependencies: openai: 4.88.0(encoding@0.1.13)(ws@8.18.0) transitivePeerDependencies: diff --git a/src/command/login.ts b/src/command/login.ts index f6999c1..124d442 100644 --- a/src/command/login.ts +++ b/src/command/login.ts @@ -65,7 +65,10 @@ const loginCommand = new Command('login') program.addCommand(loginCommand); const showMe = async (show = true) => { - const me = await queryLogin.getMe(); + let me = await queryLogin.getMe(); + if (me.code === 401) { + me = await queryLogin.getMe(); + } if (show) { console.log('Me', me.data); } @@ -84,7 +87,12 @@ const switchOrgCommand = new Command('switch').argument('', 'Switch to program.addCommand(switchOrgCommand); const command = new Command('me').description('').action(async () => { - await showMe(); + try { + const res = await showMe(false); + console.log('me', res?.data); + } catch (error) { + console.log('me error', error); + } }); program.addCommand(command); diff --git a/src/command/ls-token.ts b/src/command/ls-token.ts index c53f64d..1212b7d 100644 --- a/src/command/ls-token.ts +++ b/src/command/ls-token.ts @@ -12,7 +12,7 @@ const tokenList = new Command('list') .description('show token list') // .option('-r --remove ', 'remove token by number') .action(async (opts) => { - const res = queryLogin.cache.cache.cacheData; + const res = queryLogin.cacheStore.cacheData; console.log(util.inspect(res, { colors: true, depth: 4 })); }); token.addCommand(tokenList); diff --git a/src/command/me.ts b/src/command/me.ts deleted file mode 100644 index d16347f..0000000 --- a/src/command/me.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { program as app, Command } from '@/program.ts'; -import { getConfig, writeConfig } from '@/module/index.ts'; -import {queryMe} from '../query/index.ts'; - - -// const command = new Command('me') -// .description('') -// .action(async () => { -// const config = getConfig() -// const res = await queryMe(); -// if(res.code===200) { -// console.log('me', res.data) -// } else { -// console.log('not login') -// writeConfig({ ...config, token: '' }); -// } -// }); - -// app.addCommand(command); diff --git a/src/index.ts b/src/index.ts index c6155f0..1abf0ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ import { program } from '@/program.ts'; import './command/login.ts'; import './command/logout.ts'; import './command/ls-token.ts'; -import './command/me.ts'; import './command/deploy.ts'; import './command/serve.ts'; import './command/config.ts'; diff --git a/src/module/query.ts b/src/module/query.ts index b1095f0..f24ac03 100644 --- a/src/module/query.ts +++ b/src/module/query.ts @@ -34,20 +34,13 @@ query.beforeRequest = async (config) => { }; query.afterResponse = async (response, ctx) => { if (response.code === 401) { - if (query.stop) { - return { - code: 500, - message: '登录已过期', - }; - } - query.stop = true; - const res = await queryLogin.afterCheck401ToRefreshToken(response, ctx); - query.stop = false; - return res; + console.log('401 after', response); } return response as any; }; export const queryLogin = new QueryLoginNode({ query: query as any, - onLoad: async () => {}, + onLoad: async () => { + // console.log('onLoad'); + }, }); diff --git a/submodules/kevisual-query-login b/submodules/kevisual-query-login index af8ed90..54672a5 160000 --- a/submodules/kevisual-query-login +++ b/submodules/kevisual-query-login @@ -1 +1 @@ -Subproject commit af8ed90ab3f5a0b558c410f5a0f40d5fb7eaa6d6 +Subproject commit 54672a5574d359220e26ec17c69f567f130d9498