跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

update-exit-country-list.mjs

38 行 · 1.9 KB历史下载
1#!/usr/bin/env node
2import { createHash } from "node:crypto";
3import { mkdir, writeFile } from "node:fs/promises";
4import { isIPv4 } from "node:net";
5import { resolve } from "node:path";
6
7// Maintainer-only update: pin the reviewed upstream commit; applications never
8// download executable policy or replace this bundled snapshot at runtime.
9const commit = process.argv[2];
10if (!/^[a-f0-9]{40}$/.test(commit || "")) {
11 throw new Error("Usage: node scripts/update-exit-country-list.mjs <upstream-commit-sha>");
12}
13const upstream = "gaoyifan/china-operator-ip";
14const source = `https://raw.githubusercontent.com/${upstream}/${commit}`;
15async function download(name) {
16 const response = await fetch(`${source}/${name}`, { signal: AbortSignal.timeout(30000) });
17 if (!response.ok) throw new Error(`${name}: HTTP ${response.status}`);
18 return response.text();
19}
20const [data, license] = await Promise.all([download("china.txt"), download("LICENSE")]);
21const prefixes = data.trim().split(/\r?\n/);
22if (prefixes.length < 1000 || prefixes.length > 50000) throw new Error("Unexpected mainland prefix count");
23for (const prefix of prefixes) {
24 const [address, bits, extra] = prefix.split("/");
25 if (!isIPv4(address) || !/^[0-9]+$/.test(bits || "") || +bits < 8 || +bits > 32 || extra !== undefined) {
26 throw new Error(`Invalid IPv4 prefix: ${prefix}`);
27 }
28}
29if (!license.includes("MIT License") || !license.includes("Yifan Gao")) throw new Error("Review upstream license before updating");
30const target = resolve(import.meta.dirname, "../internal/exitpolicy/data");
31await mkdir(target, { recursive: true });
32await writeFile(`${target}/mainland-ipv4.txt`, data);
33await writeFile(`${target}/LICENSE`, license);
34await writeFile(`${target}/source.json`, JSON.stringify({
35 sha256: createHash("sha256").update(data).digest("hex"),
36 ipv4_prefixes: prefixes.length, license: "MIT",
37}, null, 2) + "\n");
38console.log(`Updated ${prefixes.length} mainland IPv4 prefixes from ${commit}`);