|
1 | 1 | import { SETTINGS_KEY } from '@/constants';
|
2 | 2 | import { HTTP, ENV } from '@/vendor/open-api';
|
| 3 | +import { hex_md5 } from '@/vendor/md5'; |
3 | 4 | import { getPolicyDescriptor } from '@/utils';
|
4 | 5 | import $ from '@/core/app';
|
5 | 6 | import headersResourceCache from '@/utils/headers-resource-cache';
|
@@ -52,29 +53,26 @@ export async function getFlowHeaders(
|
52 | 53 | return;
|
53 | 54 | }
|
54 | 55 | 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); |
56 | 71 | let flowInfo;
|
57 | 72 | if (!$arguments?.noCache && cached) {
|
58 |
| - // $.info(`使用缓存的流量信息: ${url}`); |
| 73 | + $.info(`使用缓存的流量信息: ${url}, ${userAgent}`); |
59 | 74 | flowInfo = cached;
|
60 | 75 | } 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; |
78 | 76 | const http = HTTP();
|
79 | 77 | if (flowUrl) {
|
80 | 78 | $.info(
|
@@ -170,7 +168,7 @@ export async function getFlowHeaders(
|
170 | 168 | }
|
171 | 169 | }
|
172 | 170 | if (flowInfo) {
|
173 |
| - headersResourceCache.set(url, flowInfo); |
| 171 | + headersResourceCache.set(id, flowInfo); |
174 | 172 | }
|
175 | 173 | }
|
176 | 174 |
|
|
0 commit comments