Skip to content

Commit 924e079

Browse files
committed
fix: bypass proxy for desktop auth callbacks
1 parent 2f4307b commit 924e079

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

electron/clovapi-desktop.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ function agentUninstall(kind) {
163163
return runDesktopAsync(["agents", "uninstall", "--cli", String(kind || "")], { timeout: 10 * 60 * 1000 });
164164
}
165165

166+
function mergeNoProxy(value) {
167+
const bypass = ["127.0.0.1", "localhost", "::1"];
168+
const parts = String(value || "")
169+
.split(",")
170+
.map((part) => part.trim())
171+
.filter(Boolean);
172+
for (const host of bypass) {
173+
if (!parts.some((part) => part.toLowerCase() === host.toLowerCase())) parts.push(host);
174+
}
175+
return parts.join(",");
176+
}
177+
178+
function authLoginEnv() {
179+
const env = { ...process.env };
180+
env.NO_PROXY = mergeNoProxy(env.NO_PROXY);
181+
env.no_proxy = mergeNoProxy(env.no_proxy);
182+
return env;
183+
}
184+
166185
function authStatus() {
167186
return runAuthAsync(["status"]);
168187
}
@@ -176,6 +195,7 @@ async function authLogin(provider) {
176195
cancelKey: providerId,
177196
onOutput: outputHandler,
178197
timeout: AUTH_LOGIN_TIMEOUT,
198+
env: authLoginEnv(),
179199
});
180200
if (result.cancelled) {
181201
return { ok: false, cancelled: true, error: "已取消登录" };
@@ -228,4 +248,6 @@ module.exports = {
228248
cancelAuthLogin,
229249
authLogout,
230250
queryVendorUsage,
251+
mergeNoProxy,
252+
authLoginEnv,
231253
};

electron/clovapi-exec.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const test = require("node:test");
66

77
const { cliBinPath } = require("./config-paths");
88
const { resolveClovapiExecutable, runClovapiArgsAsync } = require("./clovapi-exec");
9+
const { mergeNoProxy } = require("./clovapi-desktop");
910

1011
function withTempAppData(t) {
1112
const previousAppData = process.env.APPDATA;
@@ -97,3 +98,8 @@ test("runClovapiArgsAsync captures output without spawnSync", async (t) => {
9798
assert.equal(result.ok, true);
9899
assert.equal(result.stdout.trim(), "async:probe");
99100
});
101+
102+
test("mergeNoProxy appends loopback hosts without dropping existing entries", () => {
103+
assert.equal(mergeNoProxy("example.com, localhost"), "example.com,localhost,127.0.0.1,::1");
104+
});
105+

electron/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clovapi-switcher",
33
"private": true,
4-
"version": "0.2.11",
4+
"version": "0.2.12",
55
"description": "ClovAPI Switcher desktop app",
66
"main": "main.js",
77
"type": "commonjs",

0 commit comments

Comments
 (0)