mihomo-cli 3.9.0 → 3.10.0
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 +49 -1
- package/README.md +20 -31
- package/dist/index.js +127 -956
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var colors = {
|
|
|
19
19
|
import { spawnSync } from "child_process";
|
|
20
20
|
import fs5 from "fs";
|
|
21
21
|
|
|
22
|
-
//
|
|
22
|
+
// node_modules/js-yaml/dist/js-yaml.mjs
|
|
23
23
|
var NOT_RESOLVED = /* @__PURE__ */ Symbol("NOT_RESOLVED");
|
|
24
24
|
function defineScalarTag(tagName, options) {
|
|
25
25
|
return {
|
|
@@ -3078,7 +3078,6 @@ var LAUNCH_DAEMON_LABEL = RAW_DAEMON_LABEL && isValidDaemonLabel(RAW_DAEMON_LABE
|
|
|
3078
3078
|
var CONTROLLER_PORT = 9090;
|
|
3079
3079
|
var CONTROLLER_ADDR = `127.0.0.1:${CONTROLLER_PORT}`;
|
|
3080
3080
|
var CONTROLLER_BASE_URL = `http://${CONTROLLER_ADDR}`;
|
|
3081
|
-
var TEST_CONTROLLER_ADDR = "127.0.0.1:29090";
|
|
3082
3081
|
var TUN_CONFIG = {
|
|
3083
3082
|
tun: {
|
|
3084
3083
|
enable: true,
|
|
@@ -3089,13 +3088,6 @@ var TUN_CONFIG = {
|
|
|
3089
3088
|
"strict-route": true
|
|
3090
3089
|
}
|
|
3091
3090
|
};
|
|
3092
|
-
var TEST_CONFIG = {
|
|
3093
|
-
"mixed-port": 27890,
|
|
3094
|
-
"allow-lan": false,
|
|
3095
|
-
"external-controller": TEST_CONTROLLER_ADDR,
|
|
3096
|
-
"log-level": "error",
|
|
3097
|
-
"geodata-mode": true
|
|
3098
|
-
};
|
|
3099
3091
|
var BASE_CONFIG = {
|
|
3100
3092
|
"mixed-port": 7890,
|
|
3101
3093
|
"allow-lan": false,
|
|
@@ -3119,13 +3111,6 @@ var BASE_CONFIG = {
|
|
|
3119
3111
|
var DEFAULT_UPDATE_INTERVAL_HOURS = 12;
|
|
3120
3112
|
var DEFAULT_UPDATE_INTERVAL_HOURS_GITHUB = 6;
|
|
3121
3113
|
var DEFAULT_AUTO_UPDATE_TIMEOUT = 1e4;
|
|
3122
|
-
var DEFAULT_TEST_TIMEOUT = 2e3;
|
|
3123
|
-
var DEFAULT_TEST_CONCURRENCY = 100;
|
|
3124
|
-
var DEFAULT_TEST_URL = "http://www.gstatic.com/generate_204";
|
|
3125
|
-
var DEFAULT_CLEAN_ROUNDS = 2;
|
|
3126
|
-
var AUTO_CLEAN_THRESHOLD = 100;
|
|
3127
|
-
var AUTO_CLEAN_THRESHOLD_GITHUB = 50;
|
|
3128
|
-
var AUTO_CLEAN_COOLDOWN_HOURS = 12;
|
|
3129
3114
|
|
|
3130
3115
|
// src/errors.ts
|
|
3131
3116
|
var TimeoutError = class extends Error {
|
|
@@ -3365,24 +3350,8 @@ function maskSingleUrl(url) {
|
|
|
3365
3350
|
return url;
|
|
3366
3351
|
}
|
|
3367
3352
|
}
|
|
3368
|
-
function looksLikeMultiUrl(url) {
|
|
3369
|
-
if (!url.includes(",")) return false;
|
|
3370
|
-
const parts = url.split(",").map((u) => u.trim()).filter(Boolean);
|
|
3371
|
-
if (parts.length < 2) return false;
|
|
3372
|
-
return parts.every((p) => {
|
|
3373
|
-
try {
|
|
3374
|
-
const u = new URL(p);
|
|
3375
|
-
return u.protocol === "http:" || u.protocol === "https:";
|
|
3376
|
-
} catch {
|
|
3377
|
-
return false;
|
|
3378
|
-
}
|
|
3379
|
-
});
|
|
3380
|
-
}
|
|
3381
3353
|
function maskUrl(url) {
|
|
3382
3354
|
if (!url) return url;
|
|
3383
|
-
if (looksLikeMultiUrl(url)) {
|
|
3384
|
-
return url.split(",").map((u) => maskSingleUrl(u.trim())).join(", ");
|
|
3385
|
-
}
|
|
3386
3355
|
return maskSingleUrl(url);
|
|
3387
3356
|
}
|
|
3388
3357
|
function readSubscriptionCache() {
|
|
@@ -3689,20 +3658,6 @@ function summarizeMatch(match) {
|
|
|
3689
3658
|
}
|
|
3690
3659
|
return parts.length > 0 ? parts.join(", ") : void 0;
|
|
3691
3660
|
}
|
|
3692
|
-
function splitUrlsLocal(url) {
|
|
3693
|
-
const isValidHttp = (u) => {
|
|
3694
|
-
try {
|
|
3695
|
-
const parsed = new URL(u.trim());
|
|
3696
|
-
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
3697
|
-
} catch {
|
|
3698
|
-
return false;
|
|
3699
|
-
}
|
|
3700
|
-
};
|
|
3701
|
-
if (!url.includes(",")) return [url.trim()];
|
|
3702
|
-
const parts = url.split(",").map((u) => u.trim()).filter(Boolean);
|
|
3703
|
-
if (parts.length > 1 && parts.every(isValidHttp)) return parts;
|
|
3704
|
-
return [url.trim()];
|
|
3705
|
-
}
|
|
3706
3661
|
function hostMatchesDomain(host, domain) {
|
|
3707
3662
|
const h = host.toLowerCase();
|
|
3708
3663
|
const d = domain.toLowerCase();
|
|
@@ -3719,16 +3674,13 @@ function matchesScope(match, scope) {
|
|
|
3719
3674
|
if (match["url-domain"]) {
|
|
3720
3675
|
const domains = Array.isArray(match["url-domain"]) ? match["url-domain"] : [match["url-domain"]];
|
|
3721
3676
|
if (!scope?.subUrl) return false;
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
}
|
|
3677
|
+
let host;
|
|
3678
|
+
try {
|
|
3679
|
+
host = new URL(scope.subUrl.trim()).hostname;
|
|
3680
|
+
} catch {
|
|
3681
|
+
return false;
|
|
3728
3682
|
}
|
|
3729
|
-
if (
|
|
3730
|
-
const ok = domains.some((d) => hosts.some((h) => hostMatchesDomain(h, d)));
|
|
3731
|
-
if (!ok) return false;
|
|
3683
|
+
if (!domains.some((d) => hostMatchesDomain(host, d))) return false;
|
|
3732
3684
|
}
|
|
3733
3685
|
return true;
|
|
3734
3686
|
}
|
|
@@ -3797,11 +3749,14 @@ function getSshConfigPath(name) {
|
|
|
3797
3749
|
validateSshName(name);
|
|
3798
3750
|
return path4.join(USER_DATA_DIR, `ssh.${name}.yaml`);
|
|
3799
3751
|
}
|
|
3752
|
+
function capitalize(name) {
|
|
3753
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
3754
|
+
}
|
|
3800
3755
|
function getSshProxyName(name) {
|
|
3801
|
-
return `
|
|
3756
|
+
return `SSH-${capitalize(name)}-Host`;
|
|
3802
3757
|
}
|
|
3803
3758
|
function getSshGroupName(name) {
|
|
3804
|
-
return `
|
|
3759
|
+
return `SSH-${capitalize(name)}`;
|
|
3805
3760
|
}
|
|
3806
3761
|
function renderSshProxy(tunnel) {
|
|
3807
3762
|
return {
|
|
@@ -3972,30 +3927,17 @@ function parseStringArg(args, long, short) {
|
|
|
3972
3927
|
}
|
|
3973
3928
|
return null;
|
|
3974
3929
|
}
|
|
3975
|
-
var VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
3976
|
-
"-t",
|
|
3977
|
-
"--timeout",
|
|
3978
|
-
"-j",
|
|
3979
|
-
"--concurrency",
|
|
3980
|
-
"-r",
|
|
3981
|
-
"--rounds",
|
|
3982
|
-
"-n",
|
|
3983
|
-
"--lines",
|
|
3984
|
-
"-u",
|
|
3985
|
-
"--update-timeout",
|
|
3986
|
-
"--host",
|
|
3987
|
-
"--port"
|
|
3988
|
-
]);
|
|
3930
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set(["-n", "--lines", "-u", "--update-timeout", "--host", "--port"]);
|
|
3989
3931
|
function extractStartOptions(args) {
|
|
3990
3932
|
if (!args) return [];
|
|
3991
|
-
const BOOL_FLAGS = /* @__PURE__ */ new Set(["-s", "--no-update", "--no-
|
|
3933
|
+
const BOOL_FLAGS = /* @__PURE__ */ new Set(["-s", "--no-update", "--no-ssh"]);
|
|
3992
3934
|
const out = [];
|
|
3993
3935
|
for (let i = 0; i < args.length; i++) {
|
|
3994
3936
|
const a = args[i];
|
|
3995
3937
|
if (VALUE_FLAGS.has(a)) {
|
|
3996
3938
|
out.push(a);
|
|
3997
3939
|
if (i + 1 < args.length) out.push(args[++i]);
|
|
3998
|
-
} else if (BOOL_FLAGS.has(a) || /^--
|
|
3940
|
+
} else if (BOOL_FLAGS.has(a) || /^--update-timeout=/.test(a)) {
|
|
3999
3941
|
out.push(a);
|
|
4000
3942
|
}
|
|
4001
3943
|
}
|
|
@@ -4067,20 +4009,21 @@ function normalizeMirrorUrl(val) {
|
|
|
4067
4009
|
}
|
|
4068
4010
|
function parseMirrorArg(args) {
|
|
4069
4011
|
if (!args || args.length < 2) {
|
|
4070
|
-
return { mirror: null, isOverride: false
|
|
4012
|
+
return { mirror: null, isOverride: false };
|
|
4071
4013
|
}
|
|
4072
|
-
if (args.
|
|
4073
|
-
|
|
4014
|
+
if (args.some((a) => a === "--mirror-all" || a.startsWith("--mirror-all="))) {
|
|
4015
|
+
throw new CliError("--mirror-all \u5DF2\u79FB\u9664\uFF08v3.10.0\uFF09", {
|
|
4016
|
+
label: "\u53C2\u6570\u9519\u8BEF",
|
|
4017
|
+
hint: [
|
|
4018
|
+
"\u7248\u672C\u67E5\u8BE2\uFF08GitHub API\uFF09\u73B0\u5728\u6052\u76F4\u8FDE\uFF0C\u955C\u50CF\u53EA\u4F5C\u7528\u4E8E\u5185\u6838\u4EA7\u7269\u4E0B\u8F7D\u3002",
|
|
4019
|
+
"API \u82E5\u8D70\u955C\u50CF\uFF0C\u4E0B\u8F7D\u5730\u5740\u5C31\u7531\u955C\u50CF\u8BF4\u4E86\u7B97\uFF0C\u800C\u5185\u6838\u968F\u540E\u4EE5 root \u8FD0\u884C\u3002",
|
|
4020
|
+
"",
|
|
4021
|
+
"\u6539\u7528: mihomo kernel --mirror [\u955C\u50CF]"
|
|
4022
|
+
]
|
|
4023
|
+
});
|
|
4074
4024
|
}
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
if (mirrorAllIdx >= 0 || mirrorAllEq) {
|
|
4078
|
-
const inline = mirrorAllEq?.slice("--mirror-all=".length);
|
|
4079
|
-
const nextArg = inline ?? args[mirrorAllIdx + 1];
|
|
4080
|
-
if (!nextArg || nextArg.startsWith("-")) {
|
|
4081
|
-
return { mirror: DEFAULT_MIRROR, isOverride: true, type: "all" };
|
|
4082
|
-
}
|
|
4083
|
-
return { mirror: normalizeMirrorUrl(nextArg), isOverride: true, type: "all" };
|
|
4025
|
+
if (args.includes("--no-mirror") || args.includes("--direct")) {
|
|
4026
|
+
return { mirror: null, isOverride: true };
|
|
4084
4027
|
}
|
|
4085
4028
|
const mirrorEq = args.find((a) => a.startsWith("--mirror="));
|
|
4086
4029
|
const mirrorIdx = args.indexOf("--mirror");
|
|
@@ -4088,11 +4031,11 @@ function parseMirrorArg(args) {
|
|
|
4088
4031
|
const inline = mirrorEq?.slice("--mirror=".length);
|
|
4089
4032
|
const nextArg = inline ?? args[mirrorIdx + 1];
|
|
4090
4033
|
if (!nextArg || nextArg.startsWith("-")) {
|
|
4091
|
-
return { mirror: DEFAULT_MIRROR, isOverride: true
|
|
4034
|
+
return { mirror: DEFAULT_MIRROR, isOverride: true };
|
|
4092
4035
|
}
|
|
4093
|
-
return { mirror: normalizeMirrorUrl(nextArg), isOverride: true
|
|
4036
|
+
return { mirror: normalizeMirrorUrl(nextArg), isOverride: true };
|
|
4094
4037
|
}
|
|
4095
|
-
return { mirror: null, isOverride: false
|
|
4038
|
+
return { mirror: null, isOverride: false };
|
|
4096
4039
|
}
|
|
4097
4040
|
|
|
4098
4041
|
// src/config.ts
|
|
@@ -5035,29 +4978,6 @@ function listLogs() {
|
|
|
5035
4978
|
result.archives.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
|
|
5036
4979
|
return result;
|
|
5037
4980
|
}
|
|
5038
|
-
function isPathUnderDir(filePath, baseDir) {
|
|
5039
|
-
const resolvedPath = path5.resolve(filePath);
|
|
5040
|
-
const resolvedBase = path5.resolve(baseDir);
|
|
5041
|
-
return resolvedPath === resolvedBase || resolvedPath.startsWith(resolvedBase + path5.sep);
|
|
5042
|
-
}
|
|
5043
|
-
function getLogPathByName(name) {
|
|
5044
|
-
const logsDir = DIRS.logs;
|
|
5045
|
-
let targetName = name;
|
|
5046
|
-
if (!name.endsWith(".log")) targetName = `mihomo.${name}.log`;
|
|
5047
|
-
if (!targetName.startsWith("mihomo.")) targetName = `mihomo.${targetName}`;
|
|
5048
|
-
const filePath = path5.join(logsDir, targetName);
|
|
5049
|
-
if (fs6.existsSync(filePath) && isPathUnderDir(filePath, logsDir)) return filePath;
|
|
5050
|
-
if (fs6.existsSync(logsDir)) {
|
|
5051
|
-
const files = fs6.readdirSync(logsDir);
|
|
5052
|
-
for (const file of files) {
|
|
5053
|
-
if (file.includes(name)) {
|
|
5054
|
-
const candidatePath = path5.join(logsDir, file);
|
|
5055
|
-
if (isPathUnderDir(candidatePath, logsDir)) return candidatePath;
|
|
5056
|
-
}
|
|
5057
|
-
}
|
|
5058
|
-
}
|
|
5059
|
-
return null;
|
|
5060
|
-
}
|
|
5061
4981
|
function openUrl(url) {
|
|
5062
4982
|
try {
|
|
5063
4983
|
const child = spawn("open", ["--", url], { stdio: "ignore", detached: true });
|
|
@@ -5387,11 +5307,7 @@ async function readBodyWithLimit(response, controller, limit) {
|
|
|
5387
5307
|
|
|
5388
5308
|
// src/subscription.ts
|
|
5389
5309
|
function isGithubUrl(url) {
|
|
5390
|
-
|
|
5391
|
-
if (isMultiUrl(url)) {
|
|
5392
|
-
return splitUrls(url).every((u) => githubRe.test(u));
|
|
5393
|
-
}
|
|
5394
|
-
return githubRe.test(url);
|
|
5310
|
+
return /github\.com|raw\.githubusercontent\.com/i.test(url);
|
|
5395
5311
|
}
|
|
5396
5312
|
function getDefaultUpdateInterval(url) {
|
|
5397
5313
|
return isGithubUrl(url) ? DEFAULT_UPDATE_INTERVAL_HOURS_GITHUB : DEFAULT_UPDATE_INTERVAL_HOURS;
|
|
@@ -5400,11 +5316,6 @@ function resolveUpdateInterval(url, cachedInterval) {
|
|
|
5400
5316
|
return cachedInterval && cachedInterval > 0 ? cachedInterval : getDefaultUpdateInterval(url);
|
|
5401
5317
|
}
|
|
5402
5318
|
var HTTP_CLIENT = createHttpClient({ timeout: 6e4 });
|
|
5403
|
-
function isMultiUrl(url) {
|
|
5404
|
-
if (!url.includes(",")) return false;
|
|
5405
|
-
const parts = url.split(",").map((u) => u.trim()).filter(Boolean);
|
|
5406
|
-
return parts.length > 1 && parts.every(isValidHttpUrl);
|
|
5407
|
-
}
|
|
5408
5319
|
function isValidHttpUrl(url) {
|
|
5409
5320
|
try {
|
|
5410
5321
|
const u = new URL(url.trim());
|
|
@@ -5413,28 +5324,6 @@ function isValidHttpUrl(url) {
|
|
|
5413
5324
|
return false;
|
|
5414
5325
|
}
|
|
5415
5326
|
}
|
|
5416
|
-
function splitUrls(url) {
|
|
5417
|
-
if (!isMultiUrl(url)) return [url.trim()];
|
|
5418
|
-
return url.split(",").map((u) => u.trim()).filter(Boolean);
|
|
5419
|
-
}
|
|
5420
|
-
function loadSubscriptionConfig(subName) {
|
|
5421
|
-
const rawContent = readSubscriptionRawConfig(subName);
|
|
5422
|
-
if (!rawContent) {
|
|
5423
|
-
throw new CliError(`\u672A\u627E\u5230\u8BA2\u9605\u914D\u7F6E "${subName}"\uFF0C\u8BF7\u5148\u66F4\u65B0\u8BA2\u9605\uFF08mihomo sub update ${subName}\uFF09`);
|
|
5424
|
-
}
|
|
5425
|
-
const raw = parseYamlOrJson(rawContent, "\u8BA2\u9605\u5185\u5BB9");
|
|
5426
|
-
return {
|
|
5427
|
-
raw,
|
|
5428
|
-
proxies: raw.proxies || [],
|
|
5429
|
-
proxyGroups: raw["proxy-groups"] || []
|
|
5430
|
-
};
|
|
5431
|
-
}
|
|
5432
|
-
function saveSubscriptionConfig(subName, parsed) {
|
|
5433
|
-
normalizeProxyNamesBeforeSave(parsed);
|
|
5434
|
-
parsed.raw.proxies = parsed.proxies;
|
|
5435
|
-
parsed.raw["proxy-groups"] = parsed.proxyGroups;
|
|
5436
|
-
saveSubscriptionRawConfig(subName, dumpYaml(parsed.raw));
|
|
5437
|
-
}
|
|
5438
5327
|
function parseUserInfo(header) {
|
|
5439
5328
|
if (!header) return null;
|
|
5440
5329
|
const info = {};
|
|
@@ -5598,65 +5487,6 @@ async function downloadSubscription(url, subName = "default", signal, persist =
|
|
|
5598
5487
|
username: meta.username
|
|
5599
5488
|
};
|
|
5600
5489
|
}
|
|
5601
|
-
async function downloadMergedSubscription(urls, subName, signal, persist = true) {
|
|
5602
|
-
const internal = new AbortController();
|
|
5603
|
-
const combinedSignal = signal ? AbortSignal.any([signal, internal.signal]) : internal.signal;
|
|
5604
|
-
const responses = await Promise.all(
|
|
5605
|
-
urls.map(async (url, index) => {
|
|
5606
|
-
try {
|
|
5607
|
-
const response = await HTTP_CLIENT.get(url, { responseType: "text", signal: combinedSignal });
|
|
5608
|
-
return { url, index, response, error: null };
|
|
5609
|
-
} catch (e) {
|
|
5610
|
-
internal.abort();
|
|
5611
|
-
return { url, index, response: null, error: e };
|
|
5612
|
-
}
|
|
5613
|
-
})
|
|
5614
|
-
);
|
|
5615
|
-
const failures = responses.filter((r) => r.error);
|
|
5616
|
-
if (failures.length > 0) {
|
|
5617
|
-
const isAbort = (e) => e.name === "AbortError" || /abort/i.test(e.message);
|
|
5618
|
-
const real = failures.find((r) => !isAbort(r.error)) ?? failures[0];
|
|
5619
|
-
const maskedUrl = maskUrl(real.url);
|
|
5620
|
-
throw new Error(`\u5408\u5E76\u8BA2\u9605\u7B2C ${real.index + 1} \u4E2A URL \u83B7\u53D6\u5931\u8D25: ${real.error.message}
|
|
5621
|
-
URL: ${maskedUrl}`);
|
|
5622
|
-
}
|
|
5623
|
-
const parsed = responses.map((r, i) => {
|
|
5624
|
-
const content = r.response?.data;
|
|
5625
|
-
if (!content?.trim()) throw new Error(`\u5408\u5E76\u8BA2\u9605\u7B2C ${i + 1} \u4E2A URL \u5185\u5BB9\u4E3A\u7A7A`);
|
|
5626
|
-
return parseYamlOrJson(content, `\u5408\u5E76\u8BA2\u9605\u7B2C ${i + 1} \u4E2A`);
|
|
5627
|
-
});
|
|
5628
|
-
const base = parsed[0];
|
|
5629
|
-
const baseProxies = base.proxies || [];
|
|
5630
|
-
const seenNames = new Set(baseProxies.map((p) => p.name));
|
|
5631
|
-
for (let i = 1; i < parsed.length; i++) {
|
|
5632
|
-
const extraProxies = parsed[i].proxies || [];
|
|
5633
|
-
for (const proxy of extraProxies) {
|
|
5634
|
-
if (!seenNames.has(proxy.name)) {
|
|
5635
|
-
baseProxies.push(proxy);
|
|
5636
|
-
seenNames.add(proxy.name);
|
|
5637
|
-
}
|
|
5638
|
-
}
|
|
5639
|
-
}
|
|
5640
|
-
base.proxies = baseProxies;
|
|
5641
|
-
const mergedContent = dumpYaml(base);
|
|
5642
|
-
assertLooksLikeSubscription(base, urls.map((u) => maskUrl(u)).join(", "));
|
|
5643
|
-
if (persist) {
|
|
5644
|
-
saveSubscriptionRawConfig(subName, mergedContent);
|
|
5645
|
-
}
|
|
5646
|
-
const meta = extractSubscriptionMeta(responses[0].response?.headers);
|
|
5647
|
-
if (persist) {
|
|
5648
|
-
saveSubscriptionMeta(subName, meta);
|
|
5649
|
-
}
|
|
5650
|
-
const proxyGroups = base["proxy-groups"];
|
|
5651
|
-
return {
|
|
5652
|
-
proxies: baseProxies.length,
|
|
5653
|
-
proxyGroups: proxyGroups ? proxyGroups.length : 0,
|
|
5654
|
-
userInfo: meta.userInfo,
|
|
5655
|
-
updateInterval: meta.updateInterval,
|
|
5656
|
-
webPageUrl: meta.webPageUrl,
|
|
5657
|
-
username: meta.username
|
|
5658
|
-
};
|
|
5659
|
-
}
|
|
5660
5490
|
function prepareConfigForStart(mode, subName = "default") {
|
|
5661
5491
|
const rawContent = readSubscriptionRawConfig(subName);
|
|
5662
5492
|
if (!rawContent) {
|
|
@@ -5690,12 +5520,7 @@ function needsAutoUpdate(sub) {
|
|
|
5690
5520
|
}
|
|
5691
5521
|
async function tryUpdateOne(sub, signal) {
|
|
5692
5522
|
try {
|
|
5693
|
-
|
|
5694
|
-
if (isMultiUrl(sub.url)) {
|
|
5695
|
-
info = await downloadMergedSubscription(splitUrls(sub.url), sub.name, signal);
|
|
5696
|
-
} else {
|
|
5697
|
-
info = await downloadSubscription(sub.url, sub.name, signal);
|
|
5698
|
-
}
|
|
5523
|
+
const info = await downloadSubscription(sub.url, sub.name, signal);
|
|
5699
5524
|
return { name: sub.name, success: true, proxies: info.proxies, proxyGroups: info.proxyGroups };
|
|
5700
5525
|
} catch (e) {
|
|
5701
5526
|
return { name: sub.name, success: false, error: e.message };
|
|
@@ -5748,187 +5573,6 @@ async function autoUpdateStaleSubscription(options = {}) {
|
|
|
5748
5573
|
}
|
|
5749
5574
|
return { total: staleSubs.length, updated: updatedCount, failed: staleSubs.length - updatedCount };
|
|
5750
5575
|
}
|
|
5751
|
-
async function testProxyDelay(proxyName, timeout, testUrl, client, apiBase = CONTROLLER_BASE_URL) {
|
|
5752
|
-
const encodedName = encodeURIComponent(proxyName);
|
|
5753
|
-
const url = `${apiBase}/proxies/${encodedName}/delay?timeout=${timeout}&url=${encodeURIComponent(testUrl)}`;
|
|
5754
|
-
try {
|
|
5755
|
-
const response = await client.get(url);
|
|
5756
|
-
const data = JSON.parse(response.data);
|
|
5757
|
-
if (data.delay && data.delay > 0) {
|
|
5758
|
-
return { name: proxyName, delay: data.delay };
|
|
5759
|
-
}
|
|
5760
|
-
return { name: proxyName, delay: null, error: data.message || "no delay" };
|
|
5761
|
-
} catch (e) {
|
|
5762
|
-
const err = e;
|
|
5763
|
-
let errorMsg = "timeout";
|
|
5764
|
-
if (err.response?.data?.message) {
|
|
5765
|
-
errorMsg = String(err.response.data.message);
|
|
5766
|
-
} else if (err.message) {
|
|
5767
|
-
errorMsg = err.message;
|
|
5768
|
-
}
|
|
5769
|
-
return { name: proxyName, delay: null, error: errorMsg };
|
|
5770
|
-
}
|
|
5771
|
-
}
|
|
5772
|
-
async function testSubscriptionProxies(subName, options = {}) {
|
|
5773
|
-
const {
|
|
5774
|
-
timeout = DEFAULT_TEST_TIMEOUT,
|
|
5775
|
-
concurrency = DEFAULT_TEST_CONCURRENCY,
|
|
5776
|
-
testUrl = DEFAULT_TEST_URL,
|
|
5777
|
-
apiBase = CONTROLLER_BASE_URL,
|
|
5778
|
-
onResult
|
|
5779
|
-
} = options;
|
|
5780
|
-
const { proxies } = options.parsed || loadSubscriptionConfig(subName);
|
|
5781
|
-
if (proxies.length === 0) {
|
|
5782
|
-
return { total: 0, alive: 0, dead: 0, results: [] };
|
|
5783
|
-
}
|
|
5784
|
-
const secret = apiBase === CONTROLLER_BASE_URL ? readSettings().controller_secret : void 0;
|
|
5785
|
-
const client = createHttpClient({ timeout: timeout + 3e3, secret });
|
|
5786
|
-
const results = new Array(proxies.length);
|
|
5787
|
-
let completedCount = 0;
|
|
5788
|
-
let nextIndex = 0;
|
|
5789
|
-
async function runNext() {
|
|
5790
|
-
while (nextIndex < proxies.length) {
|
|
5791
|
-
const idx = nextIndex++;
|
|
5792
|
-
const result = await testProxyDelay(proxies[idx].name, timeout, testUrl, client, apiBase);
|
|
5793
|
-
results[idx] = result;
|
|
5794
|
-
onResult?.(result, completedCount, proxies.length);
|
|
5795
|
-
completedCount++;
|
|
5796
|
-
}
|
|
5797
|
-
}
|
|
5798
|
-
const workers = Array.from({ length: Math.min(concurrency, proxies.length) }, () => runNext());
|
|
5799
|
-
await Promise.all(workers);
|
|
5800
|
-
const alive = results.filter((r) => r.delay !== null).length;
|
|
5801
|
-
return { total: results.length, alive, dead: results.length - alive, results };
|
|
5802
|
-
}
|
|
5803
|
-
function normalizeProxyNamesBeforeSave(parsed) {
|
|
5804
|
-
const { proxies, proxyGroups } = parsed;
|
|
5805
|
-
const renameMap = /* @__PURE__ */ new Map();
|
|
5806
|
-
const usedNames = /* @__PURE__ */ new Set();
|
|
5807
|
-
for (const proxy of proxies) {
|
|
5808
|
-
const shortened = proxy.name.replace(/_github\.com\/[^_]+/, "");
|
|
5809
|
-
if (shortened !== proxy.name && !usedNames.has(shortened)) {
|
|
5810
|
-
renameMap.set(proxy.name, shortened);
|
|
5811
|
-
usedNames.add(shortened);
|
|
5812
|
-
} else {
|
|
5813
|
-
usedNames.add(proxy.name);
|
|
5814
|
-
}
|
|
5815
|
-
}
|
|
5816
|
-
if (renameMap.size === 0) return 0;
|
|
5817
|
-
for (const proxy of proxies) {
|
|
5818
|
-
const newName = renameMap.get(proxy.name);
|
|
5819
|
-
if (newName) proxy.name = newName;
|
|
5820
|
-
}
|
|
5821
|
-
for (const group of proxyGroups) {
|
|
5822
|
-
if (Array.isArray(group.proxies)) {
|
|
5823
|
-
group.proxies = group.proxies.map((name) => renameMap.get(name) || name);
|
|
5824
|
-
}
|
|
5825
|
-
}
|
|
5826
|
-
const rules = parsed.raw.rules;
|
|
5827
|
-
if (Array.isArray(rules)) {
|
|
5828
|
-
parsed.raw.rules = rules.map((rule) => {
|
|
5829
|
-
if (typeof rule !== "string") return rule;
|
|
5830
|
-
const parts = rule.split(",");
|
|
5831
|
-
if (parts.length < 2) return rule;
|
|
5832
|
-
const targetIdx = parts[parts.length - 1].trim().toLowerCase() === "no-resolve" && parts.length >= 3 ? parts.length - 2 : parts.length - 1;
|
|
5833
|
-
const target = parts[targetIdx].trim();
|
|
5834
|
-
const renamed = renameMap.get(target);
|
|
5835
|
-
if (renamed) parts[targetIdx] = renamed;
|
|
5836
|
-
return parts.join(",");
|
|
5837
|
-
});
|
|
5838
|
-
}
|
|
5839
|
-
return renameMap.size;
|
|
5840
|
-
}
|
|
5841
|
-
function cleanDeadProxies(parsed, deadNames) {
|
|
5842
|
-
const { proxies, proxyGroups } = parsed;
|
|
5843
|
-
const originalCount = proxies.length;
|
|
5844
|
-
parsed.proxies = proxies.filter((p) => !deadNames.has(p.name));
|
|
5845
|
-
const removedProxies = originalCount - parsed.proxies.length;
|
|
5846
|
-
let updatedGroups = 0;
|
|
5847
|
-
const removedGroupNames = /* @__PURE__ */ new Set();
|
|
5848
|
-
for (const group of proxyGroups) {
|
|
5849
|
-
if (Array.isArray(group.proxies)) {
|
|
5850
|
-
const before = group.proxies.length;
|
|
5851
|
-
group.proxies = group.proxies.filter((name) => !deadNames.has(name));
|
|
5852
|
-
if (group.proxies.length < before) {
|
|
5853
|
-
updatedGroups++;
|
|
5854
|
-
}
|
|
5855
|
-
const hasOtherSource = group.use || group["include-all"] || group["include-all-proxies"];
|
|
5856
|
-
if (group.proxies.length === 0 && !hasOtherSource) {
|
|
5857
|
-
removedGroupNames.add(group.name);
|
|
5858
|
-
}
|
|
5859
|
-
}
|
|
5860
|
-
}
|
|
5861
|
-
if (removedGroupNames.size > 0) {
|
|
5862
|
-
parsed.proxyGroups = proxyGroups.filter((g) => !removedGroupNames.has(g.name));
|
|
5863
|
-
for (const group of parsed.proxyGroups) {
|
|
5864
|
-
if (Array.isArray(group.proxies)) {
|
|
5865
|
-
group.proxies = group.proxies.filter((name) => !removedGroupNames.has(name));
|
|
5866
|
-
}
|
|
5867
|
-
}
|
|
5868
|
-
}
|
|
5869
|
-
const removedTargets = /* @__PURE__ */ new Set([...removedGroupNames, ...deadNames]);
|
|
5870
|
-
if (removedTargets.size > 0) {
|
|
5871
|
-
const rules = parsed.raw.rules;
|
|
5872
|
-
if (Array.isArray(rules)) {
|
|
5873
|
-
parsed.raw.rules = rules.filter((rule) => {
|
|
5874
|
-
if (typeof rule !== "string") return true;
|
|
5875
|
-
return !removedTargets.has(getRuleTarget(rule));
|
|
5876
|
-
});
|
|
5877
|
-
}
|
|
5878
|
-
}
|
|
5879
|
-
return { removedProxies, updatedGroups, removedGroups: removedGroupNames.size };
|
|
5880
|
-
}
|
|
5881
|
-
async function autoCleanSubscription(subName, options = {}) {
|
|
5882
|
-
const parsed = loadSubscriptionConfig(subName);
|
|
5883
|
-
const { onResult, onRetryRound, rounds = DEFAULT_CLEAN_ROUNDS, ...testOptions } = options;
|
|
5884
|
-
const wrapOnResult = (round) => onResult ? (r, i, t) => onResult(r, i, t, round) : void 0;
|
|
5885
|
-
const summary = await testSubscriptionProxies(subName, {
|
|
5886
|
-
...testOptions,
|
|
5887
|
-
parsed,
|
|
5888
|
-
onResult: wrapOnResult(1)
|
|
5889
|
-
});
|
|
5890
|
-
let removedProxies = 0;
|
|
5891
|
-
let updatedGroups = 0;
|
|
5892
|
-
let removedGroups = 0;
|
|
5893
|
-
let skipped = false;
|
|
5894
|
-
if (summary.dead > 0) {
|
|
5895
|
-
if (summary.alive === 0 || summary.alive / summary.total < 0.01) {
|
|
5896
|
-
skipped = true;
|
|
5897
|
-
} else {
|
|
5898
|
-
const deadNames = new Set(summary.results.filter((r) => r.delay === null).map((r) => r.name));
|
|
5899
|
-
const deadProxies = parsed.proxies.filter((p) => deadNames.has(p.name));
|
|
5900
|
-
for (let retry = 0; retry < rounds - 1; retry++) {
|
|
5901
|
-
const round = retry + 2;
|
|
5902
|
-
const retryTargets = deadProxies.filter((p) => deadNames.has(p.name));
|
|
5903
|
-
if (retryTargets.length === 0) break;
|
|
5904
|
-
onRetryRound?.(round, retryTargets.length);
|
|
5905
|
-
const retryParsed = { raw: {}, proxies: retryTargets, proxyGroups: [] };
|
|
5906
|
-
const retrySummary = await testSubscriptionProxies(subName, {
|
|
5907
|
-
...testOptions,
|
|
5908
|
-
parsed: retryParsed,
|
|
5909
|
-
onResult: wrapOnResult(round)
|
|
5910
|
-
});
|
|
5911
|
-
for (const r of retrySummary.results) {
|
|
5912
|
-
if (r.delay !== null) {
|
|
5913
|
-
deadNames.delete(r.name);
|
|
5914
|
-
}
|
|
5915
|
-
}
|
|
5916
|
-
}
|
|
5917
|
-
summary.dead = deadNames.size;
|
|
5918
|
-
summary.alive = summary.total - summary.dead;
|
|
5919
|
-
if (deadNames.size > 0) {
|
|
5920
|
-
const cleanResult = cleanDeadProxies(parsed, deadNames);
|
|
5921
|
-
removedProxies = cleanResult.removedProxies;
|
|
5922
|
-
updatedGroups = cleanResult.updatedGroups;
|
|
5923
|
-
removedGroups = cleanResult.removedGroups;
|
|
5924
|
-
}
|
|
5925
|
-
}
|
|
5926
|
-
}
|
|
5927
|
-
if (!skipped && removedProxies > 0) {
|
|
5928
|
-
saveSubscriptionConfig(subName, parsed);
|
|
5929
|
-
}
|
|
5930
|
-
return { summary, removedProxies, updatedGroups, removedGroups, skipped };
|
|
5931
|
-
}
|
|
5932
5576
|
|
|
5933
5577
|
// src/commands/shared.ts
|
|
5934
5578
|
import readline from "readline";
|
|
@@ -5959,78 +5603,6 @@ async function launchOrRestart(mode) {
|
|
|
5959
5603
|
return result.pid;
|
|
5960
5604
|
}
|
|
5961
5605
|
|
|
5962
|
-
// src/progress.ts
|
|
5963
|
-
var IS_TTY = process.stdout.isTTY === true;
|
|
5964
|
-
var BAR_WIDTH = 20;
|
|
5965
|
-
function createProgressPrinter(totalRounds = 1) {
|
|
5966
|
-
let alive = 0;
|
|
5967
|
-
let dead = 0;
|
|
5968
|
-
const resultMap = /* @__PURE__ */ new Map();
|
|
5969
|
-
function render(done, total) {
|
|
5970
|
-
if (!IS_TTY) return;
|
|
5971
|
-
const pct = Math.round(done / total * 100);
|
|
5972
|
-
const filled = Math.round(done / total * BAR_WIDTH);
|
|
5973
|
-
const bar = "\u2588".repeat(filled) + "\u2591".repeat(BAR_WIDTH - filled);
|
|
5974
|
-
process.stdout.write(`\r${bar} ${done}/${total} (${pct}%) | ${colors.green(`\u2713${alive}`)} ${colors.red(`\u2717${dead}`)}`);
|
|
5975
|
-
}
|
|
5976
|
-
return {
|
|
5977
|
-
onResult(result, index, total, round = 1) {
|
|
5978
|
-
if (resultMap.size === 0 && totalRounds > 1) {
|
|
5979
|
-
console.log(`--- \u7B2C 1 \u8F6E\u6D4B\u8BD5 (${total} \u4E2A\u8282\u70B9) ---`);
|
|
5980
|
-
}
|
|
5981
|
-
const prev = resultMap.get(result.name);
|
|
5982
|
-
if (prev) {
|
|
5983
|
-
if (prev.result.delay !== null) alive--;
|
|
5984
|
-
else dead--;
|
|
5985
|
-
}
|
|
5986
|
-
if (result.delay !== null) alive++;
|
|
5987
|
-
else dead++;
|
|
5988
|
-
resultMap.set(result.name, { result, round });
|
|
5989
|
-
render(index + 1, total);
|
|
5990
|
-
},
|
|
5991
|
-
onRetryRound(round, count) {
|
|
5992
|
-
if (IS_TTY) {
|
|
5993
|
-
process.stdout.write("\n");
|
|
5994
|
-
}
|
|
5995
|
-
console.log(`--- \u7B2C ${round} \u8F6E\u91CD\u8BD5 (${count} \u4E2A\u8282\u70B9) ---`);
|
|
5996
|
-
alive = 0;
|
|
5997
|
-
dead = 0;
|
|
5998
|
-
},
|
|
5999
|
-
finish() {
|
|
6000
|
-
if (IS_TTY) {
|
|
6001
|
-
process.stdout.write("\n");
|
|
6002
|
-
}
|
|
6003
|
-
console.log("");
|
|
6004
|
-
if (!IS_TTY) return;
|
|
6005
|
-
const entries = [...resultMap.values()];
|
|
6006
|
-
entries.sort((a, b) => a.result.name.localeCompare(b.result.name));
|
|
6007
|
-
const total = entries.length;
|
|
6008
|
-
console.log("\u8282\u70B9\u6700\u7EC8\u72B6\u6001:");
|
|
6009
|
-
for (let i = 0; i < entries.length; i++) {
|
|
6010
|
-
const { result, round } = entries[i];
|
|
6011
|
-
const prefix = `[${i + 1}/${total}]`;
|
|
6012
|
-
if (result.delay !== null) {
|
|
6013
|
-
const delayColor = result.delay < 300 ? colors.green : result.delay < 800 ? colors.yellow : colors.red;
|
|
6014
|
-
const retryNote = round > 1 ? colors.gray(` (\u7B2C${round}\u8F6E\u901A\u8FC7)`) : "";
|
|
6015
|
-
console.log(`${prefix} ${colors.green("\u2713")} ${result.name} ${delayColor(`${result.delay}ms`)}${retryNote}`);
|
|
6016
|
-
} else {
|
|
6017
|
-
console.log(`${prefix} ${colors.red("\u2717")} ${result.name} ${colors.gray(result.error || "timeout")}`);
|
|
6018
|
-
}
|
|
6019
|
-
}
|
|
6020
|
-
console.log("");
|
|
6021
|
-
}
|
|
6022
|
-
};
|
|
6023
|
-
}
|
|
6024
|
-
function formatCleanSummary(result) {
|
|
6025
|
-
const parts = [`\u79FB\u9664 ${result.removedProxies} \u4E2A\u8282\u70B9`];
|
|
6026
|
-
if (result.removedGroups > 0) parts.push(`\u5220\u9664 ${result.removedGroups} \u4E2A\u7A7A\u5206\u7EC4`);
|
|
6027
|
-
if (result.updatedGroups > 0) parts.push(`\u66F4\u65B0 ${result.updatedGroups} \u4E2A\u5206\u7EC4`);
|
|
6028
|
-
return parts.join(", ");
|
|
6029
|
-
}
|
|
6030
|
-
function formatTestSummary(summary) {
|
|
6031
|
-
return `\u7ED3\u679C: ${colors.green(`${summary.alive} \u5B58\u6D3B`)} / ${colors.red(`${summary.dead} \u5931\u8D25`)} / ${summary.total} \u603B\u8BA1`;
|
|
6032
|
-
}
|
|
6033
|
-
|
|
6034
5606
|
// src/ssh.ts
|
|
6035
5607
|
import { spawn as spawn2 } from "child_process";
|
|
6036
5608
|
import fs8 from "fs";
|
|
@@ -6046,10 +5618,6 @@ function getReservedPorts() {
|
|
|
6046
5618
|
const mixedPort = Number(BASE_CONFIG["mixed-port"]);
|
|
6047
5619
|
if (Number.isInteger(mixedPort)) reserved.set(mixedPort, "mihomo \u6DF7\u5408\u4EE3\u7406\u7AEF\u53E3");
|
|
6048
5620
|
reserved.set(CONTROLLER_PORT, "mihomo \u63A7\u5236\u5668\u7AEF\u53E3");
|
|
6049
|
-
const testPort = Number(TEST_CONFIG["mixed-port"]);
|
|
6050
|
-
if (Number.isInteger(testPort)) reserved.set(testPort, "\u6D4B\u901F\u5B9E\u4F8B\u4EE3\u7406\u7AEF\u53E3");
|
|
6051
|
-
const testController = Number(TEST_CONTROLLER_ADDR.split(":")[1]);
|
|
6052
|
-
if (Number.isInteger(testController)) reserved.set(testController, "\u6D4B\u901F\u5B9E\u4F8B\u63A7\u5236\u5668\u7AEF\u53E3");
|
|
6053
5621
|
return reserved;
|
|
6054
5622
|
}
|
|
6055
5623
|
var SAFE_HOST_RE = /^[A-Za-z0-9][A-Za-z0-9._@-]*$/;
|
|
@@ -6498,7 +6066,35 @@ async function startAutoSshTunnelsWithWarning() {
|
|
|
6498
6066
|
console.log("");
|
|
6499
6067
|
}
|
|
6500
6068
|
}
|
|
6069
|
+
var REMOVED_OPTIONS = {
|
|
6070
|
+
"-r": "--rounds",
|
|
6071
|
+
"--rounds": "--rounds",
|
|
6072
|
+
"-t": "--timeout",
|
|
6073
|
+
"--timeout": "--timeout",
|
|
6074
|
+
"-j": "--concurrency",
|
|
6075
|
+
"--concurrency": "--concurrency",
|
|
6076
|
+
"--no-clean": "--no-clean"
|
|
6077
|
+
};
|
|
6078
|
+
function assertNoRemovedOptions(args) {
|
|
6079
|
+
const hit = args.find((a) => {
|
|
6080
|
+
const name = a.startsWith("--") && a.includes("=") ? a.slice(0, a.indexOf("=")) : a;
|
|
6081
|
+
return Object.hasOwn(REMOVED_OPTIONS, name);
|
|
6082
|
+
});
|
|
6083
|
+
if (!hit) return;
|
|
6084
|
+
throw new CliError(`\u9009\u9879 ${hit} \u5DF2\u79FB\u9664\uFF08v3.10.0\uFF0C\u968F\u8282\u70B9\u6D4B\u901F\u6E05\u7406\u4E00\u5E76\u5220\u9664\uFF09`, {
|
|
6085
|
+
label: "\u53C2\u6570\u9519\u8BEF",
|
|
6086
|
+
hint: [
|
|
6087
|
+
"start \u4E0D\u518D\u5728\u542F\u52A8\u540E\u81EA\u52A8\u6D4B\u901F\u6E05\u7406\u8282\u70B9\uFF0C\u6545\u8D85\u65F6/\u5E76\u53D1/\u8F6E\u6B21\u9009\u9879\u5747\u5DF2\u5931\u6548\u3002",
|
|
6088
|
+
"",
|
|
6089
|
+
"\u8282\u70B9\u6D4B\u901F\u8BF7\u7528 Web \u9762\u677F: mihomo ui",
|
|
6090
|
+
"\u81EA\u52A8\u9009\u8DEF\u8BF7\u5728\u8BA2\u9605\u91CC\u914D\u7F6E url-test \u5206\u7EC4\uFF0C\u7531\u5185\u6838\u6301\u7EED\u6D4B\u901F\u3002",
|
|
6091
|
+
"",
|
|
6092
|
+
"start \u73B0\u6709\u9009\u9879: -s/--no-update, -u/--update-timeout <ms>, --no-ssh"
|
|
6093
|
+
]
|
|
6094
|
+
});
|
|
6095
|
+
}
|
|
6501
6096
|
async function cmdStart(args) {
|
|
6097
|
+
assertNoRemovedOptions(args);
|
|
6502
6098
|
const modeToken = args[1] && !args[1].startsWith("-") ? args[1].toLowerCase() : void 0;
|
|
6503
6099
|
if (modeToken !== void 0 && modeToken !== "tun" && modeToken !== "mixed") {
|
|
6504
6100
|
throw new CliError(`\u672A\u77E5\u7684\u542F\u52A8\u6A21\u5F0F: ${args[1]}`, { hint: "\u7528\u6CD5: mihomo start [tun|mixed]\uFF08\u9ED8\u8BA4 mixed\uFF09" });
|
|
@@ -6511,11 +6107,7 @@ async function cmdStart(args) {
|
|
|
6511
6107
|
if (targetMode === "tun" && daemonEnabled) {
|
|
6512
6108
|
throw new CliError("\u4FDD\u6D3B\u5DF2\u542F\u7528\uFF08\u4EC5\u652F\u6301 Mixed \u6A21\u5F0F\uFF09\uFF0C\u65E0\u6CD5\u542F\u52A8 TUN", { hint: "\u8BF7\u5148\u5173\u95ED\u4FDD\u6D3B: mihomo daemon off" });
|
|
6513
6109
|
}
|
|
6514
|
-
const rounds = parseIntArg(args, "-r", "--rounds", DEFAULT_CLEAN_ROUNDS);
|
|
6515
|
-
const timeout = parseIntArg(args, "-t", "--timeout", DEFAULT_TEST_TIMEOUT);
|
|
6516
|
-
const concurrency = parseIntArg(args, "-j", "--concurrency", DEFAULT_TEST_CONCURRENCY);
|
|
6517
6110
|
const skipUpdate = hasFlag(args, "-s", "--no-update");
|
|
6518
|
-
const skipClean = hasFlag(args, "--no-clean");
|
|
6519
6111
|
const skipSsh = hasFlag(args, "--no-ssh");
|
|
6520
6112
|
const updateTimeout = parseIntArg(args, "-u", "--update-timeout", DEFAULT_AUTO_UPDATE_TIMEOUT);
|
|
6521
6113
|
const sub = requireActiveSubscription("\u6CA1\u6709\u8BA2\u9605\uFF0C\u8BF7\u5148\u6DFB\u52A0\u8BA2\u9605");
|
|
@@ -6561,45 +6153,6 @@ async function cmdStart(args) {
|
|
|
6561
6153
|
if (!skipSsh) {
|
|
6562
6154
|
await startAutoSshTunnelsWithWarning();
|
|
6563
6155
|
}
|
|
6564
|
-
const cleanThreshold = isGithubUrl(sub.url) ? AUTO_CLEAN_THRESHOLD_GITHUB : AUTO_CLEAN_THRESHOLD;
|
|
6565
|
-
if (!skipClean && configInfo.proxies > cleanThreshold) {
|
|
6566
|
-
const cache = readSubscriptionCache();
|
|
6567
|
-
const lastCleanAt = cache[sub.name]?.last_auto_clean_at;
|
|
6568
|
-
const withinCooldown = !!lastCleanAt && Date.now() - new Date(lastCleanAt).getTime() < AUTO_CLEAN_COOLDOWN_HOURS * 60 * 60 * 1e3;
|
|
6569
|
-
if (!withinCooldown) {
|
|
6570
|
-
console.log("");
|
|
6571
|
-
console.log(`\u8282\u70B9\u6570 ${configInfo.proxies} \u8D85\u8FC7 ${cleanThreshold}\uFF0C\u81EA\u52A8\u6E05\u7406\uFF08${AUTO_CLEAN_COOLDOWN_HOURS}h \u5185\u4EC5\u4E00\u6B21\uFF0C--no-clean \u8DF3\u8FC7\uFF09...`);
|
|
6572
|
-
console.log("");
|
|
6573
|
-
await sleep(1e3);
|
|
6574
|
-
const progress = createProgressPrinter(rounds);
|
|
6575
|
-
const cleanResult = await autoCleanSubscription(sub.name, {
|
|
6576
|
-
timeout,
|
|
6577
|
-
concurrency,
|
|
6578
|
-
rounds,
|
|
6579
|
-
onResult: progress.onResult,
|
|
6580
|
-
onRetryRound: progress.onRetryRound
|
|
6581
|
-
});
|
|
6582
|
-
progress.finish();
|
|
6583
|
-
console.log(formatTestSummary(cleanResult.summary));
|
|
6584
|
-
if (cleanResult.skipped) {
|
|
6585
|
-
console.log(colors.yellow("\u5B58\u6D3B\u8282\u70B9\u4E0D\u8DB3 1%\uFF0C\u8DF3\u8FC7\u6E05\u7406\u3002\u8BF7\u68C0\u67E5\u539F\u59CB\u8BA2\u9605\u662F\u5426\u6709\u6548"));
|
|
6586
|
-
} else if (cleanResult.removedProxies > 0) {
|
|
6587
|
-
console.log(`${colors.green("\u5DF2\u6E05\u7406")}: ${formatCleanSummary(cleanResult)}`);
|
|
6588
|
-
console.log("");
|
|
6589
|
-
console.log("\u91CD\u65B0\u52A0\u8F7D\u914D\u7F6E...");
|
|
6590
|
-
if (!daemonEnabled) handleStopResult(stop());
|
|
6591
|
-
try {
|
|
6592
|
-
configInfo = prepareConfigForStart(targetMode, sub.name);
|
|
6593
|
-
const pid = await launchOrRestart(targetMode);
|
|
6594
|
-
console.log(`${colors.green("\u5DF2\u91CD\u542F")}${pid ? ` (PID ${pid})` : ""} \xB7 ${formatProxySummary(configInfo)}`);
|
|
6595
|
-
} catch (e) {
|
|
6596
|
-
if (e instanceof CliError) throw e;
|
|
6597
|
-
throw new CliError(e.message.split("\n")[0], { label: "\u91CD\u542F\u5931\u8D25" });
|
|
6598
|
-
}
|
|
6599
|
-
}
|
|
6600
|
-
saveSubscriptionCache(sub.name, { last_auto_clean_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
6601
|
-
}
|
|
6602
|
-
}
|
|
6603
6156
|
await printStatus();
|
|
6604
6157
|
}
|
|
6605
6158
|
|
|
@@ -6624,13 +6177,6 @@ async function confirmPrompt(question) {
|
|
|
6624
6177
|
});
|
|
6625
6178
|
return answer.toLowerCase() === "y" || answer.toLowerCase() === "yes";
|
|
6626
6179
|
}
|
|
6627
|
-
function requireRunning() {
|
|
6628
|
-
const state = getRunningState();
|
|
6629
|
-
if (!state.running) {
|
|
6630
|
-
const hint = state.daemon ? "mihomo daemon on" : "mihomo start";
|
|
6631
|
-
throw new CliError(`mihomo \u672A\u8FD0\u884C\uFF0C\u8BF7\u5148\u542F\u52A8 (${hint})`);
|
|
6632
|
-
}
|
|
6633
|
-
}
|
|
6634
6180
|
async function restartToApply(args) {
|
|
6635
6181
|
if (!isRestartNeededOnChange()) return false;
|
|
6636
6182
|
const currentMode = getRuntimeMode();
|
|
@@ -6756,32 +6302,18 @@ function openDirectory(args) {
|
|
|
6756
6302
|
throw new CliError(`\u672A\u77E5\u7684\u76EE\u5F55\u76EE\u6807 "${target}"`, { hint });
|
|
6757
6303
|
}
|
|
6758
6304
|
function printDirectoryInfo() {
|
|
6305
|
+
const entries = Object.entries(DIRECTORY_TARGETS).filter(([key]) => key !== "root");
|
|
6306
|
+
const pathWidth = Math.max(...entries.map(([, val]) => val.path.replace(USER_DATA_DIR, ".").length));
|
|
6759
6307
|
console.log("");
|
|
6760
|
-
console.log(
|
|
6761
|
-
console.log(` \u6839\u76EE\u5F55: ${USER_DATA_DIR}`);
|
|
6762
|
-
console.log(` \u5168\u5C40\u8BBE\u7F6E: ${PATHS.settingsFile}`);
|
|
6763
|
-
console.log(` \u5185\u6838\u76EE\u5F55: ${DIRS.kernel}`);
|
|
6764
|
-
console.log(` \u5185\u6838\u6587\u4EF6: ${PATHS.mihomoBinary}`);
|
|
6765
|
-
console.log(` \u8BA2\u9605\u76EE\u5F55: ${DIRS.subscriptions}`);
|
|
6766
|
-
console.log(" - cache.json (\u8BA2\u9605\u7F13\u5B58\uFF1A\u66F4\u65B0\u65F6\u95F4\u3001\u6D41\u91CF\u7B49)");
|
|
6767
|
-
console.log(" - xxx.yaml (\u8BA2\u9605\u539F\u59CB\u914D\u7F6E)");
|
|
6768
|
-
console.log(` \u8FD0\u884C\u65F6\u76EE\u5F55: ${DIRS.runtime}`);
|
|
6769
|
-
console.log(" - config.yaml (\u542F\u52A8\u65F6\u751F\u6210\uFF0Cstop \u81EA\u52A8\u6E05\u9664)");
|
|
6770
|
-
console.log(" - pid (PID \u6587\u4EF6\uFF0Cstop \u81EA\u52A8\u6E05\u9664)");
|
|
6771
|
-
console.log(` \u65E5\u5FD7\u6587\u4EF6: ${PATHS.logFile}`);
|
|
6772
|
-
console.log(` mihomo \u6570\u636E: ${DIRS.data}`);
|
|
6773
|
-
console.log(" - cache.db, Geo*.dat \u7B49 (mihomo \u81EA\u884C\u7BA1\u7406)");
|
|
6308
|
+
console.log(`\u6570\u636E\u76EE\u5F55: ${USER_DATA_DIR}`);
|
|
6774
6309
|
console.log("");
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
console.log(" mihomo dir open data \u6253\u5F00 mihomo \u6570\u636E\u76EE\u5F55");
|
|
6780
|
-
console.log(" mihomo dir open runtime \u6253\u5F00\u8FD0\u884C\u65F6\u76EE\u5F55");
|
|
6781
|
-
console.log(" mihomo dir open kernel \u6253\u5F00\u5185\u6838\u76EE\u5F55");
|
|
6310
|
+
for (const [key, val] of entries) {
|
|
6311
|
+
const rel = val.path.replace(USER_DATA_DIR, ".");
|
|
6312
|
+
console.log(` ${key.padEnd(9)}${rel.padEnd(pathWidth + 2)}${colors.gray(val.label)}`);
|
|
6313
|
+
}
|
|
6782
6314
|
console.log("");
|
|
6783
|
-
console.log(
|
|
6784
|
-
console.log("
|
|
6315
|
+
console.log(`\u6253\u5F00\u76EE\u5F55: mihomo dir open [${Object.keys(DIRECTORY_TARGETS).join("|")}]`);
|
|
6316
|
+
console.log(colors.gray(" \u81EA\u5B9A\u4E49\u6839\u76EE\u5F55: \u73AF\u5883\u53D8\u91CF MIHOMO_CLI_DIR"));
|
|
6785
6317
|
console.log("");
|
|
6786
6318
|
}
|
|
6787
6319
|
var SUBCOMMANDS2 = [
|
|
@@ -6811,7 +6343,7 @@ import { spawnSync as spawnSync4 } from "child_process";
|
|
|
6811
6343
|
import fs9 from "fs";
|
|
6812
6344
|
import path8 from "path";
|
|
6813
6345
|
|
|
6814
|
-
//
|
|
6346
|
+
// node_modules/compare-versions/lib/esm/utils.js
|
|
6815
6347
|
var semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|
6816
6348
|
var validateAndParse = (version) => {
|
|
6817
6349
|
if (typeof version !== "string") {
|
|
@@ -6849,7 +6381,7 @@ var compareSegments = (a, b) => {
|
|
|
6849
6381
|
return 0;
|
|
6850
6382
|
};
|
|
6851
6383
|
|
|
6852
|
-
//
|
|
6384
|
+
// node_modules/compare-versions/lib/esm/compareVersions.js
|
|
6853
6385
|
var compareVersions = (v1, v2) => {
|
|
6854
6386
|
const n1 = validateAndParse(v1);
|
|
6855
6387
|
const n2 = validateAndParse(v2);
|
|
@@ -6872,7 +6404,7 @@ var KERNEL_HTTP_TIMEOUT = 12e4;
|
|
|
6872
6404
|
var KERNEL_DOWNLOAD_TIMEOUT = 18e4;
|
|
6873
6405
|
var HTTP_CLIENT2 = createHttpClient({ timeout: KERNEL_HTTP_TIMEOUT });
|
|
6874
6406
|
function withMirror(url, mirror) {
|
|
6875
|
-
if (mirror &&
|
|
6407
|
+
if (mirror && url.startsWith("https://github.com/")) {
|
|
6876
6408
|
return mirror + url;
|
|
6877
6409
|
}
|
|
6878
6410
|
return url;
|
|
@@ -6915,8 +6447,8 @@ function findMatchingAsset(assets, platform, arch) {
|
|
|
6915
6447
|
});
|
|
6916
6448
|
return standardAsset || matchingAssets[0];
|
|
6917
6449
|
}
|
|
6918
|
-
async function getLatestRelease(repo
|
|
6919
|
-
const url =
|
|
6450
|
+
async function getLatestRelease(repo) {
|
|
6451
|
+
const url = `https://api.github.com/repos/${repo}/releases`;
|
|
6920
6452
|
const response = await HTTP_CLIENT2.get(url, { responseType: "json" });
|
|
6921
6453
|
const releases = response.data;
|
|
6922
6454
|
if (!Array.isArray(releases) || releases.length === 0) {
|
|
@@ -6927,9 +6459,9 @@ async function getLatestRelease(repo, mirror) {
|
|
|
6927
6459
|
);
|
|
6928
6460
|
return stableReleases.length > 0 ? stableReleases[0] : releases[0];
|
|
6929
6461
|
}
|
|
6930
|
-
async function checkUpdate(
|
|
6462
|
+
async function checkUpdate() {
|
|
6931
6463
|
const currentVersion = getKernelVersion();
|
|
6932
|
-
const latest = await getLatestRelease(GITHUB_REPO
|
|
6464
|
+
const latest = await getLatestRelease(GITHUB_REPO);
|
|
6933
6465
|
const latestVersion = latest.tag_name;
|
|
6934
6466
|
let needsUpdate = false;
|
|
6935
6467
|
const currentDisplay = currentVersion || "\u672A\u5B89\u88C5";
|
|
@@ -6969,7 +6501,7 @@ function findBinaryInDir(dir, maxDepth = 4) {
|
|
|
6969
6501
|
}
|
|
6970
6502
|
async function downloadKernel(progressCallback, mirror, releaseInfo) {
|
|
6971
6503
|
ensureDirs();
|
|
6972
|
-
const latest = releaseInfo || await getLatestRelease(GITHUB_REPO
|
|
6504
|
+
const latest = releaseInfo || await getLatestRelease(GITHUB_REPO);
|
|
6973
6505
|
const arch = getArch();
|
|
6974
6506
|
const platform = process.platform;
|
|
6975
6507
|
const asset = findMatchingAsset(latest.assets, platform, arch);
|
|
@@ -7139,14 +6671,12 @@ async function cmdKernel(args) {
|
|
|
7139
6671
|
const mirrorInfo = parseMirrorArg(args);
|
|
7140
6672
|
const effectiveMirror = mirrorInfo.mirror;
|
|
7141
6673
|
if (effectiveMirror) {
|
|
7142
|
-
|
|
7143
|
-
console.log(`\u955C\u50CF: ${effectiveMirror}${mirrorDesc}`);
|
|
6674
|
+
console.log(`\u955C\u50CF: ${effectiveMirror} (\u4EC5\u4E0B\u8F7D\u8D70\u955C\u50CF\uFF0C\u7248\u672C\u67E5\u8BE2\u6052\u76F4\u8FDE)`);
|
|
7144
6675
|
console.log("");
|
|
7145
6676
|
}
|
|
7146
6677
|
console.log("\u68C0\u67E5\u5185\u6838\u66F4\u65B0...");
|
|
7147
6678
|
try {
|
|
7148
|
-
const
|
|
7149
|
-
const info = await checkUpdate(apiMirror);
|
|
6679
|
+
const info = await checkUpdate();
|
|
7150
6680
|
console.log(`\u5F53\u524D: ${info.current}`);
|
|
7151
6681
|
console.log(`\u6700\u65B0: ${info.latest}`);
|
|
7152
6682
|
if (!info.needsUpdate) {
|
|
@@ -7174,8 +6704,7 @@ async function cmdKernel(args) {
|
|
|
7174
6704
|
hint.push(
|
|
7175
6705
|
"",
|
|
7176
6706
|
"\u63D0\u793A: \u76F4\u8FDE\u5931\u8D25\u6216\u4E0B\u8F7D\u8FC7\u6162\u65F6\u53EF\u4F7F\u7528\u955C\u50CF:",
|
|
7177
|
-
" mihomo kernel --mirror [\u955C\u50CF]
|
|
7178
|
-
" mihomo kernel --mirror-all [\u955C\u50CF] # API \u548C\u4E0B\u8F7D\u90FD\u8D70\u955C\u50CF",
|
|
6707
|
+
" mihomo kernel --mirror [\u955C\u50CF] # \u4E0B\u8F7D\u8D70\u955C\u50CF\uFF08\u9ED8\u8BA4 v6.gh-proxy.org\uFF09",
|
|
7179
6708
|
` \u53EF\u7528\u955C\u50CF: ${AVAILABLE_MIRRORS.join(", ")}`
|
|
7180
6709
|
);
|
|
7181
6710
|
}
|
|
@@ -7202,19 +6731,14 @@ function cmdLogs(args) {
|
|
|
7202
6731
|
logPath = getLogPath();
|
|
7203
6732
|
} else {
|
|
7204
6733
|
const parsedIdx = parseInt(targetName, 10);
|
|
7205
|
-
if (
|
|
7206
|
-
|
|
7207
|
-
const archive = archiveLogs.archives[parsedIdx - 1];
|
|
7208
|
-
if (!archive) {
|
|
7209
|
-
throw new CliError(`\u672A\u627E\u5230\u65E5\u5FD7 "${targetName}"`, { hint: '\u4F7F\u7528 "mihomo logs" \u67E5\u770B\u53EF\u7528\u65E5\u5FD7\u5217\u8868' });
|
|
7210
|
-
}
|
|
7211
|
-
logPath = archive.path;
|
|
7212
|
-
} else {
|
|
7213
|
-
logPath = getLogPathByName(targetName);
|
|
6734
|
+
if (Number.isNaN(parsedIdx) || parsedIdx < 1 || String(parsedIdx) !== targetName) {
|
|
6735
|
+
throw new CliError(`\u65E0\u6548\u7684\u65E5\u5FD7\u7F16\u53F7 "${targetName}"`, { hint: "\u7528\u6CD5: mihomo logs <\u7F16\u53F7>\uFF080=\u5F53\u524D\uFF0C1+=\u5F52\u6863\uFF09\uFF1B\u67E5\u770B\u5217\u8868: mihomo logs" });
|
|
7214
6736
|
}
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
6737
|
+
const archive = listLogs().archives[parsedIdx - 1];
|
|
6738
|
+
if (!archive) {
|
|
6739
|
+
throw new CliError(`\u672A\u627E\u5230\u65E5\u5FD7 "${targetName}"`, { hint: '\u4F7F\u7528 "mihomo logs" \u67E5\u770B\u53EF\u7528\u65E5\u5FD7\u5217\u8868' });
|
|
6740
|
+
}
|
|
6741
|
+
logPath = archive.path;
|
|
7218
6742
|
}
|
|
7219
6743
|
if (openInViewer) {
|
|
7220
6744
|
openLogFile(logPath);
|
|
@@ -7777,181 +7301,7 @@ async function cmdSsh(args) {
|
|
|
7777
7301
|
});
|
|
7778
7302
|
}
|
|
7779
7303
|
|
|
7780
|
-
// src/test-instance.ts
|
|
7781
|
-
import { spawn as spawn3 } from "child_process";
|
|
7782
|
-
import fs11 from "fs";
|
|
7783
|
-
import path10 from "path";
|
|
7784
|
-
function isProxyValid(proxy) {
|
|
7785
|
-
if (proxy === null || typeof proxy !== "object") return false;
|
|
7786
|
-
if (!proxy.name || !proxy.server || !proxy.port) return false;
|
|
7787
|
-
if (!proxy.type) return false;
|
|
7788
|
-
if (proxy.type === "ss" && typeof proxy.cipher === "string" && proxy.cipher.startsWith("2022-blake3")) {
|
|
7789
|
-
const pw = String(proxy.password || "");
|
|
7790
|
-
if (!/^[A-Za-z0-9+/\-_]+=*$/.test(pw) || pw.length < 20) return false;
|
|
7791
|
-
}
|
|
7792
|
-
return true;
|
|
7793
|
-
}
|
|
7794
|
-
var TEST_DIR = path10.join(USER_DATA_DIR, "test");
|
|
7795
|
-
var TEST_DIRS = {
|
|
7796
|
-
data: path10.join(TEST_DIR, "data"),
|
|
7797
|
-
runtime: path10.join(TEST_DIR, "runtime")
|
|
7798
|
-
};
|
|
7799
|
-
var TEST_PATHS = {
|
|
7800
|
-
configFile: path10.join(TEST_DIRS.runtime, "config.yaml"),
|
|
7801
|
-
pidFile: path10.join(TEST_DIRS.runtime, "pid"),
|
|
7802
|
-
logFile: path10.join(TEST_DIR, "test.log")
|
|
7803
|
-
};
|
|
7804
|
-
var TEST_API = `http://${TEST_CONFIG["external-controller"]}`;
|
|
7805
|
-
function ensureTestDirs() {
|
|
7806
|
-
for (const dir of Object.values(TEST_DIRS)) {
|
|
7807
|
-
fs11.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
7808
|
-
}
|
|
7809
|
-
}
|
|
7810
|
-
function cleanupTestDir() {
|
|
7811
|
-
rmrf(TEST_DIR);
|
|
7812
|
-
}
|
|
7813
|
-
function buildTestConfig(subName) {
|
|
7814
|
-
ensureTestDirs();
|
|
7815
|
-
const rawContent = readSubscriptionRawConfig(subName);
|
|
7816
|
-
if (!rawContent) {
|
|
7817
|
-
throw new CliError(`\u672A\u627E\u5230\u8BA2\u9605\u914D\u7F6E "${subName}"\uFF0C\u8BF7\u5148\u66F4\u65B0\u8BA2\u9605\uFF08mihomo sub update ${subName}\uFF09`);
|
|
7818
|
-
}
|
|
7819
|
-
const parsed = parseYamlOrJson(rawContent, "\u8BA2\u9605\u5185\u5BB9");
|
|
7820
|
-
const proxies = (parsed.proxies || []).filter(isProxyValid);
|
|
7821
|
-
if (proxies.length === 0) {
|
|
7822
|
-
throw new CliError(`\u8BA2\u9605 "${subName}" \u6CA1\u6709\u6709\u6548\u8282\u70B9`);
|
|
7823
|
-
}
|
|
7824
|
-
const nameCount = /* @__PURE__ */ new Map();
|
|
7825
|
-
for (const proxy of proxies) {
|
|
7826
|
-
const count = (nameCount.get(proxy.name) || 0) + 1;
|
|
7827
|
-
nameCount.set(proxy.name, count);
|
|
7828
|
-
if (count > 1) {
|
|
7829
|
-
proxy.name = `${proxy.name} #${count}`;
|
|
7830
|
-
}
|
|
7831
|
-
}
|
|
7832
|
-
const config = {
|
|
7833
|
-
...TEST_CONFIG,
|
|
7834
|
-
proxies,
|
|
7835
|
-
"proxy-groups": [
|
|
7836
|
-
{
|
|
7837
|
-
name: "PROXY",
|
|
7838
|
-
type: "select",
|
|
7839
|
-
proxies: proxies.map((p) => p.name)
|
|
7840
|
-
}
|
|
7841
|
-
],
|
|
7842
|
-
rules: ["MATCH,PROXY"]
|
|
7843
|
-
};
|
|
7844
|
-
const content = dumpYaml(config);
|
|
7845
|
-
fs11.writeFileSync(TEST_PATHS.configFile, content, { mode: 384 });
|
|
7846
|
-
}
|
|
7847
|
-
async function startTestInstance() {
|
|
7848
|
-
const binary = PATHS.mihomoBinary;
|
|
7849
|
-
if (!fs11.existsSync(binary)) throw new CliError('\u672A\u627E\u5230 mihomo \u5185\u6838\uFF0C\u8BF7\u5148\u8FD0\u884C "mihomo kernel" \u4E0B\u8F7D');
|
|
7850
|
-
stopTestInstance();
|
|
7851
|
-
const logFd = fs11.openSync(TEST_PATHS.logFile, "a");
|
|
7852
|
-
const child = spawn3(binary, ["-d", TEST_DIRS.data, "-f", TEST_PATHS.configFile], {
|
|
7853
|
-
detached: true,
|
|
7854
|
-
stdio: ["ignore", logFd, logFd]
|
|
7855
|
-
});
|
|
7856
|
-
child.on("error", () => {
|
|
7857
|
-
});
|
|
7858
|
-
fs11.closeSync(logFd);
|
|
7859
|
-
child.unref();
|
|
7860
|
-
const pid = child.pid;
|
|
7861
|
-
if (!pid) throw new CliError("\u6D4B\u8BD5\u5B9E\u4F8B\u542F\u52A8\u5931\u8D25\uFF1A\u65E0\u6CD5\u521B\u5EFA\u8FDB\u7A0B\uFF08\u5185\u6838\u4E8C\u8FDB\u5236\u53EF\u80FD\u4E0D\u53EF\u6267\u884C\uFF09");
|
|
7862
|
-
spawnedTestPid = pid;
|
|
7863
|
-
fs11.writeFileSync(TEST_PATHS.pidFile, pid.toString(), { mode: 384 });
|
|
7864
|
-
const client = createHttpClient({ timeout: 2e3 });
|
|
7865
|
-
let ready = false;
|
|
7866
|
-
for (let i = 0; i < 60; i++) {
|
|
7867
|
-
if (!isProcessRunning(pid)) break;
|
|
7868
|
-
try {
|
|
7869
|
-
await client.get(`${TEST_API}/version`);
|
|
7870
|
-
ready = true;
|
|
7871
|
-
break;
|
|
7872
|
-
} catch {
|
|
7873
|
-
await sleep(500);
|
|
7874
|
-
}
|
|
7875
|
-
}
|
|
7876
|
-
if (!isProcessRunning(pid)) {
|
|
7877
|
-
let errorDetail = "";
|
|
7878
|
-
try {
|
|
7879
|
-
errorDetail = fs11.readFileSync(TEST_PATHS.logFile, "utf8").slice(-1e3);
|
|
7880
|
-
} catch {
|
|
7881
|
-
}
|
|
7882
|
-
throw new CliError(`\u6D4B\u8BD5\u5B9E\u4F8B\u542F\u52A8\u5931\u8D25${errorDetail ? `
|
|
7883
|
-
${errorDetail}` : ""}`);
|
|
7884
|
-
}
|
|
7885
|
-
if (!ready) {
|
|
7886
|
-
throw new CliError("\u6D4B\u8BD5\u5B9E\u4F8B\u542F\u52A8\u8D85\u65F6\uFF0CAPI \u672A\u54CD\u5E94");
|
|
7887
|
-
}
|
|
7888
|
-
}
|
|
7889
|
-
var spawnedTestPid = null;
|
|
7890
|
-
function stopTestInstance() {
|
|
7891
|
-
let pid = null;
|
|
7892
|
-
try {
|
|
7893
|
-
const fromFile = parseInt(fs11.readFileSync(TEST_PATHS.pidFile, "utf8").trim(), 10);
|
|
7894
|
-
if (fromFile > 0) pid = fromFile;
|
|
7895
|
-
} catch {
|
|
7896
|
-
}
|
|
7897
|
-
if (pid === null) pid = spawnedTestPid;
|
|
7898
|
-
if (pid === null) return;
|
|
7899
|
-
if (pid > 0 && isProcessRunning(pid) && isProcessCommandMatching(pid, TEST_PATHS.configFile)) {
|
|
7900
|
-
process.kill(pid, "SIGKILL");
|
|
7901
|
-
for (let i = 0; i < 20; i++) {
|
|
7902
|
-
if (!isProcessRunning(pid)) break;
|
|
7903
|
-
sleepSync(100);
|
|
7904
|
-
}
|
|
7905
|
-
}
|
|
7906
|
-
spawnedTestPid = null;
|
|
7907
|
-
try {
|
|
7908
|
-
fs11.unlinkSync(TEST_PATHS.pidFile);
|
|
7909
|
-
} catch {
|
|
7910
|
-
}
|
|
7911
|
-
}
|
|
7912
|
-
async function withTestInstance(subName, fn) {
|
|
7913
|
-
cleanupTestDir();
|
|
7914
|
-
buildTestConfig(subName);
|
|
7915
|
-
const unregister = registerCleanup(() => {
|
|
7916
|
-
stopTestInstance();
|
|
7917
|
-
cleanupTestDir();
|
|
7918
|
-
});
|
|
7919
|
-
try {
|
|
7920
|
-
await startTestInstance();
|
|
7921
|
-
return await fn(TEST_API);
|
|
7922
|
-
} finally {
|
|
7923
|
-
unregister();
|
|
7924
|
-
stopTestInstance();
|
|
7925
|
-
cleanupTestDir();
|
|
7926
|
-
}
|
|
7927
|
-
}
|
|
7928
|
-
|
|
7929
7304
|
// src/commands/subscription.ts
|
|
7930
|
-
function githubRepoUrl(rawUrl) {
|
|
7931
|
-
const match = rawUrl.match(/raw\.githubusercontent\.com\/([^/]+\/[^/]+)/);
|
|
7932
|
-
if (match) return `https://github.com/${match[1]}`;
|
|
7933
|
-
return null;
|
|
7934
|
-
}
|
|
7935
|
-
function resolveTestTarget(args) {
|
|
7936
|
-
const subs = getSubscriptions();
|
|
7937
|
-
if (subs.length === 0) {
|
|
7938
|
-
throw new CliError("\u6CA1\u6709\u8BA2\u9605");
|
|
7939
|
-
}
|
|
7940
|
-
const nameArg = getNonFlagArg(args, 2);
|
|
7941
|
-
const timeout = parseIntArg(args, "-t", "--timeout", DEFAULT_TEST_TIMEOUT);
|
|
7942
|
-
const concurrency = parseIntArg(args, "-j", "--concurrency", DEFAULT_TEST_CONCURRENCY);
|
|
7943
|
-
let target;
|
|
7944
|
-
if (nameArg) {
|
|
7945
|
-
target = resolveSubscription(subs, nameArg);
|
|
7946
|
-
} else {
|
|
7947
|
-
const activeSub = getActiveSubscription();
|
|
7948
|
-
if (!activeSub) {
|
|
7949
|
-
throw new CliError("\u6CA1\u6709\u6D3B\u8DC3\u8BA2\u9605\uFF0C\u8BF7\u6307\u5B9A\u8BA2\u9605\u540D\u79F0");
|
|
7950
|
-
}
|
|
7951
|
-
target = activeSub;
|
|
7952
|
-
}
|
|
7953
|
-
return { target, timeout, concurrency };
|
|
7954
|
-
}
|
|
7955
7305
|
function printRestartHintIfRunning() {
|
|
7956
7306
|
if (getRunningState().running) {
|
|
7957
7307
|
console.log(colors.yellow("\u63D0\u793A: \u8FD0\u884C\u4E2D\u7684\u5B9E\u4F8B\u4ECD\u4F7F\u7528\u65E7\u914D\u7F6E\uFF0C\u6267\u884C mihomo start \u4F7F\u66F4\u65B0\u751F\u6548"));
|
|
@@ -7972,9 +7322,8 @@ function printSubscriptionList() {
|
|
|
7972
7322
|
subs.forEach((s, i) => {
|
|
7973
7323
|
const time = formatDate(s.updated_at);
|
|
7974
7324
|
const defaultMark = activeSub && s.name === activeSub.name ? colors.green(" [\u4F7F\u7528\u4E2D]") : "";
|
|
7975
|
-
const mergeBadge = isMultiUrl(s.url) ? colors.cyan(` [\u5408\u5E76 ${splitUrls(s.url).length} \u6E90]`) : "";
|
|
7976
7325
|
const interval = resolveUpdateInterval(s.url, s.update_interval);
|
|
7977
|
-
console.log(` ${i + 1}. ${s.name}${defaultMark}
|
|
7326
|
+
console.log(` ${i + 1}. ${s.name}${defaultMark}`);
|
|
7978
7327
|
console.log(` ${colors.gray("\u66F4\u65B0: ")}${time} (\u95F4\u9694: ${interval}h)`);
|
|
7979
7328
|
if (s.username) {
|
|
7980
7329
|
console.log(` ${colors.gray("\u7528\u6237: ")}${s.username}`);
|
|
@@ -8002,9 +7351,6 @@ function printSubscriptionList() {
|
|
|
8002
7351
|
console.log("\u65B0\u589E\u8BA2\u9605: mihomo sub add <url> [name]");
|
|
8003
7352
|
console.log("\u66F4\u65B0\u8BA2\u9605: mihomo sub update [name]");
|
|
8004
7353
|
console.log("\u5220\u9664\u8BA2\u9605: mihomo sub remove <name>");
|
|
8005
|
-
console.log("\u6D4B\u8BD5\u8282\u70B9: mihomo sub test [name]");
|
|
8006
|
-
console.log("\u6E05\u7406\u8282\u70B9: mihomo sub clean [name]");
|
|
8007
|
-
console.log("\u6253\u5F00\u9875\u9762: mihomo sub web [name]");
|
|
8008
7354
|
console.log("");
|
|
8009
7355
|
}
|
|
8010
7356
|
async function subAdd(args) {
|
|
@@ -8013,45 +7359,19 @@ async function subAdd(args) {
|
|
|
8013
7359
|
if (!url) {
|
|
8014
7360
|
throw new CliError("\u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u8BA2\u9605 URL");
|
|
8015
7361
|
}
|
|
8016
|
-
if (
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
8029
|
-
try {
|
|
8030
|
-
const info = await downloadMergedSubscription(urls, name);
|
|
8031
|
-
setDefaultSubscription(name);
|
|
8032
|
-
console.log(`\u5DF2\u6DFB\u52A0\u5E76\u5207\u6362\u5230 "${name}" (${formatProxySummary(info)}, \u5408\u5E76 ${urls.length} \u6E90)`);
|
|
8033
|
-
} catch (e) {
|
|
8034
|
-
removeSubscription(name);
|
|
8035
|
-
if (e instanceof CliError) throw new CliError(e.message, { label: "\u6DFB\u52A0\u5931\u8D25", hint: e.hint });
|
|
8036
|
-
throw new CliError(e.message, { label: "\u6DFB\u52A0\u5931\u8D25" });
|
|
8037
|
-
}
|
|
8038
|
-
} else {
|
|
8039
|
-
if (!isValidHttpUrl(url)) {
|
|
8040
|
-
throw new CliError("\u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u8BA2\u9605 URL\uFF08\u9700\u4EE5 http:// \u6216 https:// \u5F00\u5934\uFF09");
|
|
8041
|
-
}
|
|
8042
|
-
console.log(`\u6DFB\u52A0\u8BA2\u9605: ${name}`);
|
|
8043
|
-
addSubscription(url, name);
|
|
8044
|
-
try {
|
|
8045
|
-
const info = await downloadSubscription(url, name);
|
|
8046
|
-
setDefaultSubscription(name);
|
|
8047
|
-
const repoUrl = githubRepoUrl(url);
|
|
8048
|
-
if (repoUrl) saveSubscriptionCache(name, { web_page_url: repoUrl });
|
|
8049
|
-
console.log(`\u5DF2\u6DFB\u52A0\u5E76\u5207\u6362\u5230 "${name}" (${formatProxySummary(info)})`);
|
|
8050
|
-
} catch (e) {
|
|
8051
|
-
removeSubscription(name);
|
|
8052
|
-
if (e instanceof CliError) throw new CliError(e.message, { label: "\u6DFB\u52A0\u5931\u8D25", hint: e.hint });
|
|
8053
|
-
throw new CliError(e.message, { label: "\u6DFB\u52A0\u5931\u8D25" });
|
|
8054
|
-
}
|
|
7362
|
+
if (!isValidHttpUrl(url)) {
|
|
7363
|
+
throw new CliError("\u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u8BA2\u9605 URL\uFF08\u9700\u4EE5 http:// \u6216 https:// \u5F00\u5934\uFF09");
|
|
7364
|
+
}
|
|
7365
|
+
console.log(`\u6DFB\u52A0\u8BA2\u9605: ${name}`);
|
|
7366
|
+
addSubscription(url, name);
|
|
7367
|
+
try {
|
|
7368
|
+
const info = await downloadSubscription(url, name);
|
|
7369
|
+
setDefaultSubscription(name);
|
|
7370
|
+
console.log(`\u5DF2\u6DFB\u52A0\u5E76\u5207\u6362\u5230 "${name}" (${formatProxySummary(info)})`);
|
|
7371
|
+
} catch (e) {
|
|
7372
|
+
removeSubscription(name);
|
|
7373
|
+
if (e instanceof CliError) throw new CliError(e.message, { label: "\u6DFB\u52A0\u5931\u8D25", hint: e.hint });
|
|
7374
|
+
throw new CliError(e.message, { label: "\u6DFB\u52A0\u5931\u8D25" });
|
|
8055
7375
|
}
|
|
8056
7376
|
console.log("");
|
|
8057
7377
|
printSubscriptionList();
|
|
@@ -8113,39 +7433,6 @@ async function subUse(args) {
|
|
|
8113
7433
|
console.log("");
|
|
8114
7434
|
printSubscriptionList();
|
|
8115
7435
|
}
|
|
8116
|
-
async function subWeb(args) {
|
|
8117
|
-
const name = args[2];
|
|
8118
|
-
const subs = getSubscriptionsWithCache();
|
|
8119
|
-
if (subs.length === 0) {
|
|
8120
|
-
throw new CliError("\u6CA1\u6709\u8BA2\u9605");
|
|
8121
|
-
}
|
|
8122
|
-
let target;
|
|
8123
|
-
if (name) {
|
|
8124
|
-
target = resolveSubscription(subs, name);
|
|
8125
|
-
} else {
|
|
8126
|
-
target = getActiveSubscription() || subs[0];
|
|
8127
|
-
}
|
|
8128
|
-
const cached = subs.find((s) => s.name === target.name);
|
|
8129
|
-
let webPageUrl = cached?.web_page_url;
|
|
8130
|
-
if (!webPageUrl) {
|
|
8131
|
-
console.log("\u8BA2\u9605\u4FE1\u606F\u4E2D\u7F3A\u5C11\u9875\u9762\u5730\u5740\uFF0C\u6B63\u5728\u67E5\u8BE2\u8BA2\u9605...");
|
|
8132
|
-
try {
|
|
8133
|
-
const info = isMultiUrl(target.url) ? await downloadMergedSubscription(splitUrls(target.url), target.name, void 0, false) : await downloadSubscription(target.url, target.name, void 0, false);
|
|
8134
|
-
if (!info.webPageUrl) {
|
|
8135
|
-
throw new CliError("\u8BE5\u8BA2\u9605\u6CA1\u6709\u63D0\u4F9B\u9875\u9762\u5730\u5740");
|
|
8136
|
-
}
|
|
8137
|
-
webPageUrl = info.webPageUrl;
|
|
8138
|
-
} catch (e) {
|
|
8139
|
-
if (e instanceof CliError) throw e;
|
|
8140
|
-
throw new CliError(e.message, { label: "\u67E5\u8BE2\u5931\u8D25" });
|
|
8141
|
-
}
|
|
8142
|
-
}
|
|
8143
|
-
console.log(`\u6253\u5F00\u8BA2\u9605\u9875\u9762: ${webPageUrl}`);
|
|
8144
|
-
const opened = openUrl(webPageUrl);
|
|
8145
|
-
if (!opened) {
|
|
8146
|
-
console.log("\u8BF7\u624B\u52A8\u8BBF\u95EE\u4E0A\u9762\u7684\u5730\u5740");
|
|
8147
|
-
}
|
|
8148
|
-
}
|
|
8149
7436
|
async function subRemove(args) {
|
|
8150
7437
|
const name = getNonFlagArg(args, 2);
|
|
8151
7438
|
const subs = getSubscriptions();
|
|
@@ -8178,143 +7465,32 @@ async function subRemove(args) {
|
|
|
8178
7465
|
console.log("");
|
|
8179
7466
|
printSubscriptionList();
|
|
8180
7467
|
}
|
|
8181
|
-
async function subClean(args) {
|
|
8182
|
-
const { target, timeout, concurrency } = resolveTestTarget(args);
|
|
8183
|
-
const rounds = parseIntArg(args, "-r", "--rounds", DEFAULT_CLEAN_ROUNDS);
|
|
8184
|
-
console.log(`\u6E05\u7406\u8BA2\u9605 "${target.name}"...`);
|
|
8185
|
-
console.log(`\u8D85\u65F6: ${timeout}ms \u5E76\u53D1: ${concurrency}`);
|
|
8186
|
-
console.log("");
|
|
8187
|
-
const progress = createProgressPrinter(rounds);
|
|
8188
|
-
const result = await withTestInstance(target.name, async (apiBase) => {
|
|
8189
|
-
return autoCleanSubscription(target.name, {
|
|
8190
|
-
timeout,
|
|
8191
|
-
concurrency,
|
|
8192
|
-
rounds,
|
|
8193
|
-
apiBase,
|
|
8194
|
-
onResult: progress.onResult,
|
|
8195
|
-
onRetryRound: progress.onRetryRound
|
|
8196
|
-
});
|
|
8197
|
-
});
|
|
8198
|
-
progress.finish();
|
|
8199
|
-
console.log(formatTestSummary(result.summary));
|
|
8200
|
-
if (result.skipped) {
|
|
8201
|
-
console.log("");
|
|
8202
|
-
console.log(colors.yellow("\u5B58\u6D3B\u8282\u70B9\u4E0D\u8DB3 1%\uFF0C\u8DF3\u8FC7\u6E05\u7406\u3002\u8BF7\u68C0\u67E5\u539F\u59CB\u8BA2\u9605\u662F\u5426\u6709\u6548"));
|
|
8203
|
-
} else if (result.removedProxies > 0) {
|
|
8204
|
-
console.log(`${colors.green("\u5DF2\u6E05\u7406")}: ${formatCleanSummary(result)}`);
|
|
8205
|
-
if (getRunningState().running) {
|
|
8206
|
-
console.log("");
|
|
8207
|
-
console.log("\u63D0\u793A: \u9700\u8981\u91CD\u542F mihomo \u4F7F\u66F4\u6539\u751F\u6548 (mihomo start)");
|
|
8208
|
-
}
|
|
8209
|
-
}
|
|
8210
|
-
}
|
|
8211
|
-
async function subTest(args) {
|
|
8212
|
-
const { target, timeout, concurrency } = resolveTestTarget(args);
|
|
8213
|
-
console.log(`\u6D4B\u8BD5\u8BA2\u9605 "${target.name}" \u7684\u8282\u70B9\u8FDE\u901A\u6027...`);
|
|
8214
|
-
console.log(`\u8D85\u65F6: ${timeout}ms \u5E76\u53D1: ${concurrency}`);
|
|
8215
|
-
console.log("");
|
|
8216
|
-
const progress = createProgressPrinter();
|
|
8217
|
-
const summary = await withTestInstance(target.name, async (apiBase) => {
|
|
8218
|
-
return testSubscriptionProxies(target.name, {
|
|
8219
|
-
timeout,
|
|
8220
|
-
concurrency,
|
|
8221
|
-
apiBase,
|
|
8222
|
-
onResult: progress.onResult
|
|
8223
|
-
});
|
|
8224
|
-
});
|
|
8225
|
-
progress.finish();
|
|
8226
|
-
console.log(formatTestSummary(summary));
|
|
8227
|
-
}
|
|
8228
7468
|
var SUBCOMMANDS5 = [
|
|
8229
7469
|
{ name: "list", handler: printSubscriptionList },
|
|
8230
7470
|
{ name: "add", handler: subAdd },
|
|
8231
7471
|
{ name: "update", handler: subUpdate },
|
|
8232
7472
|
{ name: "use", handler: subUse },
|
|
8233
|
-
{ name: "
|
|
8234
|
-
{ name: "remove", aliases: ["rm", "delete"], handler: subRemove },
|
|
8235
|
-
{ name: "clean", handler: subClean },
|
|
8236
|
-
{ name: "test", handler: subTest }
|
|
7473
|
+
{ name: "remove", aliases: ["rm", "delete"], handler: subRemove }
|
|
8237
7474
|
];
|
|
8238
7475
|
async function cmdSubscription(args) {
|
|
8239
7476
|
await dispatchSubcommand(args, SUBCOMMANDS5, {
|
|
8240
7477
|
// 无子命令 → 列表;未知子命令 → 报错
|
|
8241
7478
|
fallback: printSubscriptionList,
|
|
8242
7479
|
onUnknown: (action) => {
|
|
7480
|
+
if (action === "test" || action === "clean") {
|
|
7481
|
+
throw new CliError(`sub ${action} \u5DF2\u79FB\u9664\uFF08v3.10.0\uFF09`, {
|
|
7482
|
+
hint: ["\u8282\u70B9\u6D4B\u901F\u6539\u7528 Web \u9762\u677F: mihomo ui\uFF08zash / metacubexd / yacd \u5747\u5185\u7F6E\u9010\u8282\u70B9\u6D4B\u5EF6\u8FDF\uFF09", "\u81EA\u52A8\u9009\u8DEF\u8BF7\u5728\u8BA2\u9605\u91CC\u914D\u7F6E url-test \u5206\u7EC4\uFF0C\u7531\u5185\u6838\u6301\u7EED\u6D4B\u901F\u3002"]
|
|
7483
|
+
});
|
|
7484
|
+
}
|
|
8243
7485
|
const names = SUBCOMMANDS5.flatMap((c) => [c.name, ...c.aliases ?? []]);
|
|
8244
7486
|
const suggestion = suggestSimilar(action, names);
|
|
8245
7487
|
throw new CliError(`\u672A\u77E5\u7684\u8BA2\u9605\u547D\u4EE4: ${action}`, {
|
|
8246
|
-
hint: [...suggestion.length > 0 ? [`\u662F\u5426\u60F3\u8F93\u5165: ${suggestion.join(" / ")}?`] : [], "\u7528\u6CD5: mihomo sub [list|use|add|update|remove
|
|
7488
|
+
hint: [...suggestion.length > 0 ? [`\u662F\u5426\u60F3\u8F93\u5165: ${suggestion.join(" / ")}?`] : [], "\u7528\u6CD5: mihomo sub [list|use|add|update|remove]"]
|
|
8247
7489
|
});
|
|
8248
7490
|
}
|
|
8249
7491
|
});
|
|
8250
7492
|
}
|
|
8251
7493
|
|
|
8252
|
-
// src/commands/test.ts
|
|
8253
|
-
async function cmdTest(args) {
|
|
8254
|
-
const timeout = parseIntArg(args, "-t", "--timeout", DEFAULT_TEST_TIMEOUT);
|
|
8255
|
-
const concurrency = parseIntArg(args, "-j", "--concurrency", DEFAULT_TEST_CONCURRENCY);
|
|
8256
|
-
requireRunning();
|
|
8257
|
-
const activeSub = requireActiveSubscription("\u6CA1\u6709\u6D3B\u8DC3\u8BA2\u9605");
|
|
8258
|
-
console.log(`\u6D4B\u8BD5 "${activeSub.name}" \u8282\u70B9\u8FDE\u901A\u6027...`);
|
|
8259
|
-
console.log(`\u8D85\u65F6: ${timeout}ms \u5E76\u53D1: ${concurrency}`);
|
|
8260
|
-
console.log("");
|
|
8261
|
-
const progress = createProgressPrinter();
|
|
8262
|
-
const summary = await testSubscriptionProxies(activeSub.name, {
|
|
8263
|
-
timeout,
|
|
8264
|
-
concurrency,
|
|
8265
|
-
onResult: progress.onResult
|
|
8266
|
-
});
|
|
8267
|
-
progress.finish();
|
|
8268
|
-
console.log(formatTestSummary(summary));
|
|
8269
|
-
}
|
|
8270
|
-
async function cmdClean(args) {
|
|
8271
|
-
const timeout = parseIntArg(args, "-t", "--timeout", DEFAULT_TEST_TIMEOUT);
|
|
8272
|
-
const concurrency = parseIntArg(args, "-j", "--concurrency", DEFAULT_TEST_CONCURRENCY);
|
|
8273
|
-
const rounds = parseIntArg(args, "-r", "--rounds", DEFAULT_CLEAN_ROUNDS);
|
|
8274
|
-
requireRunning();
|
|
8275
|
-
const activeSub = requireActiveSubscription("\u6CA1\u6709\u6D3B\u8DC3\u8BA2\u9605");
|
|
8276
|
-
console.log(`\u6E05\u7406 "${activeSub.name}" \u5931\u8D25\u8282\u70B9...`);
|
|
8277
|
-
console.log(`\u8D85\u65F6: ${timeout}ms \u5E76\u53D1: ${concurrency}`);
|
|
8278
|
-
console.log("");
|
|
8279
|
-
const progress = createProgressPrinter(rounds);
|
|
8280
|
-
const result = await autoCleanSubscription(activeSub.name, {
|
|
8281
|
-
timeout,
|
|
8282
|
-
concurrency,
|
|
8283
|
-
rounds,
|
|
8284
|
-
onResult: progress.onResult,
|
|
8285
|
-
onRetryRound: progress.onRetryRound
|
|
8286
|
-
});
|
|
8287
|
-
progress.finish();
|
|
8288
|
-
console.log(formatTestSummary(result.summary));
|
|
8289
|
-
if (result.skipped) {
|
|
8290
|
-
console.log("");
|
|
8291
|
-
console.log("\u5B58\u6D3B\u8282\u70B9\u4E0D\u8DB3 1%\uFF0C\u8DF3\u8FC7\u6E05\u7406\u3002\u8BF7\u68C0\u67E5\u539F\u59CB\u8BA2\u9605\u662F\u5426\u6709\u6548");
|
|
8292
|
-
} else if (result.removedProxies === 0) {
|
|
8293
|
-
console.log("\u6240\u6709\u8282\u70B9\u6B63\u5E38\uFF0C\u65E0\u9700\u6E05\u7406");
|
|
8294
|
-
} else {
|
|
8295
|
-
console.log(`${colors.green("\u5DF2\u6E05\u7406")}: ${formatCleanSummary(result)}`);
|
|
8296
|
-
console.log("");
|
|
8297
|
-
console.log("\u91CD\u542F mihomo \u4F7F\u66F4\u6539\u751F\u6548...");
|
|
8298
|
-
const mode = getRuntimeMode();
|
|
8299
|
-
const daemonManaged = isDaemonEnabled();
|
|
8300
|
-
try {
|
|
8301
|
-
if (!daemonManaged) {
|
|
8302
|
-
if (hasRootResidue()) {
|
|
8303
|
-
throw new CliError("\u4E3B\u5B9E\u4F8B\u4EE5 root \u8FD0\u884C\uFF08TUN\uFF09\uFF0C\u505C\u6B62\u5B83\u9700\u8981 sudo", { hint: "\u8BF7\u6539\u7528 mihomo sub clean\uFF08\u9694\u79BB\u5B9E\u4F8B\u6D4B\u901F\uFF0C\u65E0\u9700\u505C\u6B62\u4E3B\u5B9E\u4F8B\uFF09" });
|
|
8304
|
-
}
|
|
8305
|
-
handleStopResult(stop());
|
|
8306
|
-
}
|
|
8307
|
-
const configInfo = prepareConfigForStart(mode, activeSub.name);
|
|
8308
|
-
const pid = await launchOrRestart(mode);
|
|
8309
|
-
const label = daemonManaged ? "\u5DF2\u91CD\u542F (\u4FDD\u6D3B)" : "\u5DF2\u91CD\u542F";
|
|
8310
|
-
console.log(`${colors.green(label)}${pid ? ` (PID ${pid})` : ""} \xB7 ${formatProxySummary(configInfo)}`);
|
|
8311
|
-
} catch (e) {
|
|
8312
|
-
if (e instanceof CliError) throw e;
|
|
8313
|
-
throw new CliError(e.message.split("\n")[0], { label: "\u91CD\u542F\u5931\u8D25" });
|
|
8314
|
-
}
|
|
8315
|
-
}
|
|
8316
|
-
}
|
|
8317
|
-
|
|
8318
7494
|
// src/commands/ui.ts
|
|
8319
7495
|
function cmdUI(args) {
|
|
8320
7496
|
const uiName = args[1] || "zash";
|
|
@@ -8339,7 +7515,7 @@ function cmdUI(args) {
|
|
|
8339
7515
|
}
|
|
8340
7516
|
|
|
8341
7517
|
// src/commands/update.ts
|
|
8342
|
-
import { execFile, spawn as
|
|
7518
|
+
import { execFile, spawn as spawn3 } from "child_process";
|
|
8343
7519
|
import { promisify } from "util";
|
|
8344
7520
|
var execFileAsync = promisify(execFile);
|
|
8345
7521
|
var NPM_VIEW_TIMEOUT_MS = 15e3;
|
|
@@ -8370,7 +7546,7 @@ async function cmdUpdate() {
|
|
|
8370
7546
|
console.log("\u6B63\u5728\u66F4\u65B0 mihomo-cli...");
|
|
8371
7547
|
console.log("");
|
|
8372
7548
|
await new Promise((resolve, reject) => {
|
|
8373
|
-
const npm =
|
|
7549
|
+
const npm = spawn3("npm", ["install", "-g", PKG_NAME], { stdio: "inherit" });
|
|
8374
7550
|
npm.on("close", (code) => {
|
|
8375
7551
|
if (code === 0) {
|
|
8376
7552
|
resolve();
|
|
@@ -8407,7 +7583,7 @@ var COMMANDS = [
|
|
|
8407
7583
|
aliases: ["up"],
|
|
8408
7584
|
handler: cmdStart,
|
|
8409
7585
|
group: "control",
|
|
8410
|
-
usage: ["start [tun|mixed] [-s] [-u ms]
|
|
7586
|
+
usage: ["start [tun|mixed] [-s] [-u ms] [--no-ssh] \u542F\u52A8/\u5207\u6362\u4EE3\u7406 (\u9ED8\u8BA4 mixed)"]
|
|
8411
7587
|
},
|
|
8412
7588
|
{
|
|
8413
7589
|
name: "tun",
|
|
@@ -8464,10 +7640,7 @@ var COMMANDS = [
|
|
|
8464
7640
|
"subscription use <name> \u5207\u6362\u5F53\u524D\u8BA2\u9605",
|
|
8465
7641
|
"subscription add <url> [name] \u6DFB\u52A0\u8BA2\u9605",
|
|
8466
7642
|
"subscription update [name] \u66F4\u65B0\u8BA2\u9605\uFF08\u65E0\u53C2\u66F4\u65B0\u6240\u6709\uFF09",
|
|
8467
|
-
"subscription remove <name> \u5220\u9664\u8BA2\u9605\uFF08\u6A21\u7CCA\u5339\u914D\u9700\u786E\u8BA4\uFF0C-y \u8DF3\u8FC7\uFF09"
|
|
8468
|
-
"subscription web [name] \u6253\u5F00\u8BA2\u9605\u9875\u9762",
|
|
8469
|
-
"subscription test [name] \u6D4B\u8BD5\u8282\u70B9\uFF08\u72EC\u7ACB\u5B9E\u4F8B\uFF0C\u65E0\u9700\u8FD0\u884C\uFF09",
|
|
8470
|
-
"subscription clean [name] \u6D4B\u901F\u6E05\u7406\uFF08\u72EC\u7ACB\u5B9E\u4F8B\uFF0C\u4E0D\u52A8\u4E3B\u5B9E\u4F8B\uFF09[-r N] [-t ms] [-j N]"
|
|
7643
|
+
"subscription remove <name> \u5220\u9664\u8BA2\u9605\uFF08\u6A21\u7CCA\u5339\u914D\u9700\u786E\u8BA4\uFF0C-y \u8DF3\u8FC7\uFF09"
|
|
8471
7644
|
]
|
|
8472
7645
|
},
|
|
8473
7646
|
{
|
|
@@ -8478,20 +7651,6 @@ var COMMANDS = [
|
|
|
8478
7651
|
group: "subscription",
|
|
8479
7652
|
usage: []
|
|
8480
7653
|
},
|
|
8481
|
-
{
|
|
8482
|
-
name: "test",
|
|
8483
|
-
aliases: [],
|
|
8484
|
-
handler: cmdTest,
|
|
8485
|
-
group: "subscription",
|
|
8486
|
-
usage: ["test [-t ms] [-j N] \u6D4B\u8BD5\u5F53\u524D\u8282\u70B9\uFF08\u7ECF\u8FD0\u884C\u4E2D\u7684\u4E3B\u5B9E\u4F8B\uFF09"]
|
|
8487
|
-
},
|
|
8488
|
-
{
|
|
8489
|
-
name: "clean",
|
|
8490
|
-
aliases: [],
|
|
8491
|
-
handler: cmdClean,
|
|
8492
|
-
group: "subscription",
|
|
8493
|
-
usage: ["clean [-t ms] [-j N] [-r N] \u6E05\u7406\u5931\u8D25\u8282\u70B9\u5E76\u91CD\u542F\uFF08\u7ECF\u4E3B\u5B9E\u4F8B\uFF09"]
|
|
8494
|
-
},
|
|
8495
7654
|
// === 配置 ===
|
|
8496
7655
|
{
|
|
8497
7656
|
name: "overwrite",
|
|
@@ -8521,7 +7680,7 @@ var COMMANDS = [
|
|
|
8521
7680
|
aliases: ["dir", "dirs", "directories"],
|
|
8522
7681
|
handler: cmdDirectory,
|
|
8523
7682
|
group: "config",
|
|
8524
|
-
usage: ["directory \u663E\u793A\u6570\u636E\u76EE\u5F55\u4F4D\u7F6E\uFF08\u522B\u540D dir\uFF09", "directory open [target] \u6253\u5F00\u76EE\u5F55: root|subs|logs|runtime
|
|
7683
|
+
usage: ["directory \u663E\u793A\u6570\u636E\u76EE\u5F55\u4F4D\u7F6E\uFF08\u522B\u540D dir\uFF09", "directory open [target] \u6253\u5F00\u76EE\u5F55: root|subs|logs|data|runtime|kernel"]
|
|
8525
7684
|
},
|
|
8526
7685
|
{
|
|
8527
7686
|
name: "open",
|
|
@@ -8537,7 +7696,7 @@ var COMMANDS = [
|
|
|
8537
7696
|
aliases: [],
|
|
8538
7697
|
handler: cmdKernel,
|
|
8539
7698
|
group: "system",
|
|
8540
|
-
usage: ["kernel [--mirror [\u955C\u50CF]]
|
|
7699
|
+
usage: ["kernel [--mirror [\u955C\u50CF]] \u66F4\u65B0\u5185\u6838\uFF08\u9ED8\u8BA4\u76F4\u8FDE\uFF0C--mirror \u8D70\u955C\u50CF\u4E0B\u8F7D\uFF09"]
|
|
8541
7700
|
},
|
|
8542
7701
|
{
|
|
8543
7702
|
name: "daemon",
|
|
@@ -8660,6 +7819,15 @@ function assertSupportedPlatform(commandName) {
|
|
|
8660
7819
|
]
|
|
8661
7820
|
});
|
|
8662
7821
|
}
|
|
7822
|
+
var REMOVED_COMMANDS = {
|
|
7823
|
+
test: ["\u8282\u70B9\u6D4B\u901F\u6539\u7528 Web \u9762\u677F: mihomo ui\uFF08zash / metacubexd / yacd \u5747\u5185\u7F6E\u9010\u8282\u70B9\u6D4B\u5EF6\u8FDF\uFF09", "\u81EA\u52A8\u9009\u8DEF\u8BF7\u5728\u8BA2\u9605\u91CC\u914D\u7F6E url-test \u5206\u7EC4\uFF0C\u7531\u5185\u6838\u6301\u7EED\u6D4B\u901F\u3002"],
|
|
7824
|
+
clean: [
|
|
7825
|
+
"\u6309\u6D4B\u901F\u7ED3\u679C\u5220\u8282\u70B9\u7684\u529F\u80FD\u5DF2\u79FB\u9664\uFF1A\u4E00\u6B21\u6296\u52A8\u5C31\u53EF\u80FD\u6C38\u4E45\u6539\u5199\u8BA2\u9605\u6587\u4EF6\uFF0C\u8BEF\u5220\u53EA\u80FD\u91CD\u4E0B\u8BA2\u9605\u3002",
|
|
7826
|
+
"\u5931\u6548\u8282\u70B9\u4EA4\u7ED9\u5185\u6838\u7684 url-test / fallback \u5206\u7EC4\u81EA\u52A8\u7ED5\u5F00\u5373\u53EF\u3002",
|
|
7827
|
+
"",
|
|
7828
|
+
"\u67E5\u770B\u8282\u70B9\u5EF6\u8FDF: mihomo ui"
|
|
7829
|
+
]
|
|
7830
|
+
};
|
|
8663
7831
|
async function main() {
|
|
8664
7832
|
clearProxyEnv();
|
|
8665
7833
|
const args = process.argv.slice(2);
|
|
@@ -8673,6 +7841,9 @@ async function main() {
|
|
|
8673
7841
|
const token = args[0].toLowerCase();
|
|
8674
7842
|
const command = findCommand(token);
|
|
8675
7843
|
if (!command) {
|
|
7844
|
+
if (Object.hasOwn(REMOVED_COMMANDS, token)) {
|
|
7845
|
+
throw new CliError(`${token} \u5DF2\u79FB\u9664\uFF08v3.10.0\uFF09`, { hint: REMOVED_COMMANDS[token] });
|
|
7846
|
+
}
|
|
8676
7847
|
const suggestion = suggestSimilar(token, allCommandTokens());
|
|
8677
7848
|
throw new CliError(`\u672A\u77E5\u547D\u4EE4: ${token}`, {
|
|
8678
7849
|
hint: [suggestion.length > 0 ? `\u662F\u5426\u60F3\u8F93\u5165: ${suggestion.join(" / ")}?` : '\u4F7F\u7528 "mihomo help" \u67E5\u770B\u5E2E\u52A9']
|