Skip to content

Commit

Permalink
feat: Sub-Store 生成的订阅地址支持传入 订阅链接/User-Agent/节点内容 可以复用此订阅的其他设置
Browse files Browse the repository at this point in the history
例如: 建一个 name 为 sub 的订阅, 配置好节点操作

以后可以自由传入参数 无需在 Sub-Store 前端创建新的配置

`/download/sub?target=Surge&content=encodeURIComponent编码过的本地节点`

`/download/sub?target=Surge&url=encodeURIComponent编码过的订阅链接&ua=encodeURIComponent编码过的User-Agent`
  • Loading branch information
xream committed Nov 14, 2023
1 parent f3de132 commit 5392551
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 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.14.90",
"version": "2.14.91",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
17 changes: 15 additions & 2 deletions backend/src/restful/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ async function downloadSubscription(req, res) {
req.query.target || getPlatformFromHeaders(req.headers) || 'JSON';

$.info(`正在下载订阅:${name}`);
const { url, ua, content } = req.query;
if (url) {
$.info(`指定 url: ${url}`);
}
if (ua) {
$.info(`指定 ua: ${ua}`);
}
if (content) {
$.info(`指定 content: ${content}`);
}

const allSubs = $.read(SUBS_KEY);
const sub = findByName(allSubs, name);
Expand All @@ -29,12 +39,15 @@ async function downloadSubscription(req, res) {
type: 'subscription',
name,
platform,
url,
ua,
content,
});

if (sub.source !== 'local') {
if (sub.source !== 'local' || url) {
try {
// forward flow headers
const flowInfo = await getFlowHeaders(sub.url);
const flowInfo = await getFlowHeaders(url || sub.url);
if (flowInfo) {
res.set('subscription-userinfo', flowInfo);
}
Expand Down
8 changes: 6 additions & 2 deletions backend/src/restful/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ export default function register($app) {
$app.get('/api/sync/artifact/:name', syncArtifact);
}

async function produceArtifact({ type, name, platform }) {
async function produceArtifact({ type, name, platform, url, ua, content }) {
platform = platform || 'JSON';

if (type === 'subscription') {
const allSubs = $.read(SUBS_KEY);
const sub = findByName(allSubs, name);
let raw;
if (sub.source === 'local') {
if (url) {
raw = await download(url, ua);
} else if (content) {
raw = content;
} else if (sub.source === 'local') {
raw = sub.content;
} else {
raw = await download(sub.url, sub.ua);
Expand Down

0 comments on commit 5392551

Please sign in to comment.