feat: 支持设置查询远程订阅流量信息时的 User-Agent

This commit is contained in:
xream 2024-03-14 19:45:39 +08:00
parent 25d3cf6ca4
commit 2611dccc73
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
5 changed files with 23 additions and 8 deletions

View File

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

@ -113,7 +113,7 @@ async function downloadSubscription(req, res) {
// forward flow headers // forward flow headers
const flowInfo = await getFlowHeaders( const flowInfo = await getFlowHeaders(
url, url,
undefined, $arguments.flowUserAgent,
undefined, undefined,
sub.proxy, sub.proxy,
); );
@ -250,7 +250,7 @@ async function downloadCollection(req, res) {
if (!$arguments.noFlow) { if (!$arguments.noFlow) {
const flowInfo = await getFlowHeaders( const flowInfo = await getFlowHeaders(
url, url,
undefined, $arguments.flowUserAgent,
undefined, undefined,
sub.proxy, sub.proxy,
); );

View File

@ -115,7 +115,7 @@ async function getFlowInfo(req, res) {
} else { } else {
const flowHeaders = await getFlowHeaders( const flowHeaders = await getFlowHeaders(
url, url,
undefined, $arguments.flowUserAgent,
undefined, undefined,
sub.proxy, sub.proxy,
); );

View File

@ -129,7 +129,12 @@ export default async function download(rawUrl, ua, timeout, proxy) {
if ($arguments?.validCheck) { if ($arguments?.validCheck) {
await validCheck( await validCheck(
parseFlowHeaders( parseFlowHeaders(
await getFlowHeaders(url, undefined, undefined, proxy), await getFlowHeaders(
url,
$arguments.flowUserAgent,
undefined,
proxy,
),
), ),
); );
} }

View File

@ -49,7 +49,11 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy) {
const requestTimeout = timeout || defaultTimeout; const requestTimeout = timeout || defaultTimeout;
const http = HTTP(); const http = HTTP();
try { try {
// $.info(`使用 HEAD 方法获取流量信息: ${url}`); $.info(
`使用 HEAD 方法获取流量信息: ${url}, User-Agent: ${
userAgent || ''
}`,
);
const { headers } = await http.head({ const { headers } = await http.head({
url: url url: url
.split(/[\r\n]+/) .split(/[\r\n]+/)
@ -76,11 +80,17 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy) {
flowInfo = getFlowField(headers); flowInfo = getFlowField(headers);
} catch (e) { } catch (e) {
$.error( $.error(
`使用 HEAD 方法获取流量信息失败: ${url}: ${e.message ?? e}`, `使用 HEAD 方法获取流量信息失败: ${url}, User-Agent: ${
userAgent || ''
}: ${e.message ?? e}`,
); );
} }
if (!flowInfo) { if (!flowInfo) {
$.info(`使用 GET 方法获取流量信息: ${url}`); $.info(
`使用 GET 方法获取流量信息: ${url}, User-Agent: ${
userAgent || ''
}`,
);
const { headers } = await http.get({ const { headers } = await http.get({
url: url url: url
.split(/[\r\n]+/) .split(/[\r\n]+/)