优化 auth 中间件的日志输出;注释掉未使用的路由定义;更新 page-proxy-app 路由的描述和中间件

This commit is contained in:
2026-01-26 20:53:51 +08:00
parent c4e5668b29
commit c3624a59de
2 changed files with 29 additions and 23 deletions

View File

@@ -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',

View File

@@ -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) => {