ework-web 0.10.49 → 0.10.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +31 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1076,6 +1076,37 @@ async function handle(req: Request, url: URL, ip: string, ctx: { authed: boolean
|
|
|
1076
1076
|
return json({ ok: true, paused: isPause });
|
|
1077
1077
|
}
|
|
1078
1078
|
|
|
1079
|
+
const daemonCapacityRe = /^\/api\/daemons\/(\d+)\/capacity$/;
|
|
1080
|
+
|
|
1081
|
+
if (req.method === "POST" && daemonCapacityRe.test(url.pathname)) {
|
|
1082
|
+
if (!ctx.user || ctx.user.is_admin !== 1) return json({ error: "admin required" }, 403);
|
|
1083
|
+
const match = url.pathname.match(daemonCapacityRe);
|
|
1084
|
+
const id = match ? Number(match[1]) : NaN;
|
|
1085
|
+
if (!Number.isFinite(id)) return json({ error: "invalid id" }, 400);
|
|
1086
|
+
const payload = await req.json().catch(() => ({} as unknown));
|
|
1087
|
+
const value = (payload as { value?: unknown })?.value;
|
|
1088
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 1) {
|
|
1089
|
+
return json({ error: "value must be a positive number" }, 400);
|
|
1090
|
+
}
|
|
1091
|
+
await getDB().run(`UPDATE {{d_daemons}} SET capacity = ? WHERE id = ?`, [Math.floor(value), id]);
|
|
1092
|
+
const rows = await getDB().all<{ endpoint: string }>(
|
|
1093
|
+
`SELECT internal_endpoint AS endpoint FROM {{d_daemons}} WHERE id = ?`, [id]
|
|
1094
|
+
);
|
|
1095
|
+
if (rows.length > 0) {
|
|
1096
|
+
const ep = rows[0]!.endpoint;
|
|
1097
|
+
const proto = ep.startsWith("http") ? "" : "http://";
|
|
1098
|
+
try {
|
|
1099
|
+
await fetch(`${proto}${ep}/api/admin/max-concurrent`, {
|
|
1100
|
+
method: "POST",
|
|
1101
|
+
headers: { "Content-Type": "application/json" },
|
|
1102
|
+
body: JSON.stringify({ value: Math.floor(value) }),
|
|
1103
|
+
signal: AbortSignal.timeout(3000),
|
|
1104
|
+
});
|
|
1105
|
+
} catch { /* daemon will pick up via heartbeat DB sync */ }
|
|
1106
|
+
}
|
|
1107
|
+
return json({ ok: true, capacity: Math.floor(value) });
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1079
1110
|
if (req.method === "POST" && daemonRestartRe.test(url.pathname)) {
|
|
1080
1111
|
if (!ctx.user || ctx.user.is_admin !== 1) return json({ error: "admin required" }, 403);
|
|
1081
1112
|
const match = url.pathname.match(daemonRestartRe);
|