feat: 拉取文件时 日志输出 User-Agent; 脚本上下文参数 $options 中新增 _req 字段, 包含请求信息

This commit is contained in:
xream 2025-04-08 12:47:02 +08:00
parent e054b71a62
commit b074f42fdc
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
4 changed files with 46 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.19.17",
"version": "2.19.18",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {

View File

@ -111,7 +111,17 @@ async function downloadSubscription(req, res) {
proxy,
noCache,
} = req.query;
let $options = {};
let $options = {
_req: {
method: req.method,
url: req.url,
path: req.path,
query: req.query,
params: req.params,
headers: req.headers,
body: req.body,
},
};
if (req.query.$options) {
try {
// 支持 `#${encodeURIComponent(JSON.stringify({arg1: "1"}))}`
@ -376,7 +386,17 @@ async function downloadCollection(req, res) {
noCache,
} = req.query;
let $options = {};
let $options = {
_req: {
method: req.method,
url: req.url,
path: req.path,
query: req.query,
params: req.params,
headers: req.headers,
body: req.body,
},
};
if (req.query.$options) {
try {
// 支持 `#${encodeURIComponent(JSON.stringify({arg1: "1"}))}`

View File

@ -52,8 +52,8 @@ function createFile(req, res) {
async function getFile(req, res) {
let { name } = req.params;
name = decodeURIComponent(name);
$.info(`正在下载文件:${name}`);
const reqUA = req.headers['user-agent'] || req.headers['User-Agent'];
$.info(`正在下载文件:${name}\n请求 User-Agent: ${reqUA}`);
let {
url,
subInfoUrl,
@ -65,7 +65,17 @@ async function getFile(req, res) {
proxy,
noCache,
} = req.query;
let $options = {};
let $options = {
_req: {
method: req.method,
url: req.url,
path: req.path,
query: req.query,
params: req.params,
headers: req.headers,
body: req.body,
},
};
if (req.query.$options) {
try {
// 支持 `#${encodeURIComponent(JSON.stringify({arg1: "1"}))}`

View File

@ -40,6 +40,16 @@ function operator(proxies = [], targetPlatform, context) {
// 先这样处理 encodeURIComponent('arg1=a&arg2=b')
// /api/file/foo?$options=arg1%3Da%26arg2%3Db
// 默认会带上 _req 字段, 结构为
// {
// method,
// url,
// path,
// query,
// params,
// headers,
// body,
// }
// console.log($options)
// targetPlatform 为输出的目标平台