From 35dd4f31fc0731cc78cce42252a49b7a59bbb157 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 27 Dec 2024 11:54:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Clash=20=E8=AE=A2=E9=98=85=E4=BB=85?= =?UTF-8?q?=E7=BC=93=E5=AD=98=20proxies=20=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/utils/download.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/package.json b/backend/package.json index 9ff6995..658cd71 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.452", + "version": "2.14.453", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/utils/download.js b/backend/src/utils/download.js index 68293b6..b11ec4e 100644 --- a/backend/src/utils/download.js +++ b/backend/src/utils/download.js @@ -11,6 +11,10 @@ import { validCheck, } from '@/utils/flow'; import $ from '@/core/app'; +import PROXY_PREPROCESSORS from '@/core/proxy-utils/preprocessors'; +const clashPreprocessor = PROXY_PREPROCESSORS.find( + (processor) => processor.name === 'Clash Pre-processor', +); const tasks = new Map(); @@ -172,7 +176,7 @@ export default async function download( `Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nURL: ${url}`, ); try { - const { body, headers, statusCode } = await http.get({ + let { body, headers, statusCode } = await http.get({ url, ...(proxy ? { proxy } : {}), ...(isLoon && proxy ? { node: proxy } : {}), @@ -193,6 +197,13 @@ export default async function download( } if (body.replace(/\s/g, '').length === 0) throw new Error(new Error('远程资源内容为空')); + try { + if (clashPreprocessor.test(body)) { + body = clashPreprocessor.parse(body); + } + } catch (e) { + $.error(`Clash Pre-processor error: ${e}`); + } let shouldCache = true; if (cacheThreshold) { const size = body.length / 1024;