|
1 | 1 | // Fake CLIProxyAPI management API serving the Limits scenarios in scenarios.json. |
2 | 2 | // Usage: node hub.mjs <state.json> [port]. state.json is {"scenario": "A", "n0": <epoch ms>}; |
3 | 3 | // it is re-read on every request, so edit it and press Refresh limits to switch scenarios. |
4 | | -import { readFileSync } from "node:fs"; |
5 | | -import { createServer } from "node:http"; |
| 4 | +import * as NodeFS from "node:fs"; |
| 5 | +import * as NodeHttp from "node:http"; |
6 | 6 |
|
7 | 7 | const [statePath, port = "18517"] = process.argv.slice(2); |
8 | 8 | if (!statePath) throw new Error("usage: node hub.mjs <state.json> [port]"); |
9 | | -const scenarios = JSON.parse(readFileSync(new URL("./scenarios.json", import.meta.url), "utf8")); |
| 9 | +const scenarios = JSON.parse( |
| 10 | + NodeFS.readFileSync(new URL("./scenarios.json", import.meta.url), "utf8"), |
| 11 | +); |
10 | 12 | const MINUTE = 60_000; |
11 | 13 |
|
12 | 14 | // A window is [usedPercent, minutesFromN0 | null]; null is unknown reset timing. |
@@ -52,11 +54,11 @@ const json = (response, body) => { |
52 | 54 | response.end(JSON.stringify(body)); |
53 | 55 | }; |
54 | 56 |
|
55 | | -createServer((request, response) => { |
| 57 | +NodeHttp.createServer((request, response) => { |
56 | 58 | let raw = ""; |
57 | 59 | request.on("data", (chunk) => (raw += chunk)); |
58 | 60 | request.on("end", () => { |
59 | | - const { scenario, n0 } = JSON.parse(readFileSync(statePath, "utf8")); |
| 61 | + const { scenario, n0 } = JSON.parse(NodeFS.readFileSync(statePath, "utf8")); |
60 | 62 | const accounts = scenarios[scenario]; |
61 | 63 | if (!accounts) return json(response, { files: [] }); |
62 | 64 | if (request.url.endsWith("/v0/management/auth-files")) { |
|
0 commit comments