From 9ca21142cfcae513cb7dee4a6ecbccb4169ab58d Mon Sep 17 00:00:00 2001 From: xream Date: Mon, 12 Jan 2026 05:34:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=A0=E6=95=88=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=81=87=E8=8A=82=E7=82=B9(=E9=98=B2?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=BC=93=E5=AD=98)(=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=20>=3D=202.15.93)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/download.js | 20 ++++++++++++++++--- backend/src/restful/file.js | 2 +- backend/src/restful/index.js | 35 ++++++++++++++++++++++++++++++--- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/backend/package.json b/backend/package.json index 388afd5a..df302bd3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.20.80", + "version": "2.20.81", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/download.js b/backend/src/restful/download.js index a81a14a1..6c8afd70 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -108,7 +108,9 @@ async function downloadSubscription(req, res) { resultFormat, proxy, noCache, + _fakeNode, } = req.query; + let $options = { _req: { method: req.method, @@ -190,7 +192,13 @@ async function downloadSubscription(req, res) { } const allSubs = $.read(SUBS_KEY); - const sub = findByName(allSubs, name); + const fakeSub = { + name: 'fakeNodeInfo', + source: 'local', + content: + 'invalid share = ss, 1.0.0.1, 80, encrypt-method=aes-128-gcm, password=password', + }; + const sub = _fakeNode ? fakeSub : findByName(allSubs, name); if (sub) { try { const passThroughUA = sub.passThroughUA; @@ -200,7 +208,7 @@ async function downloadSubscription(req, res) { ); ua = reqUA; } - let output = await produceArtifact({ + const opt = { type: 'subscription', name, platform, @@ -217,7 +225,13 @@ async function downloadSubscription(req, res) { $options, proxy, noCache, - }); + }; + if (_fakeNode) { + $.info(`返回假节点信息`); + delete opt.name; + opt.subscription = fakeSub; + } + let output = await produceArtifact(opt); let flowInfo; if ( sub.source !== 'local' || diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index 5f0af8b9..1ee2ba97 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -49,7 +49,7 @@ function createFile(req, res) { success(res, file, 201); } -async function getFile(req, res) { +async function getFile(req, res, next) { let { name } = req.params; const reqUA = req.headers['user-agent'] || req.headers['User-Agent']; $.info(`正在下载文件:${name}\n请求 User-Agent: ${reqUA}`); diff --git a/backend/src/restful/index.js b/backend/src/restful/index.js index a7e7693d..e0452abd 100644 --- a/backend/src/restful/index.js +++ b/backend/src/restful/index.js @@ -6,7 +6,7 @@ import migrate from '@/utils/migration'; import download, { downloadFile } from '@/utils/download'; import { syncArtifacts, produceArtifact } from '@/restful/sync'; import { gistBackupAction } from '@/restful/miscs'; -import { TOKENS_KEY } from '@/constants'; +import { TOKENS_KEY, SETTINGS_KEY } from '@/constants'; import registerSubscriptionRoutes from './subscriptions'; import registerCollectionRoutes from './collections'; @@ -71,12 +71,26 @@ export default function serve() { const token = tokens.find( (t) => t.token === req.query.token && - `/share/${t.type}/${t.name}` === pathname && + (`/share/${t.type}/${t.name}` === pathname || + pathname.startsWith( + `/share/${t.type}/${t.name}/`, + )) && (t.exp == null || t.exp > Date.now()), ); if (token) { next(); return; + } else { + const settings = $.read(SETTINGS_KEY); + if (settings?.appearanceSetting?.invalidShareFakeNode) { + req.query._fakeNode = true; + req.url = req.url.replace( + /\/share\/.*?\//, + '/share/sub/', + ); + next(); + return; + } } } if (be_merge && fe_path && req.path.indexOf('/', 1) == -1) { @@ -378,7 +392,22 @@ export default function serve() { t.name === req.params.name && (t.exp == null || t.exp > Date.now()), ); - if (!token) throw new Error('Forbbiden'); + if (!token) { + const settings = $.read(SETTINGS_KEY); + if ( + settings?.appearanceSetting + ?.invalidShareFakeNode + ) { + return req.originalUrl + .replace( + /\/share\/.*?\//, + '/share/sub/', + ) + .replace('?', '?_fakeNode=true&'); + } else { + return '/404'; + } + } return req.originalUrl; }, }),