api-switch-cc 0.2.6 → 0.2.8
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/install.js +38 -15
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* On postinstall, installs the api-switch binary.
|
|
7
7
|
* Tries multiple methods in order:
|
|
8
|
-
* 1. go install (works behind GFW
|
|
9
|
-
* 2.
|
|
8
|
+
* 1. go install (via goproxy.cn, works behind GFW)
|
|
9
|
+
* 2. Build from Gitee mirror (fast in China)
|
|
10
|
+
* 3. Download from GitHub Releases
|
|
10
11
|
*
|
|
11
12
|
* Usage: npx api-switch-cc <command>
|
|
12
13
|
* npm install -g api-switch-cc && api-switch serve
|
|
@@ -21,6 +22,7 @@ const { execSync } = require("child_process");
|
|
|
21
22
|
const PKG = require("./package.json");
|
|
22
23
|
const DOWNLOAD_VERSION = "v0.2.1";
|
|
23
24
|
const GH_RELEASE = `https://github.com/hxz0727/API-Switch/releases/download/${DOWNLOAD_VERSION}`;
|
|
25
|
+
const GITEE_REPO = "https://gitee.com/776311606/API-Switch.git";
|
|
24
26
|
const BIN_DIR = join(__dirname, "bin");
|
|
25
27
|
|
|
26
28
|
function platform() {
|
|
@@ -54,7 +56,10 @@ function install() {
|
|
|
54
56
|
// ── Method 1: go install via goproxy.cn (works in China) ──
|
|
55
57
|
if (tryGoInstall(binPath, name)) return;
|
|
56
58
|
|
|
57
|
-
// ── Method 2:
|
|
59
|
+
// ── Method 2: Clone from Gitee + build (fast for Chinese users) ──
|
|
60
|
+
if (tryGiteeBuild(binPath)) return;
|
|
61
|
+
|
|
62
|
+
// ── Method 3: Download from GitHub Releases ──
|
|
58
63
|
if (tryGitHubDownload(binPath, name)) return;
|
|
59
64
|
|
|
60
65
|
// ── All methods failed ──
|
|
@@ -62,31 +67,30 @@ function install() {
|
|
|
62
67
|
console.error("Installation failed. Try one of these:");
|
|
63
68
|
console.error();
|
|
64
69
|
console.error(" # Option A: Install via Go (quickest)");
|
|
65
|
-
console.error(" GOPROXY=https://goproxy.cn,direct go install github.com/hxz0727/API-Switch/cmd/api-switch@v0.2.
|
|
70
|
+
console.error(" GOPROXY=https://goproxy.cn,direct go install github.com/hxz0727/API-Switch/cmd/api-switch@v0.2.1");
|
|
66
71
|
console.error(" sudo cp ~/go/bin/api-switch /usr/local/bin/");
|
|
67
72
|
console.error();
|
|
68
|
-
console.error(" # Option B:
|
|
73
|
+
console.error(" # Option B: Clone from Gitee and build");
|
|
74
|
+
console.error(` git clone --depth=1 ${GITEE_REPO}`);
|
|
75
|
+
console.error(" cd API-Switch && GOTOOLCHAIN=local GOPROXY=https://goproxy.cn,direct go build -o api-switch ./cmd/api-switch/");
|
|
76
|
+
console.error(" sudo cp api-switch /usr/local/bin/");
|
|
77
|
+
console.error();
|
|
78
|
+
console.error(" # Option C: Download from GitHub");
|
|
69
79
|
const plat = platform();
|
|
70
80
|
const isWin = process.platform === "win32";
|
|
71
81
|
const archive = `api-switch-${plat}${isWin ? ".zip" : ".tar.gz"}`;
|
|
72
82
|
console.error(` curl -sSL "${GH_RELEASE}/${archive}" | tar xz`);
|
|
73
83
|
console.error(` sudo cp api-switch-${plat} /usr/local/bin/api-switch`);
|
|
74
|
-
console.error();
|
|
75
|
-
console.error(" # Option C: Build from source");
|
|
76
|
-
console.error(" git clone https://github.com/hxz0727/API-Switch.git");
|
|
77
|
-
console.error(" cd API-Switch && make build && sudo make install");
|
|
78
84
|
process.exit(1);
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
function tryGoInstall(binPath, name) {
|
|
82
88
|
try {
|
|
83
89
|
console.log("Trying go install (works behind GFW)...");
|
|
84
|
-
// Use goproxy.cn for Chinese users, fallback to default for others
|
|
85
90
|
execSync(
|
|
86
|
-
`go install github.com/hxz0727/API-Switch/cmd/api-switch@${DOWNLOAD_VERSION}`,
|
|
91
|
+
`GOPROXY=https://goproxy.cn,direct GOTOOLCHAIN=local go install github.com/hxz0727/API-Switch/cmd/api-switch@${DOWNLOAD_VERSION}`,
|
|
87
92
|
{ stdio: "pipe", timeout: 120000 }
|
|
88
93
|
);
|
|
89
|
-
// go install puts binary in GOPATH/bin or ~/go/bin
|
|
90
94
|
const goPath = (execSync("go env GOPATH", { encoding: "utf8" }) || "~/go").trim();
|
|
91
95
|
const goBin = join(goPath, "bin", name);
|
|
92
96
|
if (existsSync(goBin)) {
|
|
@@ -95,9 +99,28 @@ function tryGoInstall(binPath, name) {
|
|
|
95
99
|
console.log(`Installed to ${binPath}`);
|
|
96
100
|
return true;
|
|
97
101
|
}
|
|
98
|
-
} catch (_) {
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
} catch (_) {}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function tryGiteeBuild(binPath) {
|
|
107
|
+
try {
|
|
108
|
+
console.log("Trying Gitee mirror build...");
|
|
109
|
+
const tmpDir = join(__dirname, "_build");
|
|
110
|
+
execSync("rm -rf " + tmpDir, { stdio: "pipe" });
|
|
111
|
+
execSync(
|
|
112
|
+
`git clone --depth=1 ${GITEE_REPO} ${tmpDir}`,
|
|
113
|
+
{ stdio: "pipe", timeout: 60000 }
|
|
114
|
+
);
|
|
115
|
+
execSync(
|
|
116
|
+
`cd ${tmpDir} && GOTOOLCHAIN=local GOPROXY=https://goproxy.cn,direct go build -ldflags="-s -w -X main.Version=v0.2.1" -o "${binPath}" ./cmd/api-switch/`,
|
|
117
|
+
{ stdio: "pipe", timeout: 120000 }
|
|
118
|
+
);
|
|
119
|
+
execSync("rm -rf " + tmpDir, { stdio: "pipe" });
|
|
120
|
+
chmodSync(binPath, 0o755);
|
|
121
|
+
console.log(`Installed to ${binPath}`);
|
|
122
|
+
return true;
|
|
123
|
+
} catch (_) {}
|
|
101
124
|
return false;
|
|
102
125
|
}
|
|
103
126
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api-switch-cc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Claude Code 多模型代理 — 一键切换 DeepSeek、Qwen、GLM、Moonshot 等国产大模型,协议自动转换,零配置即用。LLM API proxy for Claude Code with DeepSeek, Qwen, Anthropic, OpenAI support.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"api-switch": "bin/api-switch"
|