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());
}
}