From c3624a59de50b88d7f099e84789c751300184dfe Mon Sep 17 00:00:00 2001 From: abearxiong Date: Mon, 26 Jan 2026 20:53:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20auth=20=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=EF=BC=9B?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=AE=9A=E4=B9=89=EF=BC=9B=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=20page-proxy-app=20=E8=B7=AF=E7=94=B1=E7=9A=84=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E5=92=8C=E4=B8=AD=E9=97=B4=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/route.ts | 5 +-- src/routes/app-manager/proxy/list.ts | 47 +++++++++++++++------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/route.ts b/src/route.ts index 6de1a81..5d15fab 100644 --- a/src/route.ts +++ b/src/route.ts @@ -29,12 +29,11 @@ export const addAuth = (app: App) => { ctx.throw(401, 'Token is required'); } const user = await User.getOauthUser(token); - console.log('auth user: exists', !user); if (!user) { ctx.throw(401, 'Token is invalid'); return; } - console.log(`auth user: ${user.username} (${user.id})`); + // console.log(`auth user: ${user.username} (${user.id})`); const someInfo = getSomeInfoFromReq(ctx); if (someInfo.isBrowser && !ctx.req?.cookies?.['token']) { createCookie({ accessToken: token }, ctx); @@ -87,6 +86,7 @@ app if (!tokenUser) { ctx.throw(401, 'No User For authorized'); } + console.log('auth-admin tokenUser', ctx.state); if (typeof ctx.state.isAdmin !== 'undefined' && ctx.state.isAdmin === true) { return; } @@ -114,6 +114,7 @@ app } }) .addTo(app); + app .route({ path: 'auth-check', diff --git a/src/routes/app-manager/proxy/list.ts b/src/routes/app-manager/proxy/list.ts index 94ed347..70759f0 100644 --- a/src/routes/app-manager/proxy/list.ts +++ b/src/routes/app-manager/proxy/list.ts @@ -3,7 +3,6 @@ import { app, redis } from '@/app.ts'; import fs from 'fs'; import { fileStore } from '@/modules/config.ts'; import { getAppLoadStatus } from '@/modules/user-app/index.ts'; -import { getLoginUser } from '@/modules/auth.ts'; export class CenterUserApp { user: string; @@ -55,25 +54,25 @@ export class CenterUserApp { deleteUserAppFiles(user, app); } } -app - .route({ - path: 'page-proxy-app', - key: 'auth-admin', - id: 'auth-admin', - }) - .define(async (ctx) => { - const { user } = ctx.query; - const loginUser = await getLoginUser(ctx.req); - if (loginUser) { - const root = ['admin', 'root']; - if (root.includes(loginUser.tokenUser?.username)) { - return; - } - ctx.throw(401, 'No Proxy App Permission'); - } - ctx.throw(401, 'No Login And No Proxy App Permission'); - }) - .addTo(app); +// app +// .route({ +// path: 'page-proxy-app', +// key: 'auth-admin', +// id: 'auth-admin', +// }) +// .define(async (ctx) => { +// const { user } = ctx.query; +// const loginUser = await getLoginUser(ctx.req); +// if (loginUser) { +// const root = ['admin', 'root']; +// if (root.includes(loginUser.tokenUser?.username)) { +// return; +// } +// ctx.throw(401, 'No Proxy App Permission'); +// } +// ctx.throw(401, 'No Login And No Proxy App Permission'); +// }) +// .addTo(app); app .route({ @@ -81,7 +80,6 @@ app key: 'list', middleware: ['auth-admin'], description: '获取应用列表', - isDebug: true, }) .define(async (ctx) => { const keys = await redis.keys('user:app:*'); @@ -101,6 +99,7 @@ app path: 'page-proxy-app', key: 'delete', middleware: ['auth-admin'], + description: '删除应用缓存', }) .define(async (ctx) => { const { user, app } = ctx.query; @@ -119,6 +118,8 @@ app .route({ path: 'page-proxy-app', key: 'deleteAll', + middleware: ['auth-admin'], + description: '删除所有应用缓存', }) .define(async (ctx) => { const keys = await redis.keys('user:app:*'); @@ -134,7 +135,9 @@ app app .route({ path: 'page-proxy-app', + description: '清理所有应用缓存', key: 'clear', + middleware: ['auth-admin'], }) .define(async (ctx) => { const keys = await redis.keys('user:app:*'); @@ -153,6 +156,7 @@ app .route({ path: 'page-proxy-app', key: 'get', + description: '获取应用缓存信息', middleware: ['auth-admin'], }) .define(async (ctx) => { @@ -178,6 +182,7 @@ app .route({ path: 'page-proxy-app', key: 'status', + description: '获取应用加载状态', middleware: [], }) .define(async (ctx) => {