From 5ccb5ba707bb69fcb367c98c501759a53ce486ca Mon Sep 17 00:00:00 2001 From: SALTWOOD <105980161+SALTWOOD@users.noreply.github.com> Date: Fri, 1 Nov 2024 20:08:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20ApiAdmin=20=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/ApiAdmin.ts | 7 ++----- src/routes/ApiClusters.ts | 30 ++++++++++++++++++++++++++++++ src/routes/ApiV1.txt | 29 ----------------------------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/routes/ApiAdmin.ts b/src/routes/ApiAdmin.ts index e473e80..617af16 100644 --- a/src/routes/ApiAdmin.ts +++ b/src/routes/ApiAdmin.ts @@ -60,11 +60,6 @@ export class ApiAdmin { }); inst.app.post("/api/admin/update", async (req, res) => { - const user = inst.db.getEntity(UserEntity, (JwtHelper.instance.verifyToken(req.cookies.adminToken, 'admin') as { userId: number }).userId); - if (!user) { - res.status(401).send(); - return; - } if (inst.server.isUpdating) { res.status(409).send({ success: false, @@ -77,5 +72,7 @@ export class ApiAdmin { success: true }); }); + + inst.app.get("/api/admin/all_users", async (req, res) => { res.json(inst.db.getEntities(UserEntity)) }); } } \ No newline at end of file diff --git a/src/routes/ApiClusters.ts b/src/routes/ApiClusters.ts index 564d78c..6f38c7e 100644 --- a/src/routes/ApiClusters.ts +++ b/src/routes/ApiClusters.ts @@ -125,5 +125,35 @@ export class ApiClusters { inst.db.update(cluster); res.json({ success: true }); }); + + inst.app.get("/api/clusters/:id/shards", async (req, res) => { + if (!Utilities.verifyAdmin(req, res, inst.db)) return; + const cluster = inst.clusters.find(c => c.clusterId === req.params.id); + if (!cluster) { + res.status(404).send(); // 集群不存在 + return; + } + res.status(200).json({ shards: cluster.shards }); + }); + inst.app.put("/api/clusters/:id/shards", async (req, res) => { + if (!Utilities.verifyAdmin(req, res, inst.db)) return; + const cluster = inst.clusters.find(c => c.clusterId === req.query.clusterId); + if (!cluster) { + res.status(404).send(); // 集群不存在 + return; + } + // 判断 shards 是不是在 int 范围内 + const shards = Number(req.body.shards); + if (shards < 0 || shards > 1000) { + res.status(400).send({ + message: "Shards must be between 0 and 1000" + }); + return; + } + cluster.shards = shards; + inst.db.update(cluster); + res.setHeader('Content-Type', 'application/json'); + res.status(200).json(cluster.getJson(true, false)); + }); } } \ No newline at end of file diff --git a/src/routes/ApiV1.txt b/src/routes/ApiV1.txt index 73b89f0..47476f7 100644 --- a/src/routes/ApiV1.txt +++ b/src/routes/ApiV1.txt @@ -561,33 +561,4 @@ }); this.app.get('/93AtHome/syncSources', (req: Request, res: Response) => { res.status(200).json(this.sources); - }); - this.app.get('/93AtHome/super/list_users', (req: Request, res: Response) => { - if (!Utilities.verifyAdmin(req, res, this.db)) return; - const users = this.db.getEntities(UserEntity); - res.status(200).json(users); - }) - this.app.get('/93AtHome/shards', (req: Request, res: Response) => { - if (!Utilities.verifyAdmin(req, res, this.db)) return; - res.json(this.fileList.shards); - }); - this.app.post('/93AtHome/super/modify_shards', (req: Request, res: Response) => { - if (!Utilities.verifyAdmin(req, res, this.db)) return; - const cluster = this.clusters.find(c => c.clusterId === req.query.clusterId); - if (!cluster) { - res.status(404).send(); // 集群不存在 - return; - } - // 判断 shards 是不是在 int 范围内 - const shards = Number(req.body.shards); - if (shards < 0 || shards > 1000) { - res.status(400).send({ - message: "Shards must be between 0 and 1000" - }); - return; - } - cluster.shards = shards; - this.db.update(cluster); - res.setHeader('Content-Type', 'application/json'); - res.status(200).json(cluster.getJson(true, false)); }); \ No newline at end of file