Skip to content

Commit

Permalink
chore: YAML 解析兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 30, 2024
1 parent a91f978 commit 751e50b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 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.195",
"version": "2.14.196",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/core/proxy-utils/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/core/proxy-utils/preprocessors/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { safeLoad } from 'static-js-yaml';
import { safeLoad } from '@/utils/yaml';
import { Base64 } from 'js-base64';

function HTML() {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/core/rule-utils/producers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import YAML from 'static-js-yaml';
import YAML from '@/utils/yaml';

function QXFilter() {
const type = 'SINGLE';
Expand Down
29 changes: 29 additions & 0 deletions backend/src/utils/yaml.js
Original file line number Diff line number Diff line change
@@ -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,
};

0 comments on commit 751e50b

Please sign in to comment.