Skip to content

Commit

Permalink
feat: 通过代理/节点/策略获取订阅 现已支持 Surge, Loon, Stash, Shadowrocket, QX, Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Mar 13, 2024
1 parent 3637c5e commit 59a9290
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.252",
"version": "2.14.253",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
14 changes: 9 additions & 5 deletions backend/src/utils/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default async function download(rawUrl, ua, timeout, proxy) {
// return item.content;
// }

const { isNode, isStash } = ENV();
const { isNode, isStash, isLoon, isShadowRocket, isQX } = ENV();
const { defaultUserAgent, defaultTimeout, cacheThreshold } =
$.read(SETTINGS_KEY);
const userAgent = ua || defaultUserAgent || 'clash.meta';
Expand All @@ -66,8 +66,10 @@ export default async function download(rawUrl, ua, timeout, proxy) {
const http = HTTP({
headers: {
'User-Agent': userAgent,
'X-Stash-Selected-Proxy':
isStash && proxy ? encodeURIComponent(proxy) : undefined,
...(isStash && proxy
? { 'X-Stash-Selected-Proxy': encodeURIComponent(proxy) }
: {}),
...(isShadowRocket && proxy ? { 'X-Surge-Policy': proxy } : {}),
},
timeout: requestTimeout,
});
Expand All @@ -86,8 +88,10 @@ export default async function download(rawUrl, ua, timeout, proxy) {
try {
const { body, headers } = await http.get({
url,
proxy,
...getPolicyDescriptor(proxy),
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
});

if (headers) {
Expand Down
21 changes: 14 additions & 7 deletions backend/src/utils/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy) {
if ($arguments?.noFlow) {
return;
}
const { isStash } = ENV();
const { isStash, isLoon, isShadowRocket, isQX } = ENV();
const cached = headersResourceCache.get(url);
let flowInfo;
if (!$arguments?.noCache && cached) {
Expand All @@ -57,14 +57,21 @@ export async function getFlowHeaders(rawUrl, ua, timeout, proxy) {
.filter((i) => i.length)[0],
headers: {
'User-Agent': userAgent,
'X-Stash-Selected-Proxy':
isStash && proxy
? encodeURIComponent(proxy)
: undefined,
...(isStash && proxy
? {
'X-Stash-Selected-Proxy':
encodeURIComponent(proxy),
}
: {}),
...(isShadowRocket && proxy
? { 'X-Surge-Policy': proxy }
: {}),
},
timeout: requestTimeout,
proxy,
...getPolicyDescriptor(proxy),
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
...(isQX && proxy ? { opts: { policy: proxy } } : {}),
...(proxy ? getPolicyDescriptor(proxy) : {}),
});
flowInfo = getFlowField(headers);
} catch (e) {
Expand Down

0 comments on commit 59a9290

Please sign in to comment.