Skip to content

Commit

Permalink
feat: 文件支持设置代理/策略, 链接支持传入 proxy 参数指定代理/策略; 修复代理/策略优先级
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Oct 7, 2024
1 parent 8ffb060 commit ef85b6d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 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.390",
"version": "2.14.391",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/restful/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async function downloadSubscription(req, res) {
url,
$arguments.flowUserAgent,
undefined,
sub.proxy,
proxy || sub.proxy,
$arguments.flowUrl,
);
if (flowInfo) {
Expand Down Expand Up @@ -368,7 +368,7 @@ async function downloadCollection(req, res) {
url,
$arguments.flowUserAgent,
undefined,
sub.proxy || collection.proxy || proxy,
proxy || sub.proxy || collection.proxy,
$arguments.flowUrl,
);
if (flowInfo) {
Expand Down
8 changes: 8 additions & 0 deletions backend/src/restful/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async function getFile(req, res) {
content,
mergeSources,
ignoreFailedRemoteFile,
proxy,
} = req.query;
let $options = {};
if (req.query.$options) {
Expand All @@ -82,6 +83,10 @@ async function getFile(req, res) {
url = decodeURIComponent(url);
$.info(`指定远程文件 URL: ${url}`);
}
if (proxy) {
proxy = decodeURIComponent(proxy);
$.info(`指定远程订阅使用代理/策略 proxy: ${proxy}`);
}
if (ua) {
ua = decodeURIComponent(ua);
$.info(`指定远程文件 User-Agent: ${ua}`);
Expand Down Expand Up @@ -120,6 +125,7 @@ async function getFile(req, res) {
mergeSources,
ignoreFailedRemoteFile,
$options,
proxy,
});

try {
Expand All @@ -129,6 +135,8 @@ async function getFile(req, res) {
const flowInfo = await getFlowHeaders(
subInfoUrl,
subInfoUserAgent || file.subInfoUserAgent,
undefined,
proxy || file.proxy,
);
if (flowInfo) {
res.set('subscription-userinfo', flowInfo);
Expand Down
24 changes: 17 additions & 7 deletions backend/src/restful/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function produceArtifact({
url,
ua || sub.ua,
undefined,
sub.proxy || proxy,
proxy || sub.proxy,
undefined,
awaitCustomCache,
);
Expand Down Expand Up @@ -116,7 +116,7 @@ async function produceArtifact({
url,
ua || sub.ua,
undefined,
sub.proxy || proxy,
proxy || sub.proxy,
undefined,
awaitCustomCache,
);
Expand Down Expand Up @@ -221,9 +221,9 @@ async function produceArtifact({
url,
sub.ua,
undefined,
sub.proxy ||
collection.proxy ||
proxy,
proxy ||
sub.proxy ||
collection.proxy,
);
} catch (err) {
errors[url] = err;
Expand Down Expand Up @@ -392,7 +392,12 @@ async function produceArtifact({
.filter((i) => i.length)
.map(async (url) => {
try {
return await download(url, ua || file.ua);
return await download(
url,
ua || file.ua,
undefined,
file.proxy || proxy,
);
} catch (err) {
errors[url] = err;
$.error(
Expand Down Expand Up @@ -435,7 +440,12 @@ async function produceArtifact({
.filter((i) => i.length)
.map(async (url) => {
try {
return await download(url, ua || file.ua);
return await download(
url,
ua || file.ua,
undefined,
file.proxy || proxy,
);
} catch (err) {
errors[url] = err;
$.error(
Expand Down

0 comments on commit ef85b6d

Please sign in to comment.