From 95615d1877d29e53c4ff459a408674e3cdc5bc69 Mon Sep 17 00:00:00 2001 From: xream Date: Mon, 8 Jan 2024 07:14:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=B6=85=E6=97=B6(=E5=89=8D=E7=AB=AF=20>=202?= =?UTF-8?q?.14.29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/utils/download.js | 16 ++++++++++------ backend/src/utils/flow.js | 13 +++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/backend/package.json b/backend/package.json index 1787881..e981877 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.140", + "version": "2.14.141", "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 42ef38d..5548385 100644 --- a/backend/src/utils/download.js +++ b/backend/src/utils/download.js @@ -7,7 +7,7 @@ import $ from '@/core/app'; const tasks = new Map(); -export default async function download(url, ua) { +export default async function download(url, ua, timeout) { let $arguments = {}; const rawArgs = url.split('#'); if (rawArgs.length > 1) { @@ -45,17 +45,19 @@ export default async function download(url, ua) { } const { isNode } = ENV(); - const { defaultUserAgent } = $.read(SETTINGS_KEY); - ua = ua || defaultUserAgent || 'clash.meta'; - const id = hex_md5(ua + url); + const { defaultUserAgent, defaultTimeout } = $.read(SETTINGS_KEY); + const userAgent = ua || defaultUserAgent || 'clash.meta'; + const requestTimeout = timeout || defaultTimeout; + const id = hex_md5(userAgent + url); if (!isNode && tasks.has(id)) { return tasks.get(id); } const http = HTTP({ headers: { - 'User-Agent': ua, + 'User-Agent': userAgent, }, + timeout: requestTimeout, }); const result = new Promise((resolve, reject) => { @@ -64,7 +66,9 @@ export default async function download(url, ua) { if (!$arguments?.noCache && cached) { resolve(cached); } else { - $.info(`Downloading...\nUser-Agent: ${ua}\nURL: ${url}`); + $.info( + `Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nURL: ${url}`, + ); http.get(url) .then((resp) => { const body = resp.body; diff --git a/backend/src/utils/flow.js b/backend/src/utils/flow.js index 7c801b5..cdf2bfc 100644 --- a/backend/src/utils/flow.js +++ b/backend/src/utils/flow.js @@ -1,6 +1,14 @@ +import { SETTINGS_KEY } from '@/constants'; import { HTTP } from '@/vendor/open-api'; +import $ from '@/core/app'; -export async function getFlowHeaders(url) { +export async function getFlowHeaders(url, ua, timeout) { + const { defaultFlowUserAgent, defaultTimeout } = $.read(SETTINGS_KEY); + const userAgent = + ua || + defaultFlowUserAgent || + 'Quantumult%20X/1.0.30 (iPhone14,2; iOS 15.6)'; + const requestTimeout = timeout || defaultTimeout; const http = HTTP(); const { headers } = await http.get({ url: url @@ -8,8 +16,9 @@ export async function getFlowHeaders(url) { .map((i) => i.trim()) .filter((i) => i.length)[0], headers: { - 'User-Agent': 'Quantumult%20X/1.0.30 (iPhone14,2; iOS 15.6)', + 'User-Agent': userAgent, }, + timeout: requestTimeout, }); const subkey = Object.keys(headers).filter((k) => /SUBSCRIPTION-USERINFO/i.test(k),