mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-12-03 09:45:54 +00:00
feat: 新增参数 prettyYaml 输出更易读的块状 YAML, 默认仍是单行 JSON 风格
This commit is contained in:
12 files changed
+128
-39
No files matched your search
@@ -1,4 +1,7 @@
|
||||
import { isPresent } from '@/core/proxy-utils/producers/utils';
|
||||
import {
|
||||
isPresent,
|
||||
produceProxyListOutput,
|
||||
} from '@/core/proxy-utils/producers/utils';
|
||||
import $ from '@/core/app';
|
||||
|
||||
export default function Clash_Producer() {
|
||||
@@ -213,12 +216,7 @@ export default function Clash_Producer() {
|
||||
}
|
||||
return proxy;
|
||||
});
|
||||
return type === 'internal'
|
||||
? list
|
||||
: 'proxies:\n' +
|
||||
list
|
||||
.map((proxy) => ' - ' + JSON.stringify(proxy) + '\n')
|
||||
.join('');
|
||||
return produceProxyListOutput(list, type, opts);
|
||||
};
|
||||
return { type, produce };
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import { isPresent } from '@/core/proxy-utils/producers/utils';
|
||||
import {
|
||||
isPresent,
|
||||
produceProxyListOutput,
|
||||
} from '@/core/proxy-utils/producers/utils';
|
||||
|
||||
const ipVersions = {
|
||||
dual: 'dual',
|
||||
@@ -301,12 +304,7 @@ export default function ClashMeta_Producer() {
|
||||
return proxy;
|
||||
});
|
||||
|
||||
return type === 'internal'
|
||||
? list
|
||||
: 'proxies:\n' +
|
||||
list
|
||||
.map((proxy) => ' - ' + JSON.stringify(proxy) + '\n')
|
||||
.join('');
|
||||
return produceProxyListOutput(list, type, opts);
|
||||
};
|
||||
return { type, produce };
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import $ from '@/core/app';
|
||||
import { isPresent } from './utils';
|
||||
import { isPresent, produceProxyListOutput } from './utils';
|
||||
|
||||
export default function Egern_Producer() {
|
||||
const type = 'ALL';
|
||||
const produce = (proxies, type) => {
|
||||
const produce = (proxies, type, opts = {}) => {
|
||||
// https://egernapp.com/zh-CN/docs/configuration/proxies
|
||||
const list = proxies
|
||||
.filter((proxy) => {
|
||||
@@ -572,12 +572,7 @@ export default function Egern_Producer() {
|
||||
}
|
||||
})
|
||||
.filter(Boolean);
|
||||
return type === 'internal'
|
||||
? list
|
||||
: 'proxies:\n' +
|
||||
list
|
||||
.map((proxy) => ' - ' + JSON.stringify(proxy) + '\n')
|
||||
.join('');
|
||||
return produceProxyListOutput(list, type, opts);
|
||||
};
|
||||
return { type, produce };
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import { isPresent } from '@/core/proxy-utils/producers/utils';
|
||||
import {
|
||||
isPresent,
|
||||
produceProxyListOutput,
|
||||
} from '@/core/proxy-utils/producers/utils';
|
||||
import $ from '@/core/app';
|
||||
|
||||
export default function Shadowrocket_Producer() {
|
||||
@@ -271,14 +274,7 @@ export default function Shadowrocket_Producer() {
|
||||
}
|
||||
return proxy;
|
||||
});
|
||||
return type === 'internal'
|
||||
? list
|
||||
: 'proxies:\n' +
|
||||
list
|
||||
.map((proxy) => {
|
||||
return ' - ' + JSON.stringify(proxy) + '\n';
|
||||
})
|
||||
.join('');
|
||||
return produceProxyListOutput(list, type, opts);
|
||||
};
|
||||
return { type, produce };
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import { isPresent } from '@/core/proxy-utils/producers/utils';
|
||||
import {
|
||||
isPresent,
|
||||
produceProxyListOutput,
|
||||
} from '@/core/proxy-utils/producers/utils';
|
||||
import $ from '@/core/app';
|
||||
|
||||
export default function Stash_Producer() {
|
||||
@@ -347,12 +350,7 @@ export default function Stash_Producer() {
|
||||
}
|
||||
return proxy;
|
||||
});
|
||||
return type === 'internal'
|
||||
? list
|
||||
: 'proxies:\n' +
|
||||
list
|
||||
.map((proxy) => ' - ' + JSON.stringify(proxy) + '\n')
|
||||
.join('');
|
||||
return produceProxyListOutput(list, type, opts);
|
||||
};
|
||||
return { type, produce };
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
import YAML from '@/utils/yaml';
|
||||
|
||||
export class Result {
|
||||
constructor(proxy) {
|
||||
@@ -28,3 +29,24 @@ export function isPresent(obj, attr) {
|
||||
const data = _.get(obj, attr);
|
||||
return typeof data !== 'undefined' && data !== null;
|
||||
}
|
||||
|
||||
export function produceProxyListOutput(list, type, opts = {}) {
|
||||
if (type === 'internal') return list;
|
||||
|
||||
if (
|
||||
opts.prettyYaml ||
|
||||
opts['pretty-yaml']
|
||||
) {
|
||||
return YAML.safeDump(
|
||||
{
|
||||
proxies: list,
|
||||
},
|
||||
{
|
||||
lineWidth: -1,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return 'proxies:\n' +
|
||||
list.map((proxy) => ' - ' + JSON.stringify(proxy) + '\n').join('');
|
||||
}
|
||||
Reference in new issue
Block a user