mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-11 11:28:59 +08:00
feat: 支持全局请求超时(前端 > 2.14.29)
This commit is contained in:
parent
962bcda9dd
commit
95615d1877
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.14.140",
|
"version": "2.14.141",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -7,7 +7,7 @@ import $ from '@/core/app';
|
|||||||
|
|
||||||
const tasks = new Map();
|
const tasks = new Map();
|
||||||
|
|
||||||
export default async function download(url, ua) {
|
export default async function download(url, ua, timeout) {
|
||||||
let $arguments = {};
|
let $arguments = {};
|
||||||
const rawArgs = url.split('#');
|
const rawArgs = url.split('#');
|
||||||
if (rawArgs.length > 1) {
|
if (rawArgs.length > 1) {
|
||||||
@ -45,17 +45,19 @@ export default async function download(url, ua) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { isNode } = ENV();
|
const { isNode } = ENV();
|
||||||
const { defaultUserAgent } = $.read(SETTINGS_KEY);
|
const { defaultUserAgent, defaultTimeout } = $.read(SETTINGS_KEY);
|
||||||
ua = ua || defaultUserAgent || 'clash.meta';
|
const userAgent = ua || defaultUserAgent || 'clash.meta';
|
||||||
const id = hex_md5(ua + url);
|
const requestTimeout = timeout || defaultTimeout;
|
||||||
|
const id = hex_md5(userAgent + url);
|
||||||
if (!isNode && tasks.has(id)) {
|
if (!isNode && tasks.has(id)) {
|
||||||
return tasks.get(id);
|
return tasks.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const http = HTTP({
|
const http = HTTP({
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': ua,
|
'User-Agent': userAgent,
|
||||||
},
|
},
|
||||||
|
timeout: requestTimeout,
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = new Promise((resolve, reject) => {
|
const result = new Promise((resolve, reject) => {
|
||||||
@ -64,7 +66,9 @@ export default async function download(url, ua) {
|
|||||||
if (!$arguments?.noCache && cached) {
|
if (!$arguments?.noCache && cached) {
|
||||||
resolve(cached);
|
resolve(cached);
|
||||||
} else {
|
} else {
|
||||||
$.info(`Downloading...\nUser-Agent: ${ua}\nURL: ${url}`);
|
$.info(
|
||||||
|
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nURL: ${url}`,
|
||||||
|
);
|
||||||
http.get(url)
|
http.get(url)
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
const body = resp.body;
|
const body = resp.body;
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
|
import { SETTINGS_KEY } from '@/constants';
|
||||||
import { HTTP } from '@/vendor/open-api';
|
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 http = HTTP();
|
||||||
const { headers } = await http.get({
|
const { headers } = await http.get({
|
||||||
url: url
|
url: url
|
||||||
@ -8,8 +16,9 @@ export async function getFlowHeaders(url) {
|
|||||||
.map((i) => i.trim())
|
.map((i) => i.trim())
|
||||||
.filter((i) => i.length)[0],
|
.filter((i) => i.length)[0],
|
||||||
headers: {
|
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) =>
|
const subkey = Object.keys(headers).filter((k) =>
|
||||||
/SUBSCRIPTION-USERINFO/i.test(k),
|
/SUBSCRIPTION-USERINFO/i.test(k),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user