Skip to content

Commit

Permalink
feat: 订阅支持开关 passThroughUA 透传请求的 User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Dec 29, 2024
1 parent 7e2109d commit ff4be7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 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.15.8",
"version": "2.15.9",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
21 changes: 16 additions & 5 deletions backend/src/restful/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ export default function register($app) {
$app.get('/share/col/:name', downloadCollection);
$app.get('/share/sub/:name', downloadSubscription);

$app.get('/download/collection/:name/:target', async (req, res) => {
req.query.target = req.params.target;
$.info(`使用路由指定目标: ${req.params.target}`);
await downloadCollection(req, res);
});
$app.get('/download/collection/:name', downloadCollection);
$app.get('/download/:name', downloadSubscription);
$app.get('/download/:name/:target', async (req, res) => {
req.query.target = req.params.target;
$.info(`使用路由指定目标: ${req.params.target}`);
await downloadSubscription(req, res);
});
$app.get('/download/:name', downloadSubscription);

$app.get(
'/download/collection/:name/api/v1/server/details',
async (req, res) => {
Expand Down Expand Up @@ -64,11 +70,9 @@ async function downloadSubscription(req, res) {

const platform =
req.query.target || getPlatformFromHeaders(req.headers) || 'JSON';

const reqUA = req.headers['user-agent'] || req.headers['User-Agent'];
$.info(
`正在下载订阅:${name}\n请求 User-Agent: ${
req.headers['user-agent'] || req.headers['User-Agent']
}\n请求 target: ${req.query.target}\n实际输出: ${platform}`,
`正在下载订阅:${name}\n请求 User-Agent: ${reqUA}\n请求 target: ${req.query.target}\n实际输出: ${platform}`,
);
let {
url,
Expand Down Expand Up @@ -150,6 +154,13 @@ async function downloadSubscription(req, res) {
const sub = findByName(allSubs, name);
if (sub) {
try {
const passThroughUA = sub.passThroughUA;
if (passThroughUA) {
$.info(
`订阅开启了透传 User-Agent, 使用请求的 User-Agent: ${reqUA}`,
);
ua = reqUA;
}
let output = await produceArtifact({
type: 'subscription',
name,
Expand Down

0 comments on commit ff4be7a

Please sign in to comment.