Skip to content

Commit

Permalink
fix: 修复节点被 ban 仍然分发流量的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
SALTWOOD committed Sep 30, 2024
1 parent 6b8fc67 commit 7e4b213
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/FileList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class FileList {
const availableClusters: ClusterEntity[] = [];
const values = clusters? clusters : this._clusters;

for (const cluster of values.filter(c => c.isOnline)) {
for (const cluster of values.filter(c => c.isOnline && !(c.isBanned))) {
if (FileList.availableInCluster(file, cluster)) {
availableClusters.push(cluster);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,23 @@ export class Server {
return;
}
cluster.isBanned = Number(data.ban);
cluster.doOffline("This cluster is banned.");
this.db.update(cluster);
res.setHeader('Content-Type', 'application/json');
res.status(200).json(cluster.getJson(true, false));
});
this.app.post('/93AtHome/super/cluster/kick', (req: Request, res: Response) => {
if (!Utilities.verifyAdmin(req, res, this.db)) return;
const clusterId = req.query.clusterId as string || "";
const cluster = this.clusters.find(c => c.clusterId === clusterId);
if (!cluster) {
res.status(404).send(); // 集群不存在
return;
}
cluster.doOffline("Operator kicked this cluster.");
this.db.update(cluster);
res.status(200).json(cluster.getJson(true, false));
});
this.app.post('/93AtHome/super/cluster/profile', (req: Request, res: Response) => {
if (!Utilities.verifyAdmin(req, res, this.db)) return;
const userId = JwtHelper.getInstance().verifyToken(req.cookies.token, 'user') as { userId: number };
Expand Down Expand Up @@ -1035,6 +1048,7 @@ export class Server {
}
else if (cluster?.isBanned) {
socket.send("This cluster is banned.");
cluster.doOffline("This cluster is banned.");
}
ack([null, false]);
}
Expand Down

0 comments on commit 7e4b213

Please sign in to comment.