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

@@ -20,7 +20,7 @@ export class AuthController {
if (!ctx.session.isNew) {
return ctx.session.user;
}
const { code } = (ctx.request as any).body;
const { code } = ctx.request.body as LoginRequestBody;
const { access_token } = await gitea.getToken(code);
const giteaUser = await gitea.getUserInfo(access_token);
log.debug(this.TAG, 'gitea user: %o', giteaUser);
@@ -64,3 +64,7 @@ export class AuthController {
return ctx.session.user;
}
}
interface LoginRequestBody {
code: string;
}

View File

@@ -4,8 +4,8 @@ import { log } from '../libs/logger.ts';
import { BusinessError } from '../middlewares/exception.ts';
import { Controller, Get } from '../decorators/route.ts';
@Controller('/application')
export class ApplicationController {
@Controller('/project')
export class ProjectController {
@Get('/list')
async list(ctx: Context) {
log.debug('app', 'session %o', ctx.session);

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,
]);

View File

@@ -14,6 +14,7 @@
"@koa/router": "^14.0.0",
"@prisma/client": "^6.15.0",
"koa": "^3.0.1",
"koa-bodyparser": "^4.4.1",
"koa-session": "^7.0.2",
"pino": "^9.9.1",
"pino-pretty": "^13.1.1"
@@ -22,6 +23,7 @@
"@tsconfig/node-ts": "^23.6.1",
"@tsconfig/node22": "^22.0.2",
"@types/koa": "^3.0.0",
"@types/koa-bodyparser": "^4.3.12",
"@types/koa__cors": "^5.0.0",
"@types/koa__router": "^12.0.4",
"@types/node": "^24.3.0",