diff --git a/backend/package.json b/backend/package.json index 37d5372..3791e62 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.344", + "version": "2.14.345", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index d589a6e..db865b4 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -1,4 +1,5 @@ import { deleteByName, findByName, updateByName } from '@/utils/database'; +import { getFlowHeaders } from '@/utils/flow'; import { FILES_KEY } from '@/constants'; import { failed, success } from '@/restful/response'; import $ from '@/core/app'; @@ -50,7 +51,15 @@ async function getFile(req, res) { name = decodeURIComponent(name); $.info(`正在下载文件:${name}`); - let { url, ua, content, mergeSources, ignoreFailedRemoteFile } = req.query; + let { + url, + subInfoUrl, + subInfoUserAgent, + ua, + content, + mergeSources, + ignoreFailedRemoteFile, + } = req.query; if (url) { url = decodeURIComponent(url); $.info(`指定远程文件 URL: ${url}`); @@ -59,6 +68,14 @@ async function getFile(req, res) { ua = decodeURIComponent(ua); $.info(`指定远程文件 User-Agent: ${ua}`); } + if (subInfoUrl) { + subInfoUrl = decodeURIComponent(subInfoUrl); + $.info(`指定获取流量的 subInfoUrl: ${subInfoUrl}`); + } + if (subInfoUserAgent) { + subInfoUserAgent = decodeURIComponent(subInfoUserAgent); + $.info(`指定获取流量的 subInfoUserAgent: ${subInfoUserAgent}`); + } if (content) { content = decodeURIComponent(content); $.info(`指定本地文件: ${content}`); @@ -86,6 +103,26 @@ async function getFile(req, res) { ignoreFailedRemoteFile, }); + try { + subInfoUrl = subInfoUrl || file.subInfoUrl; + if (subInfoUrl) { + // forward flow headers + const flowInfo = await getFlowHeaders( + subInfoUrl, + subInfoUserAgent || file.subInfoUserAgent, + ); + if (flowInfo) { + res.set('subscription-userinfo', flowInfo); + } + } + } catch (err) { + $.error( + `文件 ${name} 获取流量信息时发生错误: ${JSON.stringify( + err, + )}`, + ); + } + res.set('Content-Type', 'text/plain; charset=utf-8').send( output ?? '', );