Skip to content

Commit

Permalink
feat: ⚠️ BREAKING CHANG 仅手动指定 target 为 SurgeMac 时, 启用 mihomo 来支援 Surg…
Browse files Browse the repository at this point in the history
…e 本身不支持的协议
  • Loading branch information
xream committed Oct 17, 2024
1 parent 6cf8080 commit 27e693c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.399",
"version": "2.14.400",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
10 changes: 6 additions & 4 deletions backend/src/core/proxy-utils/producers/surgemac.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ export default function SurgeMac_Producer() {
try {
return surge_Producer.produce(proxy, type, opts);
} catch (e) {
$.log(
`${proxy.name} is not supported on ${targetPlatform}, try to use Mihomo(SurgeMac - External Proxy Program) instead`,
);
return mihomo(proxy, type, opts);
if (opts.useMihomoExternal) {
$.log(
`${proxy.name} is not supported on ${targetPlatform}, try to use Mihomo(SurgeMac - External Proxy Program) instead`,
);
return mihomo(proxy, type, opts);
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions backend/src/products/cron-sync-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,23 @@ async function doSync() {
try {
if (artifact.sync && artifact.source) {
$.info(`正在同步云配置:${artifact.name}...`);

const useMihomoExternal =
artifact.platform === 'SurgeMac';

if (useMihomoExternal) {
$.info(
`手动指定了 target 为 SurgeMac, 将使用 Mihomo External`,
);
}
const output = await produceArtifact({
type: artifact.type,
name: artifact.source,
platform: artifact.platform,
produceOpts: {
'include-unsupported-proxy':
artifact.includeUnsupportedProxy,
useMihomoExternal,
},
});

Expand Down
13 changes: 13 additions & 0 deletions backend/src/restful/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ async function downloadSubscription(req, res) {
name = decodeURIComponent(name);
nezhaIndex = decodeURIComponent(nezhaIndex);

const useMihomoExternal = req.query.target === 'SurgeMac';

const platform =
req.query.target || getPlatformFromHeaders(req.headers) || 'JSON';

Expand Down Expand Up @@ -122,6 +124,10 @@ async function downloadSubscription(req, res) {
$.info(`包含不支持的节点: ${includeUnsupportedProxy}`);
}

if (useMihomoExternal) {
$.info(`手动指定了 target 为 SurgeMac, 将使用 Mihomo External`);
}

const allSubs = $.read(SUBS_KEY);
const sub = findByName(allSubs, name);
if (sub) {
Expand All @@ -138,6 +144,7 @@ async function downloadSubscription(req, res) {
produceType,
produceOpts: {
'include-unsupported-proxy': includeUnsupportedProxy,
useMihomoExternal,
},
$options,
proxy,
Expand Down Expand Up @@ -253,6 +260,8 @@ async function downloadCollection(req, res) {
name = decodeURIComponent(name);
nezhaIndex = decodeURIComponent(nezhaIndex);

const useMihomoExternal = req.query.target === 'SurgeMac';

const platform =
req.query.target || getPlatformFromHeaders(req.headers) || 'JSON';

Expand Down Expand Up @@ -310,6 +319,9 @@ async function downloadCollection(req, res) {
includeUnsupportedProxy = decodeURIComponent(includeUnsupportedProxy);
$.info(`包含不支持的节点: ${includeUnsupportedProxy}`);
}
if (useMihomoExternal) {
$.info(`手动指定了 target 为 SurgeMac, 将使用 Mihomo External`);
}

if (collection) {
try {
Expand All @@ -321,6 +333,7 @@ async function downloadCollection(req, res) {
produceType,
produceOpts: {
'include-unsupported-proxy': includeUnsupportedProxy,
useMihomoExternal,
},
$options,
proxy,
Expand Down
17 changes: 17 additions & 0 deletions backend/src/restful/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,24 @@ async function syncArtifacts() {
try {
if (artifact.sync && artifact.source) {
$.info(`正在同步云配置:${artifact.name}...`);

const useMihomoExternal =
artifact.platform === 'SurgeMac';

if (useMihomoExternal) {
$.info(
`手动指定了 target 为 SurgeMac, 将使用 Mihomo External`,
);
}

const output = await produceArtifact({
type: artifact.type,
name: artifact.source,
platform: artifact.platform,
produceOpts: {
'include-unsupported-proxy':
artifact.includeUnsupportedProxy,
useMihomoExternal,
},
});

Expand Down Expand Up @@ -681,12 +692,18 @@ async function syncArtifact(req, res) {
}

try {
const useMihomoExternal = artifact.platform === 'SurgeMac';

if (useMihomoExternal) {
$.info(`手动指定了 target 为 SurgeMac, 将使用 Mihomo External`);
}
const output = await produceArtifact({
type: artifact.type,
name: artifact.source,
platform: artifact.platform,
produceOpts: {
'include-unsupported-proxy': artifact.includeUnsupportedProxy,
useMihomoExternal,
},
});

Expand Down

0 comments on commit 27e693c

Please sign in to comment.