Skip to content

Commit 8250e0f

Browse files
authored
Merge pull request #601 from hhh2210/feat/surgemac-mihomo-local-port
feat(SurgeMac): expose mihomoLocalPort via URL query
2 parents dbc4786 + 8e670fe commit 8250e0f

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

backend/src/restful/download.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,20 @@ function getMihomoExternalOptions(query) {
4242
const mihomoMergeName = useMihomoExternal
4343
? query.mihomoMergeName
4444
: undefined;
45+
let mihomoLocalPort;
46+
if (useMihomoExternal && query.mihomoLocalPort != null) {
47+
const parsed = parseInt(query.mihomoLocalPort, 10);
48+
if (Number.isInteger(parsed) && parsed >= 1 && parsed <= 65535) {
49+
mihomoLocalPort = parsed;
50+
}
51+
}
4552

4653
return {
4754
useMihomoExternal,
4855
mihomoExternal,
4956
mihomoMerge,
5057
mihomoMergeName,
58+
mihomoLocalPort,
5159
};
5260
}
5361

@@ -126,8 +134,13 @@ async function downloadSubscription(req, res) {
126134
let { name, nezhaIndex } = req.params;
127135
const isShareRoute = req.path?.startsWith('/share/');
128136

129-
const { useMihomoExternal, mihomoMerge, mihomoMergeName, mihomoExternal } =
130-
getMihomoExternalOptions(req.query);
137+
const {
138+
useMihomoExternal,
139+
mihomoMerge,
140+
mihomoMergeName,
141+
mihomoExternal,
142+
mihomoLocalPort,
143+
} = getMihomoExternalOptions(req.query);
131144

132145
const platform =
133146
req.query.platform ||
@@ -316,6 +329,7 @@ async function downloadSubscription(req, res) {
316329
merge: mihomoMerge,
317330
mergeName: mihomoMergeName,
318331
mihomoExternal,
332+
localPort: mihomoLocalPort,
319333
prettyYaml,
320334
},
321335
$options,
@@ -533,8 +547,13 @@ async function downloadSubscription(req, res) {
533547
async function downloadCollection(req, res) {
534548
let { name, nezhaIndex } = req.params;
535549

536-
const { useMihomoExternal, mihomoMerge, mihomoMergeName, mihomoExternal } =
537-
getMihomoExternalOptions(req.query);
550+
const {
551+
useMihomoExternal,
552+
mihomoMerge,
553+
mihomoMergeName,
554+
mihomoExternal,
555+
mihomoLocalPort,
556+
} = getMihomoExternalOptions(req.query);
538557

539558
const platform =
540559
req.query.platform ||
@@ -640,6 +659,7 @@ async function downloadCollection(req, res) {
640659
merge: mihomoMerge,
641660
mergeName: mihomoMergeName,
642661
mihomoExternal,
662+
localPort: mihomoLocalPort,
643663
prettyYaml,
644664
},
645665
$options,

0 commit comments

Comments
 (0)