From 25d3cf6ca485e06f26475b0b0bdccc384063d7c2 Mon Sep 17 00:00:00 2001 From: xream Date: Thu, 14 Mar 2024 01:28:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=9A=E8=BF=87=E4=BB=A3=E7=90=86/?= =?UTF-8?q?=E8=8A=82=E7=82=B9/=E7=AD=96=E7=95=A5=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=AE=A2=E9=98=85=20=E7=8E=B0=E5=B7=B2=E6=94=AF=E6=8C=81=20Sur?= =?UTF-8?q?ge,=20Loon,=20Stash,=20Shadowrocket,=20QX,=20Node.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/utils/download.js | 14 +++++++++----- backend/src/utils/flow.js | 21 ++++++++++++++------- backend/src/vendor/open-api.js | 1 + 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/backend/package.json b/backend/package.json index cc9f572..78636cf 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.252", + "version": "2.14.254", "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 6407cb0..a8c8f72 100644 --- a/backend/src/utils/download.js +++ b/backend/src/utils/download.js @@ -53,7 +53,7 @@ export default async function download(rawUrl, ua, timeout, proxy) { // return item.content; // } - const { isNode, isStash } = ENV(); + const { isNode, isStash, isLoon, isShadowRocket, isQX } = ENV(); const { defaultUserAgent, defaultTimeout, cacheThreshold } = $.read(SETTINGS_KEY); const userAgent = ua || defaultUserAgent || 'clash.meta'; @@ -66,8 +66,10 @@ export default async function download(rawUrl, ua, timeout, proxy) { const http = HTTP({ headers: { 'User-Agent': userAgent, - 'X-Stash-Selected-Proxy': - isStash && proxy ? encodeURIComponent(proxy) : undefined, + ...(isStash && proxy + ? { 'X-Stash-Selected-Proxy': encodeURIComponent(proxy) } + : {}), + ...(isShadowRocket && proxy ? { 'X-Surge-Policy': proxy } : {}), }, timeout: requestTimeout, }); @@ -86,8 +88,10 @@ export default async function download(rawUrl, ua, timeout, proxy) { try { const { body, headers } = await http.get({ url, - proxy, - ...getPolicyDescriptor(proxy), + ...(proxy ? { proxy } : {}), + ...(isLoon && proxy ? { node: proxy } : {}), + ...(isQX && proxy ? { opts: { policy: proxy } } : {}), + ...(proxy ? getPolicyDescriptor(proxy) : {}), }); if (headers) { diff --git a/backend/src/utils/flow.js b/backend/src/utils/flow.js index 9d1daa4..a2d5e1b 100644 --- a/backend/src/utils/flow.js +++ b/backend/src/utils/flow.js @@ -34,7 +34,7 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy) { if ($arguments?.noFlow) { return; } - const { isStash } = ENV(); + const { isStash, isLoon, isShadowRocket, isQX } = ENV(); const cached = headersResourceCache.get(url); let flowInfo; if (!$arguments?.noCache && cached) { @@ -57,14 +57,21 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy) { .filter((i) => i.length)[0], headers: { 'User-Agent': userAgent, - 'X-Stash-Selected-Proxy': - isStash && proxy - ? encodeURIComponent(proxy) - : undefined, + ...(isStash && proxy + ? { + 'X-Stash-Selected-Proxy': + encodeURIComponent(proxy), + } + : {}), + ...(isShadowRocket && proxy + ? { 'X-Surge-Policy': proxy } + : {}), }, timeout: requestTimeout, - proxy, - ...getPolicyDescriptor(proxy), + ...(proxy ? { proxy } : {}), + ...(isLoon && proxy ? { node: proxy } : {}), + ...(isQX && proxy ? { opts: { policy: proxy } } : {}), + ...(proxy ? getPolicyDescriptor(proxy) : {}), }); flowInfo = getFlowField(headers); } catch (e) { diff --git a/backend/src/vendor/open-api.js b/backend/src/vendor/open-api.js index 4085422..18bdcba 100644 --- a/backend/src/vendor/open-api.js +++ b/backend/src/vendor/open-api.js @@ -316,6 +316,7 @@ export function HTTP(defaultOptions = { baseURL: '' }) { url: options.url, headers: options.headers, body: options.body, + opts: options.opts, }); } else if (isLoon || isSurge || isNode) { worker = new Promise((resolve, reject) => {