feat: project list

This commit is contained in:
2025-09-06 01:44:33 +08:00
parent ef473d6084
commit 9b54d18ef3
11 changed files with 333 additions and 56 deletions

View File

@@ -1,3 +1,4 @@
import bodyParser from 'koa-bodyparser';
import type Koa from 'koa';
import type { Middleware } from './types.ts';
@@ -6,41 +7,6 @@ import type { Middleware } from './types.ts';
*/
export class BodyParser implements Middleware {
apply(app: Koa): void {
// 使用动态导入来避免类型问题
app.use(async (ctx, next) => {
if (ctx.request.method === 'POST' ||
ctx.request.method === 'PUT' ||
ctx.request.method === 'PATCH') {
// 简单的JSON解析
if (ctx.request.type === 'application/json') {
try {
const chunks: Buffer[] = [];
ctx.req.on('data', (chunk) => {
chunks.push(chunk);
});
await new Promise((resolve) => {
ctx.req.on('end', () => {
const body = Buffer.concat(chunks).toString();
try {
(ctx.request as any).body = JSON.parse(body);
} catch {
(ctx.request as any).body = {};
}
resolve(void 0);
});
});
} catch (error) {
(ctx.request as any).body = {};
}
} else {
(ctx.request as any).body = {};
}
}
await next();
});
app.use(bodyParser());
}
}

View File

@@ -2,7 +2,7 @@ import KoaRouter from '@koa/router';
import type Koa from 'koa';
import type { Middleware } from './types.ts';
import { RouteScanner } from '../libs/route-scanner.ts';
import { ApplicationController } from '../controllers/application.ts';
import { ProjectController } from '../controllers/project.ts';
import { UserController } from '../controllers/user.ts';
import { AuthController } from '../controllers/auth.ts';
import { log } from '../libs/logger.ts';
@@ -33,7 +33,7 @@ export class Router implements Middleware {
private registerDecoratorRoutes(): void {
// 注册所有使用装饰器的控制器
this.routeScanner.registerControllers([
ApplicationController,
ProjectController,
UserController,
AuthController,
]);