From 751e50bf99d0ea82cf770fad09f3961293043663 Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 30 Jan 2024 22:23:57 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20YAML=20=E8=A7=A3=E6=9E=90=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/index.js | 2 +- .../core/proxy-utils/preprocessors/index.js | 2 +- backend/src/core/rule-utils/producers.js | 2 +- backend/src/utils/yaml.js | 29 +++++++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 backend/src/utils/yaml.js diff --git a/backend/package.json b/backend/package.json index 45c561565..fe1583ff3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index f2043a1ef..5d92fff7f 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -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'; diff --git a/backend/src/core/proxy-utils/preprocessors/index.js b/backend/src/core/proxy-utils/preprocessors/index.js index 01c23428e..2aa2a2987 100644 --- a/backend/src/core/proxy-utils/preprocessors/index.js +++ b/backend/src/core/proxy-utils/preprocessors/index.js @@ -1,4 +1,4 @@ -import { safeLoad } from 'static-js-yaml'; +import { safeLoad } from '@/utils/yaml'; import { Base64 } from 'js-base64'; function HTML() { diff --git a/backend/src/core/rule-utils/producers.js b/backend/src/core/rule-utils/producers.js index 9a7efcc5c..10fd4ac3a 100644 --- a/backend/src/core/rule-utils/producers.js +++ b/backend/src/core/rule-utils/producers.js @@ -1,4 +1,4 @@ -import YAML from 'static-js-yaml'; +import YAML from '@/utils/yaml'; function QXFilter() { const type = 'SINGLE'; diff --git a/backend/src/utils/yaml.js b/backend/src/utils/yaml.js new file mode 100644 index 000000000..6f7c5c400 --- /dev/null +++ b/backend/src/utils/yaml.js @@ -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(/!/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, +};