Skip to content

Commit e20d0c1

Browse files
committed
feat: 订阅流量信息中的数值取整以兼容部分客户端解析; 不包含有效节点的订阅不写入乐观缓存
1 parent c566002 commit e20d0c1

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

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.19.74",
3+
"version": "2.19.75",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/utils/download.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import $ from '@/core/app';
1414
import { findByName } from '@/utils/database';
1515
import { produceArtifact } from '@/restful/sync';
1616
import PROXY_PREPROCESSORS from '@/core/proxy-utils/preprocessors';
17+
import { ProxyUtils } from '@/core/proxy-utils';
18+
1719
const clashPreprocessor = PROXY_PREPROCESSORS.find(
1820
(processor) => processor.name === 'Clash Pre-processor',
1921
);
@@ -261,10 +263,34 @@ export default async function download(
261263
if (shouldCache) {
262264
resourceCache.set(id, body);
263265
if (customCacheKey) {
264-
$.info(
265-
`URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`,
266-
);
267-
$.write(body, customCacheKey);
266+
let shouldWriteCustomCacheKey = true;
267+
if (preprocess) {
268+
try {
269+
const proxies = ProxyUtils.parse(body);
270+
if (
271+
!Array.isArray(proxies) ||
272+
proxies.length === 0
273+
) {
274+
$.error(
275+
`URL ${url} 不包含有效节点\n不写入自定义缓存 ${$arguments?.cacheKey}`,
276+
);
277+
shouldWriteCustomCacheKey = false;
278+
}
279+
} catch (e) {
280+
$.error(
281+
`URL ${url} 尝试解析节点失败 ${
282+
e.message ?? e
283+
}\n不写入自定义缓存 ${$arguments?.cacheKey}`,
284+
);
285+
shouldWriteCustomCacheKey = false;
286+
}
287+
}
288+
if (shouldWriteCustomCacheKey) {
289+
$.info(
290+
`URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`,
291+
);
292+
$.write(body, customCacheKey);
293+
}
268294
}
269295
}
270296

backend/src/utils/flow.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,22 @@ export function normalizeFlowHeader(flowHeaders) {
334334
if (!kvMap.has(key)) {
335335
try {
336336
// 解码 URI 组件并保留原始值作为 fallback
337-
const decodedValue = decodeURIComponent(encodedValue);
337+
let decodedValue = decodeURIComponent(encodedValue);
338+
if (
339+
['upload', 'download', 'total', 'expire'].includes(
340+
key,
341+
)
342+
) {
343+
try {
344+
decodedValue = Number(decodedValue).toFixed(0);
345+
} catch (e) {
346+
$.error(
347+
`Failed to convert value for key "${key}=${encodedValue}": ${
348+
e.message ?? e
349+
}`,
350+
);
351+
}
352+
}
338353
kvMap.set(key, decodedValue);
339354
} catch (e) {
340355
kvMap.set(key, encodedValue);

0 commit comments

Comments
 (0)