From f524920c137f69d34eecfc245b3ae9ef7bd5c9b4 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 28 Jun 2024 18:34:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20=E6=9F=A5=E8=AF=A2=E6=B5=81=E9=87=8F?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=AE=A2=E9=98=85=E9=93=BE=E6=8E=A5.=20?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=89=88=E4=B8=AD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=AD=A4=E9=93=BE=E6=8E=A5=E5=8F=AF=E5=9C=A8=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E4=B8=AD=E4=BC=A0=E9=80=92=E8=AE=A2=E9=98=85=E6=B5=81=E9=87=8F?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/file.js | 39 ++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) 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 ?? '', );