Skip to content

Commit

Permalink
feat: 远程订阅支持换行符连接的多个订阅链接(前端版本 > 2.14.13 可输入)
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Nov 28, 2023
1 parent 5a64508 commit 3054d5c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 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.103",
"version": "2.14.104",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
24 changes: 20 additions & 4 deletions backend/src/restful/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ async function compareSub(req, res) {
content = sub.content;
} else {
try {
content = await download(sub.url, sub.ua);
content = await Promise.all(
sub.url
.split(/[\r\n]+/)
.map((i) => i.trim())
.filter((i) => i.length)
.map((url) => download(url, sub.ua)),
);
} catch (err) {
failed(
res,
Expand All @@ -34,7 +40,9 @@ async function compareSub(req, res) {
}
}
// parse proxies
const original = ProxyUtils.parse(content);
const original = (Array.isArray(content) ? content : [content])
.map((i) => ProxyUtils.parse(i))
.flat();

// add id
original.forEach((proxy, i) => {
Expand Down Expand Up @@ -80,10 +88,18 @@ async function compareCollection(req, res) {
if (sub.source === 'local') {
raw = sub.content;
} else {
raw = await download(sub.url, sub.ua);
raw = await Promise.all(
sub.url
.split(/[\r\n]+/)
.map((i) => i.trim())
.filter((i) => i.length)
.map((url) => download(url, sub.ua)),
);
}
// parse proxies
let currentProxies = ProxyUtils.parse(raw);
let currentProxies = (Array.isArray(raw) ? raw : [raw])
.map((i) => ProxyUtils.parse(i))
.flat();

currentProxies.forEach((proxy) => {
proxy.subName = sub.name;
Expand Down
33 changes: 28 additions & 5 deletions backend/src/restful/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,31 @@ async function produceArtifact({ type, name, platform, url, ua, content }) {
const sub = findByName(allSubs, name);
let raw;
if (url) {
raw = await download(url, ua);
raw = await Promise.all(
url
.split(/[\r\n]+/)
.map((i) => i.trim())
.filter((i) => i.length)
.map((url) => download(url, ua)),
);
} else if (content) {
raw = content;
} else if (sub.source === 'local') {
raw = sub.content;
} else {
raw = await download(sub.url, sub.ua);
raw = await Promise.all(
sub.url
.split(/[\r\n]+/)
.map((i) => i.trim())
.filter((i) => i.length)
.map((url) => download(url, sub.ua)),
);
}
// parse proxies
let proxies = ProxyUtils.parse(raw);
let proxies = (Array.isArray(raw) ? raw : [raw])
.map((i) => ProxyUtils.parse(i))
.flat();

proxies.forEach((proxy) => {
proxy.subName = sub.name;
});
Expand Down Expand Up @@ -90,10 +105,18 @@ async function produceArtifact({ type, name, platform, url, ua, content }) {
if (sub.source === 'local') {
raw = sub.content;
} else {
raw = await download(sub.url, sub.ua);
raw = await await Promise.all(
sub.url
.split(/[\r\n]+/)
.map((i) => i.trim())
.filter((i) => i.length)
.map((url) => download(url, sub.ua)),
);
}
// parse proxies
let currentProxies = ProxyUtils.parse(raw);
let currentProxies = (Array.isArray(raw) ? raw : [raw])
.map((i) => ProxyUtils.parse(i))
.flat();

currentProxies.forEach((proxy) => {
proxy.subName = sub.name;
Expand Down

0 comments on commit 3054d5c

Please sign in to comment.