feat: 订阅链接支持参数(例: https://foo.com#noCache 关闭缓存)

This commit is contained in:
xream 2023-10-26 11:26:31 +08:00
parent 6a66475154
commit 14648d6401
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 21 additions and 2 deletions

View File

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

View File

@ -8,6 +8,25 @@ import $ from '@/core/app';
const tasks = new Map();
export default async function download(url, ua) {
let $arguments = {};
const rawArgs = url.split('#');
if (rawArgs.length > 1) {
try {
// 支持 `#${encodeURIComponent(JSON.stringify({arg1: "1"}))}`
$arguments = JSON.parse(decodeURIComponent(rawArgs[1]));
} catch (e) {
for (const pair of rawArgs[1].split('&')) {
const key = pair.split('=')[0];
const value = pair.split('=')[1];
// 部分兼容之前的逻辑 const value = pair.split('=')[1] || true;
$arguments[key] =
value == null || value === ''
? true
: decodeURIComponent(value);
}
}
}
const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/);
if (downloadUrlMatch) {
let type = downloadUrlMatch?.[1];
@ -41,7 +60,7 @@ export default async function download(url, ua) {
const result = new Promise((resolve, reject) => {
// try to find in app cache
const cached = resourceCache.get(id);
if (cached) {
if (!$arguments?.noCache && cached) {
resolve(cached);
} else {
http.get(url)