From 2fd473a1b13313c4c6e5e22ec1e984485812c59f Mon Sep 17 00:00:00 2001 From: abearxiong Date: Tue, 31 Mar 2026 02:05:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=90=8D=E7=A7=B0=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20CLI=20=E5=85=A5=E5=8F=A3=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=94=A8=E6=88=B7=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/auth/oauth/oauth.ts | 1 - src/cli.ts | 8 ++++++++ src/modules/auth.ts | 2 ++ src/modules/v1-ws-proxy/index.ts | 1 - 5 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/cli.ts diff --git a/package.json b/package.json index 636c2a8..5cd288d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "scripts": { "dev": "bun run --watch --hot src/index.ts", - "cmd": "bun run src/run.ts ", + "cli": "bun run src/cli.ts ", "prebuild": "rimraf dist && rimraf pack-dist", "build": "NODE_ENV=production bun bun.config.mjs", "postbuild": "ev pack", diff --git a/src/auth/oauth/oauth.ts b/src/auth/oauth/oauth.ts index 2413a6c..95cd9d3 100644 --- a/src/auth/oauth/oauth.ts +++ b/src/auth/oauth/oauth.ts @@ -166,7 +166,6 @@ export class RedisTokenStore implements Store { } else { expire = Math.min(expire, 60 * 60 * 24 * 30); // 默认的过期时间最大为30天 } - await this.set(accessToken, JSON.stringify(value), expire); await this.set(userPrefix + ':token:' + accessToken, accessToken, expire); // refreshToken的过期时间比accessToken多expireDay天,确保在accessToken过期后,refreshToken仍然有效 diff --git a/src/cli.ts b/src/cli.ts new file mode 100644 index 0000000..611cbe8 --- /dev/null +++ b/src/cli.ts @@ -0,0 +1,8 @@ +import { parse } from '@kevisual/router/commander' + +import { app } from './app.ts'; +import './route.ts'; + +parse({ + app, +}) \ No newline at end of file diff --git a/src/modules/auth.ts b/src/modules/auth.ts index f9baf61..39cd219 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -52,6 +52,7 @@ export const getLoginUserByToken = async (token: string) => { let tokenUser; try { tokenUser = await User.verifyToken(token); + if (!tokenUser) return null; return { tokenUser, token }; } catch (e) { return null; @@ -66,6 +67,7 @@ export const getLoginUser = async (req: http.IncomingMessage) => { logger.debug('getLoginUser', token); try { tokenUser = await User.verifyToken(token); + if (!tokenUser) return null; return { tokenUser, token }; } catch (e) { return null; diff --git a/src/modules/v1-ws-proxy/index.ts b/src/modules/v1-ws-proxy/index.ts index 90c7c29..033a537 100644 --- a/src/modules/v1-ws-proxy/index.ts +++ b/src/modules/v1-ws-proxy/index.ts @@ -26,7 +26,6 @@ export const wssFun: WebSocketListenerFun = async (req, res) => { } if (!user) { logger.debug('未提供用户名,无法注册 ws 连接'); - ws.close(); return; } let userApp = user + '--' + id;