Forward subscription-userinfo from the first subscription in a collection

This commit is contained in:
Peng-YM 2022-04-28 17:03:01 +08:00
parent 8b1928e2da
commit 4dc40e92ae
2 changed files with 29 additions and 18 deletions

View File

@ -164,22 +164,9 @@ function service() {
});
// forward flow headers
if (
["QX", "Surge", "Loon", "Clash"].indexOf(
getPlatformFromHeaders(req.headers)
) !== -1
) {
const {headers} = await $.http.get({
url: sub.url,
headers: {
"User-Agent": "Quantumult/1.0.13 (iPhone10,3; iOS 14.0)",
},
});
const subkey = Object.keys(headers).filter((k) =>
/SUBSCRIPTION-USERINFO/i.test(k)
)[0];
const userinfo = headers[subkey];
res.set("subscription-userinfo", userinfo);
const flowInfo = await getFlowHeaders(sub.url);
if (flowInfo) {
res.set("subscription-userinfo", flowInfo);
}
if (platform === "JSON") {
@ -335,6 +322,17 @@ function service() {
$.info(`正在下载组合订阅:${name}`);
// forward flow header from the first subscription in this collection
const allSubs = $.read(SUBS_KEY);
const subs = collection["subscriptions"];
if (subs.length > 0) {
const sub = allSubs[subs[0]];
const flowInfo = await getFlowHeaders(sub.url);
if (flowInfo) {
res.set("subscription-userinfo", flowInfo);
}
}
if (collection) {
try {
const output = await produceArtifact({
@ -790,6 +788,19 @@ function service() {
}
}
async function getFlowHeaders(url) {
const {headers} = await $.http.get({
url,
headers: {
"User-Agent": "Quantumult/1.0.13 (iPhone10,3; iOS 14.0)",
},
});
const subkey = Object.keys(headers).filter((k) =>
/SUBSCRIPTION-USERINFO/i.test(k)
)[0];
return headers[subkey];
}
function getEnv(req, res) {
const {isNode, isQX, isLoon, isSurge} = ENV();
let backend = "Node";

File diff suppressed because one or more lines are too long