mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-11 03:29:03 +08:00
feat: SurgeMac 支持使用 mihomo 来支援 Surge 本身不支持的协议; 弃用旧的 ssr-local 方案
This commit is contained in:
parent
99d5868cff
commit
75d88c02c7
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.14.373",
|
"version": "2.14.374",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -244,21 +244,10 @@ function produce(proxies, targetPlatform, type, opts = {}) {
|
|||||||
|
|
||||||
$.log(`Producing proxies for target: ${targetPlatform}`);
|
$.log(`Producing proxies for target: ${targetPlatform}`);
|
||||||
if (typeof producer.type === 'undefined' || producer.type === 'SINGLE') {
|
if (typeof producer.type === 'undefined' || producer.type === 'SINGLE') {
|
||||||
let localPort = 10000;
|
|
||||||
let list = proxies
|
let list = proxies
|
||||||
.map((proxy) => {
|
.map((proxy) => {
|
||||||
try {
|
try {
|
||||||
let line = producer.produce(proxy, type, opts);
|
return producer.produce(proxy, type, opts);
|
||||||
if (
|
|
||||||
line.length > 0 &&
|
|
||||||
line.includes('__SubStoreLocalPort__')
|
|
||||||
) {
|
|
||||||
line = line.replace(
|
|
||||||
/__SubStoreLocalPort__/g,
|
|
||||||
localPort++,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return line;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
$.error(
|
$.error(
|
||||||
`Cannot produce proxy: ${JSON.stringify(
|
`Cannot produce proxy: ${JSON.stringify(
|
||||||
|
@ -163,9 +163,11 @@ export default function Clash_Producer() {
|
|||||||
delete proxy.id;
|
delete proxy.id;
|
||||||
delete proxy.resolved;
|
delete proxy.resolved;
|
||||||
delete proxy['no-resolve'];
|
delete proxy['no-resolve'];
|
||||||
for (const key in proxy) {
|
if (type !== 'internal') {
|
||||||
if (proxy[key] == null || /^_/i.test(key)) {
|
for (const key in proxy) {
|
||||||
delete proxy[key];
|
if (proxy[key] == null || /^_/i.test(key)) {
|
||||||
|
delete proxy[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -178,9 +178,11 @@ export default function ClashMeta_Producer() {
|
|||||||
delete proxy.id;
|
delete proxy.id;
|
||||||
delete proxy.resolved;
|
delete proxy.resolved;
|
||||||
delete proxy['no-resolve'];
|
delete proxy['no-resolve'];
|
||||||
for (const key in proxy) {
|
if (type !== 'internal') {
|
||||||
if (proxy[key] == null || /^_/i.test(key)) {
|
for (const key in proxy) {
|
||||||
delete proxy[key];
|
if (proxy[key] == null || /^_/i.test(key)) {
|
||||||
|
delete proxy[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -181,9 +181,11 @@ export default function ShadowRocket_Producer() {
|
|||||||
delete proxy.id;
|
delete proxy.id;
|
||||||
delete proxy.resolved;
|
delete proxy.resolved;
|
||||||
delete proxy['no-resolve'];
|
delete proxy['no-resolve'];
|
||||||
for (const key in proxy) {
|
if (type !== 'internal') {
|
||||||
if (proxy[key] == null || /^_/i.test(key)) {
|
for (const key in proxy) {
|
||||||
delete proxy[key];
|
if (proxy[key] == null || /^_/i.test(key)) {
|
||||||
|
delete proxy[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -272,9 +272,11 @@ export default function Stash_Producer() {
|
|||||||
delete proxy.id;
|
delete proxy.id;
|
||||||
delete proxy.resolved;
|
delete proxy.resolved;
|
||||||
delete proxy['no-resolve'];
|
delete proxy['no-resolve'];
|
||||||
for (const key in proxy) {
|
if (type !== 'internal') {
|
||||||
if (proxy[key] == null || /^_/i.test(key)) {
|
for (const key in proxy) {
|
||||||
delete proxy[key];
|
if (proxy[key] == null || /^_/i.test(key)) {
|
||||||
|
delete proxy[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import { Base64 } from 'js-base64';
|
||||||
import { Result, isPresent } from './utils';
|
import { Result, isPresent } from './utils';
|
||||||
import Surge_Producer from './surge';
|
import Surge_Producer from './surge';
|
||||||
|
import ClashMeta_Producer from './clashmeta';
|
||||||
import { isIPv4, isIPv6 } from '@/utils';
|
import { isIPv4, isIPv6 } from '@/utils';
|
||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
|
|
||||||
@ -8,14 +10,22 @@ const targetPlatform = 'SurgeMac';
|
|||||||
const surge_Producer = Surge_Producer();
|
const surge_Producer = Surge_Producer();
|
||||||
|
|
||||||
export default function SurgeMac_Producer() {
|
export default function SurgeMac_Producer() {
|
||||||
const produce = (proxy) => {
|
const produce = (proxy, type, opts = {}) => {
|
||||||
switch (proxy.type) {
|
switch (proxy.type) {
|
||||||
case 'external':
|
case 'external':
|
||||||
return external(proxy);
|
return external(proxy);
|
||||||
case 'ssr':
|
// case 'ssr':
|
||||||
return shadowsocksr(proxy);
|
// return shadowsocksr(proxy);
|
||||||
default:
|
default: {
|
||||||
return surge_Producer.produce(proxy);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return { produce };
|
return { produce };
|
||||||
@ -60,6 +70,7 @@ function external(proxy) {
|
|||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
function shadowsocksr(proxy) {
|
function shadowsocksr(proxy) {
|
||||||
const external_proxy = {
|
const external_proxy = {
|
||||||
...proxy,
|
...proxy,
|
||||||
@ -101,6 +112,65 @@ function shadowsocksr(proxy) {
|
|||||||
|
|
||||||
return external(external_proxy);
|
return external(external_proxy);
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
function mihomo(proxy, type, opts) {
|
||||||
|
const clashProxy = ClashMeta_Producer().produce([proxy], 'internal')?.[0];
|
||||||
|
if (clashProxy) {
|
||||||
|
const localPort = opts?.localPort || proxy._localPort || 65535;
|
||||||
|
const ipv6 = ['ipv4', 'v4-only'].includes(proxy['ip-version'])
|
||||||
|
? false
|
||||||
|
: true;
|
||||||
|
const external_proxy = {
|
||||||
|
name: proxy.name,
|
||||||
|
type: 'external',
|
||||||
|
exec: proxy._exec || '/usr/local/bin/mihomo',
|
||||||
|
'local-port': localPort,
|
||||||
|
args: [
|
||||||
|
'-config',
|
||||||
|
Base64.encode(
|
||||||
|
JSON.stringify({
|
||||||
|
'mixed-port': localPort,
|
||||||
|
ipv6,
|
||||||
|
mode: 'global',
|
||||||
|
dns: {
|
||||||
|
enable: true,
|
||||||
|
ipv6,
|
||||||
|
nameserver: [
|
||||||
|
'https://223.6.6.6/dns-query',
|
||||||
|
'https://120.53.53.53/dns-query',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
proxies: [
|
||||||
|
{
|
||||||
|
...clashProxy,
|
||||||
|
name: 'proxy',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
'proxy-groups': [
|
||||||
|
{
|
||||||
|
name: 'GLOBAL',
|
||||||
|
type: 'select',
|
||||||
|
proxies: ['proxy'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
addresses: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://manual.nssurge.com/policy/external-proxy.html
|
||||||
|
if (isIP(proxy.server)) {
|
||||||
|
external_proxy.addresses.push(proxy.server);
|
||||||
|
} else {
|
||||||
|
$.log(
|
||||||
|
`Platform ${targetPlatform}, proxy type ${proxy.type}: addresses should be an IP address, but got ${proxy.server}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
opts.localPort = localPort - 1;
|
||||||
|
return external(external_proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function isIP(ip) {
|
function isIP(ip) {
|
||||||
return isIPv4(ip) || isIPv6(ip);
|
return isIPv4(ip) || isIPv6(ip);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user