mihomo-cli 2.4.0 → 2.4.1
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/CHANGELOG.md +8 -0
- package/dist/index.js +36 -38
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -3509,48 +3509,37 @@ function parseProxyUris(content) {
|
|
|
3509
3509
|
return proxies;
|
|
3510
3510
|
}
|
|
3511
3511
|
async function downloadAllSources(sources, onProgress) {
|
|
3512
|
-
const
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
const entry = { name: source.name, url: source.url, proxies: [], proxyGroups: 0 };
|
|
3512
|
+
const client = createHttpClient({ timeout: 3e4 });
|
|
3513
|
+
const tasks = sources.map(async (source) => {
|
|
3514
|
+
const entry = { name: source.name, url: source.url, proxies: [], proxyGroups: 0 };
|
|
3515
|
+
try {
|
|
3516
|
+
const response = await client.get(source.url, { responseType: "text" });
|
|
3517
|
+
const content = response.data;
|
|
3518
|
+
if (!content?.trim()) throw new Error("\u5185\u5BB9\u4E3A\u7A7A");
|
|
3519
|
+
let proxies;
|
|
3521
3520
|
try {
|
|
3522
|
-
const
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
const decoded = tryDecodeBase64Content(content);
|
|
3533
|
-
if (decoded) {
|
|
3534
|
-
proxies = parseProxyUris(decoded);
|
|
3535
|
-
} else {
|
|
3536
|
-
proxies = parseProxyUris(content);
|
|
3537
|
-
}
|
|
3538
|
-
if (proxies.length === 0) throw new Error("\u65E0\u6CD5\u89E3\u6790\u8BA2\u9605\u5185\u5BB9\uFF08\u975E YAML/JSON/Base64\uFF09");
|
|
3521
|
+
const parsed = parseYamlOrJson(content, "\u8BA2\u9605\u5185\u5BB9");
|
|
3522
|
+
proxies = parsed.proxies || [];
|
|
3523
|
+
const groups = parsed["proxy-groups"];
|
|
3524
|
+
if (groups) entry.proxyGroups = groups.length;
|
|
3525
|
+
} catch {
|
|
3526
|
+
const decoded = tryDecodeBase64Content(content);
|
|
3527
|
+
if (decoded) {
|
|
3528
|
+
proxies = parseProxyUris(decoded);
|
|
3529
|
+
} else {
|
|
3530
|
+
proxies = parseProxyUris(content);
|
|
3539
3531
|
}
|
|
3540
|
-
|
|
3541
|
-
onProgress?.(source.name, true, proxies.length, entry.proxyGroups);
|
|
3542
|
-
} catch (e) {
|
|
3543
|
-
entry.error = e.message;
|
|
3544
|
-
onProgress?.(source.name, false, 0, 0, entry.error);
|
|
3532
|
+
if (proxies.length === 0) throw new Error("\u65E0\u6CD5\u89E3\u6790\u8BA2\u9605\u5185\u5BB9\uFF08\u975E YAML/JSON/Base64\uFF09");
|
|
3545
3533
|
}
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
if (val !== void 0) process.env[key] = val;
|
|
3534
|
+
entry.proxies = proxies.map((p) => ({ ...p, name: `[${source.name}] ${p.name}` }));
|
|
3535
|
+
onProgress?.(source.name, true, proxies.length, entry.proxyGroups);
|
|
3536
|
+
} catch (e) {
|
|
3537
|
+
entry.error = e.message;
|
|
3538
|
+
onProgress?.(source.name, false, 0, 0, entry.error);
|
|
3552
3539
|
}
|
|
3553
|
-
|
|
3540
|
+
return entry;
|
|
3541
|
+
});
|
|
3542
|
+
return await Promise.all(tasks);
|
|
3554
3543
|
}
|
|
3555
3544
|
function isProxyValid(proxy) {
|
|
3556
3545
|
if (!proxy.name || !proxy.server || !proxy.port) return false;
|
|
@@ -6174,7 +6163,16 @@ process.on("unhandledRejection", (reason) => {
|
|
|
6174
6163
|
\u672A\u5904\u7406\u7684 Promise \u62D2\u7EDD: ${msg}`);
|
|
6175
6164
|
process.exit(1);
|
|
6176
6165
|
});
|
|
6166
|
+
function clearProxyEnv() {
|
|
6167
|
+
delete process.env.http_proxy;
|
|
6168
|
+
delete process.env.https_proxy;
|
|
6169
|
+
delete process.env.HTTP_PROXY;
|
|
6170
|
+
delete process.env.HTTPS_PROXY;
|
|
6171
|
+
delete process.env.all_proxy;
|
|
6172
|
+
delete process.env.ALL_PROXY;
|
|
6173
|
+
}
|
|
6177
6174
|
async function main() {
|
|
6175
|
+
clearProxyEnv();
|
|
6178
6176
|
ensureDirs();
|
|
6179
6177
|
const args = process.argv.slice(2);
|
|
6180
6178
|
if (args.length === 0) {
|