feat(center-nodes): add paginated node listing

This commit is contained in:
nav
2026-05-12 08:51:01 +00:00
parent e381679165
commit e10d225063
2 changed files with 22 additions and 4 deletions

View File

@@ -2,9 +2,12 @@ import {
Body,
ConflictException,
Controller,
DefaultValuePipe,
ForbiddenException,
Get,
ParseIntPipe,
Post,
Query,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
@@ -59,10 +62,25 @@ export class NodesController {
}
@Get()
async list() {
const items = await this.nodeRepo.find({
async list(
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
@Query('pageSize', new DefaultValuePipe(20), ParseIntPipe) pageSize: number,
) {
const safePage = page < 1 ? 1 : page;
const safePageSize = pageSize < 1 ? 20 : Math.min(pageSize, 100);
const [items, total] = await this.nodeRepo.findAndCount({
order: { createdAt: 'DESC' },
skip: (safePage - 1) * safePageSize,
take: safePageSize,
});
return { items };
return {
items,
page: safePage,
pageSize: safePageSize,
total,
totalPages: Math.max(1, Math.ceil(total / safePageSize)),
};
}
}

View File

@@ -26,7 +26,7 @@
- [x] `POST /nodes/register` shared-secret 校验
- [x] node 唯一性校验nodeId/endpoint
- [ ] node 状态模型active/offline/revoked
- [ ] `GET /nodes` 列表 + 分页
- [x] `GET /nodes` 列表 + 分页
- [ ] node 心跳接口(可选)
### 1.3 Center 运维能力