feat(center-nodes): enforce nodeId and endpoint uniqueness

This commit is contained in:
nav
2026-05-12 08:49:34 +00:00
parent 0020df5d5e
commit e381679165
2 changed files with 16 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import {
Body,
ConflictException,
Controller,
ForbiddenException,
Get,
@@ -23,6 +24,20 @@ export class NodesController {
throw new ForbiddenException('invalid shared secret');
}
const existedByNodeId = await this.nodeRepo.findOne({
where: { nodeId: body.nodeId },
});
if (existedByNodeId) {
throw new ConflictException('nodeId already exists');
}
const existedByEndpoint = await this.nodeRepo.findOne({
where: { endpoint: body.endpoint },
});
if (existedByEndpoint) {
throw new ConflictException('endpoint already exists');
}
const node = this.nodeRepo.create({
nodeId: body.nodeId,
name: body.name,

View File

@@ -24,7 +24,7 @@
### 1.2 Guild Node 注册与握手
- [x] `POST /nodes/register` shared-secret 校验
- [ ] node 唯一性校验nodeId/endpoint
- [x] node 唯一性校验nodeId/endpoint
- [ ] node 状态模型active/offline/revoked
- [ ] `GET /nodes` 列表 + 分页
- [ ] node 心跳接口(可选)