优化 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'); ctx.throw(401, 'Token is required');
} }
const user = await User.getOauthUser(token); const user = await User.getOauthUser(token);
console.log('auth user: exists', !user);
if (!user) { if (!user) {
ctx.throw(401, 'Token is invalid'); ctx.throw(401, 'Token is invalid');
return; return;
} }
console.log(`auth user: ${user.username} (${user.id})`); // console.log(`auth user: ${user.username} (${user.id})`);
const someInfo = getSomeInfoFromReq(ctx); const someInfo = getSomeInfoFromReq(ctx);
if (someInfo.isBrowser && !ctx.req?.cookies?.['token']) { if (someInfo.isBrowser && !ctx.req?.cookies?.['token']) {
createCookie({ accessToken: token }, ctx); createCookie({ accessToken: token }, ctx);
@@ -87,6 +86,7 @@ app
if (!tokenUser) { if (!tokenUser) {
ctx.throw(401, 'No User For authorized'); ctx.throw(401, 'No User For authorized');
} }
console.log('auth-admin tokenUser', ctx.state);
if (typeof ctx.state.isAdmin !== 'undefined' && ctx.state.isAdmin === true) { if (typeof ctx.state.isAdmin !== 'undefined' && ctx.state.isAdmin === true) {
return; return;
} }
@@ -114,6 +114,7 @@ app
} }
}) })
.addTo(app); .addTo(app);
app app
.route({ .route({
path: 'auth-check', path: 'auth-check',

View File

@@ -3,7 +3,6 @@ import { app, redis } from '@/app.ts';
import fs from 'fs'; import fs from 'fs';
import { fileStore } from '@/modules/config.ts'; import { fileStore } from '@/modules/config.ts';
import { getAppLoadStatus } from '@/modules/user-app/index.ts'; import { getAppLoadStatus } from '@/modules/user-app/index.ts';
import { getLoginUser } from '@/modules/auth.ts';
export class CenterUserApp { export class CenterUserApp {
user: string; user: string;
@@ -55,25 +54,25 @@ export class CenterUserApp {
deleteUserAppFiles(user, app); deleteUserAppFiles(user, app);
} }
} }
app // app
.route({ // .route({
path: 'page-proxy-app', // path: 'page-proxy-app',
key: 'auth-admin', // key: 'auth-admin',
id: 'auth-admin', // id: 'auth-admin',
}) // })
.define(async (ctx) => { // .define(async (ctx) => {
const { user } = ctx.query; // const { user } = ctx.query;
const loginUser = await getLoginUser(ctx.req); // const loginUser = await getLoginUser(ctx.req);
if (loginUser) { // if (loginUser) {
const root = ['admin', 'root']; // const root = ['admin', 'root'];
if (root.includes(loginUser.tokenUser?.username)) { // if (root.includes(loginUser.tokenUser?.username)) {
return; // return;
} // }
ctx.throw(401, 'No Proxy App Permission'); // ctx.throw(401, 'No Proxy App Permission');
} // }
ctx.throw(401, 'No Login And No Proxy App Permission'); // ctx.throw(401, 'No Login And No Proxy App Permission');
}) // })
.addTo(app); // .addTo(app);
app app
.route({ .route({
@@ -81,7 +80,6 @@ app
key: 'list', key: 'list',
middleware: ['auth-admin'], middleware: ['auth-admin'],
description: '获取应用列表', description: '获取应用列表',
isDebug: true,
}) })
.define(async (ctx) => { .define(async (ctx) => {
const keys = await redis.keys('user:app:*'); const keys = await redis.keys('user:app:*');
@@ -101,6 +99,7 @@ app
path: 'page-proxy-app', path: 'page-proxy-app',
key: 'delete', key: 'delete',
middleware: ['auth-admin'], middleware: ['auth-admin'],
description: '删除应用缓存',
}) })
.define(async (ctx) => { .define(async (ctx) => {
const { user, app } = ctx.query; const { user, app } = ctx.query;
@@ -119,6 +118,8 @@ app
.route({ .route({
path: 'page-proxy-app', path: 'page-proxy-app',
key: 'deleteAll', key: 'deleteAll',
middleware: ['auth-admin'],
description: '删除所有应用缓存',
}) })
.define(async (ctx) => { .define(async (ctx) => {
const keys = await redis.keys('user:app:*'); const keys = await redis.keys('user:app:*');
@@ -134,7 +135,9 @@ app
app app
.route({ .route({
path: 'page-proxy-app', path: 'page-proxy-app',
description: '清理所有应用缓存',
key: 'clear', key: 'clear',
middleware: ['auth-admin'],
}) })
.define(async (ctx) => { .define(async (ctx) => {
const keys = await redis.keys('user:app:*'); const keys = await redis.keys('user:app:*');
@@ -153,6 +156,7 @@ app
.route({ .route({
path: 'page-proxy-app', path: 'page-proxy-app',
key: 'get', key: 'get',
description: '获取应用缓存信息',
middleware: ['auth-admin'], middleware: ['auth-admin'],
}) })
.define(async (ctx) => { .define(async (ctx) => {
@@ -178,6 +182,7 @@ app
.route({ .route({
path: 'page-proxy-app', path: 'page-proxy-app',
key: 'status', key: 'status',
description: '获取应用加载状态',
middleware: [], middleware: [],
}) })
.define(async (ctx) => { .define(async (ctx) => {