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",
"version": "2.14.254",
"version": "2.14.255",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

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

View File

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

View File

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