Skip to content

Commit dea937d

Browse files
committed
feat: 默认查询流量信息的 User-AgentQuantumult%20X/1.0.30 (iPhone14,2; iOS 15.6) 改为 clash; 流量信息缓存逻辑调整
1 parent cfb5a8e commit dea937d

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
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.14.419",
3+
"version": "2.14.420",
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default async function download(
151151
// try to find in app cache
152152
const cached = resourceCache.get(id);
153153
if (!noCache && !$arguments?.noCache && cached) {
154-
$.info(`使用缓存: ${url}`);
154+
$.info(`使用缓存: ${url}, ${userAgent}`);
155155
result = cached;
156156
if (customCacheKey) {
157157
$.info(`URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`);
@@ -179,7 +179,7 @@ export default async function download(
179179
if (headers) {
180180
const flowInfo = getFlowField(headers);
181181
if (flowInfo) {
182-
headersResourceCache.set(url, flowInfo);
182+
headersResourceCache.set(id, flowInfo);
183183
}
184184
}
185185
if (body.replace(/\s/g, '').length === 0)

backend/src/utils/flow.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SETTINGS_KEY } from '@/constants';
22
import { HTTP, ENV } from '@/vendor/open-api';
3+
import { hex_md5 } from '@/vendor/md5';
34
import { getPolicyDescriptor } from '@/utils';
45
import $ from '@/core/app';
56
import headersResourceCache from '@/utils/headers-resource-cache';
@@ -52,29 +53,26 @@ export async function getFlowHeaders(
5253
return;
5354
}
5455
const { isStash, isLoon, isShadowRocket, isQX } = ENV();
55-
const cached = headersResourceCache.get(url);
56+
const insecure = $arguments?.insecure
57+
? $.env.isNode
58+
? { strictSSL: false }
59+
: { insecure: true }
60+
: undefined;
61+
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
62+
$.read(SETTINGS_KEY);
63+
let proxy = customProxy || defaultProxy;
64+
if ($.env.isNode) {
65+
proxy = proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
66+
}
67+
const userAgent = ua || defaultFlowUserAgent || 'clash';
68+
const requestTimeout = timeout || defaultTimeout;
69+
const id = hex_md5(userAgent + url);
70+
const cached = headersResourceCache.get(id);
5671
let flowInfo;
5772
if (!$arguments?.noCache && cached) {
58-
// $.info(`使用缓存的流量信息: ${url}`);
73+
$.info(`使用缓存的流量信息: ${url}, ${userAgent}`);
5974
flowInfo = cached;
6075
} else {
61-
const insecure = $arguments?.insecure
62-
? $.env.isNode
63-
? { strictSSL: false }
64-
: { insecure: true }
65-
: undefined;
66-
const { defaultProxy, defaultFlowUserAgent, defaultTimeout } =
67-
$.read(SETTINGS_KEY);
68-
let proxy = customProxy || defaultProxy;
69-
if ($.env.isNode) {
70-
proxy =
71-
proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY');
72-
}
73-
const userAgent =
74-
ua ||
75-
defaultFlowUserAgent ||
76-
'Quantumult%20X/1.0.30 (iPhone14,2; iOS 15.6)';
77-
const requestTimeout = timeout || defaultTimeout;
7876
const http = HTTP();
7977
if (flowUrl) {
8078
$.info(
@@ -170,7 +168,7 @@ export async function getFlowHeaders(
170168
}
171169
}
172170
if (flowInfo) {
173-
headersResourceCache.set(url, flowInfo);
171+
headersResourceCache.set(id, flowInfo);
174172
}
175173
}
176174

0 commit comments

Comments
 (0)