chore: YAML 解析兼容

This commit is contained in:
xream 2024-01-30 22:23:57 +08:00
parent a91f978042
commit 751e50bf99
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
5 changed files with 33 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.195",
"version": "2.14.196",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@ -1,4 +1,4 @@
import YAML from 'static-js-yaml';
import YAML from '@/utils/yaml';
import download from '@/utils/download';
import { isIPv4, isIPv6, isValidPortNumber } from '@/utils';
import PROXY_PROCESSORS, { ApplyProcessor } from './processors';

View File

@ -1,4 +1,4 @@
import { safeLoad } from 'static-js-yaml';
import { safeLoad } from '@/utils/yaml';
import { Base64 } from 'js-base64';
function HTML() {

View File

@ -1,4 +1,4 @@
import YAML from 'static-js-yaml';
import YAML from '@/utils/yaml';
function QXFilter() {
const type = 'SINGLE';

29
backend/src/utils/yaml.js Normal file
View File

@ -0,0 +1,29 @@
import YAML from 'static-js-yaml';
function retry(fn, content, ...args) {
try {
return fn(content, ...args);
} catch (e) {
return fn(content.replace(/!<str>/g, ''), ...args);
}
}
export function safeLoad(content, ...args) {
return retry(YAML.safeLoad, content, ...args);
}
export function load(content, ...args) {
return retry(YAML.load, content, ...args);
}
export function safeDump(...args) {
return YAML.safeDump(...args);
}
export function dump(...args) {
return YAML.dump(...args);
}
export default {
safeLoad,
load,
safeDump,
dump,
};