Skip to content

Commit 9ca2114

Browse files
committed
feat: 无效分享返回假节点(防客户端缓存)(前端 >= 2.15.93)
1 parent 5529183 commit 9ca2114

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.20.80",
3+
"version": "2.20.81",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/restful/download.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ async function downloadSubscription(req, res) {
108108
resultFormat,
109109
proxy,
110110
noCache,
111+
_fakeNode,
111112
} = req.query;
113+
112114
let $options = {
113115
_req: {
114116
method: req.method,
@@ -190,7 +192,13 @@ async function downloadSubscription(req, res) {
190192
}
191193

192194
const allSubs = $.read(SUBS_KEY);
193-
const sub = findByName(allSubs, name);
195+
const fakeSub = {
196+
name: 'fakeNodeInfo',
197+
source: 'local',
198+
content:
199+
'invalid share = ss, 1.0.0.1, 80, encrypt-method=aes-128-gcm, password=password',
200+
};
201+
const sub = _fakeNode ? fakeSub : findByName(allSubs, name);
194202
if (sub) {
195203
try {
196204
const passThroughUA = sub.passThroughUA;
@@ -200,7 +208,7 @@ async function downloadSubscription(req, res) {
200208
);
201209
ua = reqUA;
202210
}
203-
let output = await produceArtifact({
211+
const opt = {
204212
type: 'subscription',
205213
name,
206214
platform,
@@ -217,7 +225,13 @@ async function downloadSubscription(req, res) {
217225
$options,
218226
proxy,
219227
noCache,
220-
});
228+
};
229+
if (_fakeNode) {
230+
$.info(`返回假节点信息`);
231+
delete opt.name;
232+
opt.subscription = fakeSub;
233+
}
234+
let output = await produceArtifact(opt);
221235
let flowInfo;
222236
if (
223237
sub.source !== 'local' ||

backend/src/restful/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function createFile(req, res) {
4949
success(res, file, 201);
5050
}
5151

52-
async function getFile(req, res) {
52+
async function getFile(req, res, next) {
5353
let { name } = req.params;
5454
const reqUA = req.headers['user-agent'] || req.headers['User-Agent'];
5555
$.info(`正在下载文件:${name}\n请求 User-Agent: ${reqUA}`);

backend/src/restful/index.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import migrate from '@/utils/migration';
66
import download, { downloadFile } from '@/utils/download';
77
import { syncArtifacts, produceArtifact } from '@/restful/sync';
88
import { gistBackupAction } from '@/restful/miscs';
9-
import { TOKENS_KEY } from '@/constants';
9+
import { TOKENS_KEY, SETTINGS_KEY } from '@/constants';
1010

1111
import registerSubscriptionRoutes from './subscriptions';
1212
import registerCollectionRoutes from './collections';
@@ -71,12 +71,26 @@ export default function serve() {
7171
const token = tokens.find(
7272
(t) =>
7373
t.token === req.query.token &&
74-
`/share/${t.type}/${t.name}` === pathname &&
74+
(`/share/${t.type}/${t.name}` === pathname ||
75+
pathname.startsWith(
76+
`/share/${t.type}/${t.name}/`,
77+
)) &&
7578
(t.exp == null || t.exp > Date.now()),
7679
);
7780
if (token) {
7881
next();
7982
return;
83+
} else {
84+
const settings = $.read(SETTINGS_KEY);
85+
if (settings?.appearanceSetting?.invalidShareFakeNode) {
86+
req.query._fakeNode = true;
87+
req.url = req.url.replace(
88+
/\/share\/.*?\//,
89+
'/share/sub/',
90+
);
91+
next();
92+
return;
93+
}
8094
}
8195
}
8296
if (be_merge && fe_path && req.path.indexOf('/', 1) == -1) {
@@ -378,7 +392,22 @@ export default function serve() {
378392
t.name === req.params.name &&
379393
(t.exp == null || t.exp > Date.now()),
380394
);
381-
if (!token) throw new Error('Forbbiden');
395+
if (!token) {
396+
const settings = $.read(SETTINGS_KEY);
397+
if (
398+
settings?.appearanceSetting
399+
?.invalidShareFakeNode
400+
) {
401+
return req.originalUrl
402+
.replace(
403+
/\/share\/.*?\//,
404+
'/share/sub/',
405+
)
406+
.replace('?', '?_fakeNode=true&');
407+
} else {
408+
return '/404';
409+
}
410+
}
382411
return req.originalUrl;
383412
},
384413
}),

0 commit comments

Comments
 (0)