feat: 支持设置默认 User-Agent

This commit is contained in:
xream 2023-11-25 04:31:17 +08:00
parent 5f1415d9d4
commit 1fc5b764fe
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.14.101", "version": "2.14.102",
"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": {

View File

@ -1,4 +1,4 @@
import { FILES_KEY, MODULES_KEY } from '@/constants'; import { FILES_KEY, MODULES_KEY, SETTINGS_KEY } from '@/constants';
import { findByName } from '@/utils/database'; import { findByName } from '@/utils/database';
import { HTTP, ENV } from '@/vendor/open-api'; import { HTTP, ENV } from '@/vendor/open-api';
import { hex_md5 } from '@/vendor/md5'; import { hex_md5 } from '@/vendor/md5';
@ -45,7 +45,8 @@ export default async function download(url, ua) {
} }
const { isNode } = ENV(); const { isNode } = ENV();
ua = ua || 'Quantumult%20X/1.0.29 (iPhone14,5; iOS 15.4.1)'; const { defaultUserAgent } = $.read(SETTINGS_KEY);
ua = ua || defaultUserAgent || 'clash.meta';
const id = hex_md5(ua + url); const id = hex_md5(ua + url);
if (!isNode && tasks.has(id)) { if (!isNode && tasks.has(id)) {
return tasks.get(id); return tasks.get(id);
@ -63,6 +64,7 @@ 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}`);
http.get(url) http.get(url)
.then((resp) => { .then((resp) => {
const body = resp.body; const body = resp.body;