mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-06-04 11:13:59 +08:00
feat: 文件支持 Mihomo 配置, 支持使用覆写; target 名称适配大小写和别名
This commit is contained in:
parent
95b7557635
commit
85a3e2ee54
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.16.2",
|
"version": "2.16.3",
|
||||||
"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": {
|
||||||
|
@ -10,6 +10,7 @@ import { hex_md5 } from '@/vendor/md5';
|
|||||||
import { ProxyUtils } from '@/core/proxy-utils';
|
import { ProxyUtils } from '@/core/proxy-utils';
|
||||||
import { produceArtifact } from '@/restful/sync';
|
import { produceArtifact } from '@/restful/sync';
|
||||||
import { SETTINGS_KEY } from '@/constants';
|
import { SETTINGS_KEY } from '@/constants';
|
||||||
|
import YAML from '@/utils/yaml';
|
||||||
|
|
||||||
import env from '@/utils/env';
|
import env from '@/utils/env';
|
||||||
import {
|
import {
|
||||||
@ -21,6 +22,46 @@ import {
|
|||||||
getRmainingDays,
|
getRmainingDays,
|
||||||
} from '@/utils/flow';
|
} from '@/utils/flow';
|
||||||
|
|
||||||
|
function isObject(item) {
|
||||||
|
return item && typeof item === 'object' && !Array.isArray(item);
|
||||||
|
}
|
||||||
|
function trimWrap(str) {
|
||||||
|
if (str.startsWith('<') && str.endsWith('>')) {
|
||||||
|
return str.slice(1, -1);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
function deepMerge(target, _other) {
|
||||||
|
const other = typeof _other === 'string' ? JSON.parse(_other) : _other;
|
||||||
|
for (const key in other) {
|
||||||
|
if (isObject(other[key])) {
|
||||||
|
if (key.endsWith('!')) {
|
||||||
|
const k = trimWrap(key.slice(0, -1));
|
||||||
|
target[k] = other[key];
|
||||||
|
} else {
|
||||||
|
const k = trimWrap(key);
|
||||||
|
if (!target[k]) Object.assign(target, { [k]: {} });
|
||||||
|
deepMerge(target[k], other[k]);
|
||||||
|
}
|
||||||
|
} else if (Array.isArray(other[key])) {
|
||||||
|
if (key.startsWith('+')) {
|
||||||
|
const k = trimWrap(key.slice(1));
|
||||||
|
if (!target[k]) Object.assign(target, { [k]: [] });
|
||||||
|
target[k] = [...other[key], ...target[k]];
|
||||||
|
} else if (key.endsWith('+')) {
|
||||||
|
const k = trimWrap(key.slice(0, -1));
|
||||||
|
if (!target[k]) Object.assign(target, { [k]: [] });
|
||||||
|
target[k] = [...target[k], ...other[key]];
|
||||||
|
} else {
|
||||||
|
const k = trimWrap(key);
|
||||||
|
Object.assign(target, { [k]: other[key] });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Object.assign(target, { [key]: other[key] });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
The rule "(name CONTAINS "🇨🇳") AND (port IN [80, 443])" can be expressed as follows:
|
The rule "(name CONTAINS "🇨🇳") AND (port IN [80, 443])" can be expressed as follows:
|
||||||
{
|
{
|
||||||
@ -321,6 +362,33 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
|
|||||||
name: 'Script Operator',
|
name: 'Script Operator',
|
||||||
func: async (proxies) => {
|
func: async (proxies) => {
|
||||||
let output = proxies;
|
let output = proxies;
|
||||||
|
if (output?.$file?.type === 'mihomoProfile') {
|
||||||
|
try {
|
||||||
|
let patch = YAML.safeLoad(script);
|
||||||
|
if (typeof patch !== 'object') patch = {};
|
||||||
|
output.$content = ProxyUtils.yaml.safeDump(
|
||||||
|
deepMerge(
|
||||||
|
{
|
||||||
|
proxies: await produceArtifact({
|
||||||
|
type:
|
||||||
|
output?.$file?.sourceType ||
|
||||||
|
'collection',
|
||||||
|
name: output?.$file?.sourceName,
|
||||||
|
platform: 'mihomo',
|
||||||
|
produceType: 'internal',
|
||||||
|
produceOpts: {
|
||||||
|
'delete-underscore-fields': true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
patch,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return output;
|
||||||
|
} catch (e) {
|
||||||
|
// console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
await (async function () {
|
await (async function () {
|
||||||
const operator = createDynamicFunction(
|
const operator = createDynamicFunction(
|
||||||
'operator',
|
'operator',
|
||||||
@ -339,9 +407,27 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
|
|||||||
'operator',
|
'operator',
|
||||||
`async function operator(input = []) {
|
`async function operator(input = []) {
|
||||||
if (input && (input.$files || input.$content)) {
|
if (input && (input.$files || input.$content)) {
|
||||||
let { $content, $files, $options } = input
|
let { $content, $files, $options, $file } = input
|
||||||
${script}
|
if($file.type === 'mihomoProfile') {
|
||||||
return { $content, $files, $options }
|
${script}
|
||||||
|
if(typeof main === 'function') {
|
||||||
|
const config = {
|
||||||
|
proxies: await produceArtifact({
|
||||||
|
type: $file.sourceType || 'collection',
|
||||||
|
name: $file.sourceName,
|
||||||
|
platform: 'mihomo',
|
||||||
|
produceType: 'internal',
|
||||||
|
produceOpts: {
|
||||||
|
'delete-underscore-fields': true
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
$content = ProxyUtils.yaml.safeDump(await main(config))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
${script}
|
||||||
|
}
|
||||||
|
return { $content, $files, $options, $file }
|
||||||
} else {
|
} else {
|
||||||
let proxies = input
|
let proxies = input
|
||||||
let list = []
|
let list = []
|
||||||
|
@ -180,7 +180,7 @@ 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'];
|
||||||
if (type !== 'internal') {
|
if (type !== 'internal' || opts['delete-underscore-fields']) {
|
||||||
for (const key in proxy) {
|
for (const key in proxy) {
|
||||||
if (proxy[key] == null || /^_/i.test(key)) {
|
if (proxy[key] == null || /^_/i.test(key)) {
|
||||||
delete proxy[key];
|
delete proxy[key];
|
||||||
|
@ -20,20 +20,37 @@ function JSON_Producer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
qx: QX_Producer(),
|
||||||
QX: QX_Producer(),
|
QX: QX_Producer(),
|
||||||
QuantumultX: QX_Producer(),
|
QuantumultX: QX_Producer(),
|
||||||
|
surge: Surge_Producer(),
|
||||||
Surge: Surge_Producer(),
|
Surge: Surge_Producer(),
|
||||||
SurgeMac: SurgeMac_Producer(),
|
SurgeMac: SurgeMac_Producer(),
|
||||||
Loon: Loon_Producer(),
|
Loon: Loon_Producer(),
|
||||||
Clash: Clash_Producer(),
|
Clash: Clash_Producer(),
|
||||||
|
meta: ClashMeta_Producer(),
|
||||||
|
clashmeta: ClashMeta_Producer(),
|
||||||
|
'clash.meta': ClashMeta_Producer(),
|
||||||
|
'Clash.Meta': ClashMeta_Producer(),
|
||||||
ClashMeta: ClashMeta_Producer(),
|
ClashMeta: ClashMeta_Producer(),
|
||||||
|
mihomo: ClashMeta_Producer(),
|
||||||
|
Mihomo: ClashMeta_Producer(),
|
||||||
|
uri: URI_Producer(),
|
||||||
URI: URI_Producer(),
|
URI: URI_Producer(),
|
||||||
|
v2: V2Ray_Producer(),
|
||||||
|
v2ray: V2Ray_Producer(),
|
||||||
V2Ray: V2Ray_Producer(),
|
V2Ray: V2Ray_Producer(),
|
||||||
|
json: JSON_Producer(),
|
||||||
JSON: JSON_Producer(),
|
JSON: JSON_Producer(),
|
||||||
|
stash: Stash_Producer(),
|
||||||
Stash: Stash_Producer(),
|
Stash: Stash_Producer(),
|
||||||
|
shadowrocket: Shadowrocket_Producer(),
|
||||||
Shadowrocket: Shadowrocket_Producer(),
|
Shadowrocket: Shadowrocket_Producer(),
|
||||||
ShadowRocket: Shadowrocket_Producer(),
|
ShadowRocket: Shadowrocket_Producer(),
|
||||||
|
surfboard: Surfboard_Producer(),
|
||||||
Surfboard: Surfboard_Producer(),
|
Surfboard: Surfboard_Producer(),
|
||||||
|
singbox: singbox_Producer(),
|
||||||
'sing-box': singbox_Producer(),
|
'sing-box': singbox_Producer(),
|
||||||
|
egern: Egern_Producer(),
|
||||||
Egern: Egern_Producer(),
|
Egern: Egern_Producer(),
|
||||||
};
|
};
|
||||||
|
@ -67,7 +67,7 @@ async function previewFile(req, res) {
|
|||||||
const processed =
|
const processed =
|
||||||
Array.isArray(file.process) && file.process.length > 0
|
Array.isArray(file.process) && file.process.length > 0
|
||||||
? await ProxyUtils.process(
|
? await ProxyUtils.process(
|
||||||
{ $files: files, $content: filesContent },
|
{ $files: files, $content: filesContent, $file: file },
|
||||||
file.process,
|
file.process,
|
||||||
)
|
)
|
||||||
: { $content: filesContent, $files: files };
|
: { $content: filesContent, $files: files };
|
||||||
|
@ -512,7 +512,12 @@ async function produceArtifact({
|
|||||||
const processed =
|
const processed =
|
||||||
Array.isArray(file.process) && file.process.length > 0
|
Array.isArray(file.process) && file.process.length > 0
|
||||||
? await ProxyUtils.process(
|
? await ProxyUtils.process(
|
||||||
{ $files: files, $content: filesContent, $options },
|
{
|
||||||
|
$files: files,
|
||||||
|
$content: filesContent,
|
||||||
|
$options,
|
||||||
|
$file: file,
|
||||||
|
},
|
||||||
file.process,
|
file.process,
|
||||||
)
|
)
|
||||||
: { $content: filesContent, $files: files, $options };
|
: { $content: filesContent, $files: files, $options };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user