mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 23:13:43 +00:00
feat: 无效分享返回假节点(防客户端缓存)(前端 >= 2.15.93)
This commit is contained in:
4 files changed
+51
-8
No files matched your search
@@ -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": {
|
||||
|
||||
@@ -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' ||
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user