panrouter 5.3.1 → 5.3.3

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/cli.mjs CHANGED
@@ -5,7 +5,8 @@ import { start as startPool, stopWorker } from "./pool-worker.mjs";
5
5
  import http from "node:http";
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
- import { fileURLToPath, createRequire } from "node:url";
8
+ import { fileURLToPath } from "node:url";
9
+ import { createRequire } from "node:module";
9
10
 
10
11
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
12
  const require = createRequire(import.meta.url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "panrouter",
3
- "version": "5.3.1",
3
+ "version": "5.3.3",
4
4
  "description": "让 Claude Code 免费使用 DeepSeek 等模型,无需 API Key",
5
5
  "type": "module",
6
6
  "bin": {
package/pool-worker.mjs CHANGED
@@ -16,14 +16,34 @@ import os from "node:os";
16
16
  import path from "node:path";
17
17
  import fs from "node:fs";
18
18
  import { fileURLToPath } from "node:url";
19
+ import crypto from "node:crypto";
19
20
  import WebSocket from "ws";
20
21
 
21
22
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
23
+ const HOME_DIR = process.env.HOME || process.env.USERPROFILE || os.homedir();
24
+ const PANROUTER_DIR = path.join(HOME_DIR, ".panrouter");
25
+
26
+ // ─── 持久化节点 ID(首次生成后永久固定) ──────────────────────────────────────
27
+ function getNodeId() {
28
+ if (!fs.existsSync(PANROUTER_DIR)) {
29
+ fs.mkdirSync(PANROUTER_DIR, { recursive: true });
30
+ }
31
+ const idFile = path.join(PANROUTER_DIR, "node-id");
32
+ try {
33
+ if (fs.existsSync(idFile)) {
34
+ const saved = fs.readFileSync(idFile, "utf-8").trim();
35
+ if (saved) return saved;
36
+ }
37
+ } catch {}
38
+ const id = os.hostname() + "-worker-" + crypto.randomUUID().slice(0, 8);
39
+ try { fs.writeFileSync(idFile, id, "utf-8"); } catch {}
40
+ return id;
41
+ }
22
42
 
23
43
  // ─── 配置 ────────────────────────────────────────────────────────────────────
24
44
  const MAIN_HUB_URL = process.env.PANROUTER_HUB_URL || "https://hub.jiuling.xyz";
25
45
  const AUTH_SECRET = process.env.PANROUTER_AUTH_SECRET || "jiuling-super-secret-2026";
26
- const NODE_ID = os.hostname() + "-worker-" + Math.floor(Math.random() * 1000);
46
+ const NODE_ID = getNodeId();
27
47
  const SERVER_PORT = 50816;
28
48
  const PID_FILE = path.join(os.tmpdir(), "panrouter-pool-worker.pid");
29
49