feat: /api/sub/flow/:name 接口支持指定远程订阅 url(可携带订阅 url 支持的参数, 例如 flowUserAgent)

This commit is contained in:
xream
2024-06-10 13:24:06 +08:00
parent d7f7069ee0
commit 76da8d1c5c
2 changed files with 8 additions and 3 deletions

View File

@@ -34,6 +34,11 @@ export default function register($app) {
async function getFlowInfo(req, res) {
let { name } = req.params;
name = decodeURIComponent(name);
let { url } = req.query;
if (url) {
url = decodeURIComponent(url);
$.info(`指定远程订阅 URL: ${url}`);
}
const allSubs = $.read(SUBS_KEY);
const sub = findByName(allSubs, name);
if (!sub) {
@@ -68,8 +73,8 @@ async function getFlowInfo(req, res) {
return;
}
try {
let url =
`${sub.url}`
url =
`${url || sub.url}`
.split(/[\r\n]+/)
.map((i) => i.trim())
.filter((i) => i.length)?.[0] || '';