节点预览可以预览原始订阅的节点了

This commit is contained in:
Peng-YM committed 2021-01-04 00:03:43 +08:00
1 parent 37370cccda
commit 8da264608a
5 files changed
+106 -54

No files matched your search

+38 -10
View File
@@ -139,6 +139,7 @@ function service() {
async function downloadSubscription(req, res) {
const {name} = req.params;
const {cache} = req.query;
const {raw} = req.query || "false";
const platform = req.query.target || getPlatformFromHeaders(req.headers) || "JSON";
const useCache = typeof cache === 'undefined' ? (platform === 'JSON' || platform === 'URI') : cache;
@@ -148,7 +149,13 @@ function service() {
const sub = allSubs[name];
if (sub) {
try {
const output = await produceArtifact({type: 'subscription', item: sub, platform, useCache});
const output = await produceArtifact({
type: 'subscription',
item: sub,
platform,
useCache,
noProcessor: raw
});
if (platform === 'JSON') {
res.set("Content-Type", "application/json;charset=utf-8").send(output);
} else {
@@ -289,6 +296,7 @@ function service() {
async function downloadCollection(req, res) {
const {name} = req.params;
const {cache} = req.query || "false";
const {raw} = req.query || "false";
const platform = req.query.target || getPlatformFromHeaders(req.headers) || "JSON";
const useCache = typeof cache === 'undefined' ? (platform === 'JSON' || platform === 'URI') : cache;
@@ -299,7 +307,13 @@ function service() {
if (collection) {
try {
const output = await produceArtifact({type: "collection", item: collection, platform, useCache});
const output = await produceArtifact({
type: "collection",
item: collection,
platform,
useCache,
noProcessor: raw
});
if (platform === 'JSON') {
res.set("Content-Type", "application/json;charset=utf-8").send(output);
} else {
@@ -445,15 +459,19 @@ function service() {
function createRule(req, res) {
}
function deleteRule(req, res) {
}
function updateRule(req, res) {
}
function getAllRules(req, res) {
}
function getRule(req, res) {
}
@@ -790,14 +808,20 @@ function service() {
return body;
}
async function produceArtifact({type, item, platform, useCache} = {platform: "JSON", useCache: false}) {
async function produceArtifact({type, item, platform, useCache, noProcessor} = {
platform: "JSON",
useCache: false,
noProcessor: false
}) {
if (type === 'subscription') {
const sub = item;
const raw = await getResource(sub.url, useCache);
// parse proxies
let proxies = ProxyUtils.parse(raw);
// apply processors
proxies = await ProxyUtils.process(proxies, sub.process || []);
if (!noProcessor) {
// apply processors
proxies = await ProxyUtils.process(proxies, sub.process || []);
}
// produce
return ProxyUtils.produce(proxies, platform);
} else if (type === 'collection') {
@@ -812,16 +836,20 @@ function service() {
const raw = await getResource(sub.url, useCache);
// parse proxies
let currentProxies = ProxyUtils.parse(raw)
// apply processors
currentProxies = await ProxyUtils.process(currentProxies, sub.process || []);
if (!noProcessor) {
// apply processors
currentProxies = await ProxyUtils.process(currentProxies, sub.process || []);
}
// merge
proxies = proxies.concat(currentProxies);
} catch (err) {
$.error(`处理组合订阅中的子订阅: ${sub.name}时出现错误:${err}! 该订阅已被跳过。`);
}
}
// apply own processors
proxies = await ProxyUtils.process(proxies, collection.process || []);
if (!noProcessor) {
// apply own processors
proxies = await ProxyUtils.process(proxies, collection.process || []);
}
if (proxies.length === 0) {
throw new Error(`组合订阅中不含有效节点!`);
}
@@ -2966,7 +2994,7 @@ var RuleUtils = (function () {
let matched;
try {
matched = parser.test(raw);
} catch(err) {
} catch (err) {
matched = false;
}
if (matched) {
+2 -2
View File
@@ -1,2 +1,2 @@
// UPDATED AT: 2020年12月31日 星期四 14时29分41秒 CST
const $=API("sub-store"),Base64=new Base64Code;function service(){console.log("\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 © 𝑷𝒆𝒏𝒈-𝒀𝑴\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n");const e=express(),t="settings",s="subs",r="collections",n="rules",o="builtin",a="artifacts",i="Auto Generated Sub-Store Backup",p="Sub-Store",c="Sub-Store Artifacts Repository";async function u({filename:e,content:s}){const{gistToken:r}=$.read(t);return r?new Gist({token:r,key:c}).upload({filename:e,content:s}):Promise.reject("未设置Gist Token!")}function l(e){const t=Object.keys(e);let s="";for(let r of t)if(/USER-AGENT/i.test(r)){s=e[r];break}return-1!==s.indexOf("Quantumult%20X")?"QX":-1!==s.indexOf("Surge")?"Surge":-1!==s.indexOf("Decar")||-1!==s.indexOf("Loon")?"Loon":null}async function f(e,t=!0){const s=HTTP({headers:{"User-Agent":"Quantumult%20X"}}),r="#"+Base64.safeEncode(e),n=$.read(r),o=`#TIME-${Base64.safeEncode(e)}`,a=(new Date).getTime()-$.read(o)>36e5;if(t&&n&&!a)return $.log(`Use cached for resource: ${e}`),n;let i="";try{i=(await s.get(e)).body}catch(e){throw new Error(e)}finally{$.write(i,r),$.write((new Date).getTime(),o)}if(0===i.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return i}async function d({type:e,item:t,platform:r,useCache:n}={platform:"JSON",useCache:!1}){if("subscription"===e){const e=t,s=await f(e.url,n);let o=ProxyUtils.parse(s);return o=await ProxyUtils.process(o,e.process||[]),ProxyUtils.produce(o,r)}if("collection"===e){const e=$.read(s),o=t,a=o.subscriptions;let i=[];for(let t=0;t<a.length;t++){const s=e[a[t]];$.info(`正在处理子订阅:${s.name},进度--${100*((t+1)/a.length).toFixed(1)}% `);try{const e=await f(s.url,n);let t=ProxyUtils.parse(e);t=await ProxyUtils.process(t,s.process||[]),i=i.concat(t)}catch(e){$.error(`处理组合订阅中的子订阅: ${s.name}时出现错误:${e}! 该订阅已被跳过。`)}}if(0===(i=await ProxyUtils.process(i,o.process||[])).length)throw new Error("组合订阅中不含有效节点!");return ProxyUtils.produce(i,r)}if("rule"===e){const e=t;let s=[];for(let t=0;t<e.urls.length;t++){const r=e.urls[t];$.info(`正在处理URL:${r},进度--${100*((t+1)/e.urls.length).toFixed(1)}% `);try{const{body:e}=await $.http.get(r),t=RuleUtils.parse(e);s=s.concat(t)}catch(e){$.error(`处理分流订阅中的URL: ${r}时出现错误:${e}! 该订阅已被跳过。`)}}return s=await RuleUtils.process(s,[{type:"Remove Duplicate Filter"}]),RuleUtils.produce(s,r)}}$.read(s)||$.write({},s),$.read(r)||$.write({},r),$.read(t)||$.write({},t),$.read(n)||$.write({},n),$.read(a)||$.write({},a),$.write({rules:getBuiltInRules()},o),e.get("/download/collection/:name",async function(e,t){const{name:s}=e.params,{cache:n}=e.query||"false",o=e.query.target||l(e.headers)||"JSON",a=void 0===n?"JSON"===o||"URI"===o:n,i=$.read(r)[s];if($.info(`正在下载组合订阅:${s}`),i)try{const e=await d({type:"collection",item:i,platform:o,useCache:a});"JSON"===o?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 下载组合订阅错误:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(404).json({status:"failed"})}),e.get("/download/:name",async function(e,t){const{name:r}=e.params,{cache:n}=e.query,o=e.query.target||l(e.headers)||"JSON",a=void 0===n?"JSON"===o||"URI"===o:n;$.info(`正在下载订阅:${r}`);const i=$.read(s)[r];if(i)try{const e=await d({type:"subscription",item:i,platform:o,useCache:a});"JSON"===o?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 未找到订阅:${r}!`),t.status(404).json({status:"failed"})}),e.route("/api/sub/:name").get(function(e,t){const{name:r}=e.params,n=$.read(s)[r];n?t.json({status:"success",data:n}):t.status(404).json({status:"failed",message:`未找到订阅:${r}!`})}).patch(function(e,t){const{name:n}=e.params;let o=e.body;const a=$.read(s);if(a[n]){const e={...a[n],...o};if($.info(`正在更新订阅: ${n}`),n!==o.name){const t=$.read(r);for(const e of Object.keys(t)){const s=t[e].subscriptions.indexOf(n);-1!==s&&(t[e].subscriptions[s]=o.name)}delete a[n],a[o.name]=e}else a[n]=e;$.write(a,s),t.json({status:"success",data:e})}else t.status(500).json({status:"failed",message:`订 Line truncated
// UPDATED AT: 2021年 1月 4日 星期一 00时03分16秒 CST
const $=API("sub-store"),Base64=new Base64Code;function service(){console.log("\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 © 𝑷𝒆𝒏𝒈-𝒀𝑴\n┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅\n");const e=express(),t="settings",s="subs",r="collections",n="rules",o="builtin",a="artifacts",i="Auto Generated Sub-Store Backup",p="Sub-Store",c="Sub-Store Artifacts Repository";async function u({filename:e,content:s}){const{gistToken:r}=$.read(t);return r?new Gist({token:r,key:c}).upload({filename:e,content:s}):Promise.reject("未设置Gist Token!")}function l(e){const t=Object.keys(e);let s="";for(let r of t)if(/USER-AGENT/i.test(r)){s=e[r];break}return-1!==s.indexOf("Quantumult%20X")?"QX":-1!==s.indexOf("Surge")?"Surge":-1!==s.indexOf("Decar")||-1!==s.indexOf("Loon")?"Loon":null}async function f(e,t=!0){const s=HTTP({headers:{"User-Agent":"Quantumult%20X"}}),r="#"+Base64.safeEncode(e),n=$.read(r),o=`#TIME-${Base64.safeEncode(e)}`,a=(new Date).getTime()-$.read(o)>36e5;if(t&&n&&!a)return $.log(`Use cached for resource: ${e}`),n;let i="";try{i=(await s.get(e)).body}catch(e){throw new Error(e)}finally{$.write(i,r),$.write((new Date).getTime(),o)}if(0===i.replace(/\s/g,"").length)throw new Error("订阅内容为空!");return i}async function d({type:e,item:t,platform:r,useCache:n,noProcessor:o}={platform:"JSON",useCache:!1,noProcessor:!1}){if("subscription"===e){const e=t,s=await f(e.url,n);let a=ProxyUtils.parse(s);return o||(a=await ProxyUtils.process(a,e.process||[])),ProxyUtils.produce(a,r)}if("collection"===e){const e=$.read(s),a=t,i=a.subscriptions;let p=[];for(let t=0;t<i.length;t++){const s=e[i[t]];$.info(`正在处理子订阅:${s.name},进度--${100*((t+1)/i.length).toFixed(1)}% `);try{const e=await f(s.url,n);let t=ProxyUtils.parse(e);o||(t=await ProxyUtils.process(t,s.process||[])),p=p.concat(t)}catch(e){$.error(`处理组合订阅中的子订阅: ${s.name}时出现错误:${e}! 该订阅已被跳过。`)}}if(o||(p=await ProxyUtils.process(p,a.process||[])),0===p.length)throw new Error("组合订阅中不含有效节点!");return ProxyUtils.produce(p,r)}if("rule"===e){const e=t;let s=[];for(let t=0;t<e.urls.length;t++){const r=e.urls[t];$.info(`正在处理URL:${r},进度--${100*((t+1)/e.urls.length).toFixed(1)}% `);try{const{body:e}=await $.http.get(r),t=RuleUtils.parse(e);s=s.concat(t)}catch(e){$.error(`处理分流订阅中的URL: ${r}时出现错误:${e}! 该订阅已被跳过。`)}}return s=await RuleUtils.process(s,[{type:"Remove Duplicate Filter"}]),RuleUtils.produce(s,r)}}$.read(s)||$.write({},s),$.read(r)||$.write({},r),$.read(t)||$.write({},t),$.read(n)||$.write({},n),$.read(a)||$.write({},a),$.write({rules:getBuiltInRules()},o),e.get("/download/collection/:name",async function(e,t){const{name:s}=e.params,{cache:n}=e.query||"false",{raw:o}=e.query||"false",a=e.query.target||l(e.headers)||"JSON",i=void 0===n?"JSON"===a||"URI"===a:n,p=$.read(r)[s];if($.info(`正在下载组合订阅:${s}`),p)try{const e=await d({type:"collection",item:p,platform:a,useCache:i,noProcessor:o});"JSON"===a?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 下载组合订阅错误:${s}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载组合订阅失败",`❌ 未找到组合订阅:${s}!`),t.status(404).json({status:"failed"})}),e.get("/download/:name",async function(e,t){const{name:r}=e.params,{cache:n}=e.query,{raw:o}=e.query||"false",a=e.query.target||l(e.headers)||"JSON",i=void 0===n?"JSON"===a||"URI"===a:n;$.info(`正在下载订阅:${r}`);const p=$.read(s)[r];if(p)try{const e=await d({type:"subscription",item:p,platform:a,useCache:i,noProcessor:o});"JSON"===a?t.set("Content-Type","application/json;charset=utf-8").send(e):t.send(e)}catch(e){$.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 无法下载订阅:${r}!`,`🤔 原因:${e}`),t.status(500).json({status:"failed",message:e})}else $.notify("🌍 『 𝑺𝒖𝒃-𝑺𝒕𝒐𝒓𝒆 』 下载订阅失败",`❌ 未找到订阅:${r}!`),t.status(404).json({status:"failed"})}),e.route("/api/sub/:name").get(function(e,t){const{name:r}=e.params,n=$.read(s)[r];n?t.json({status:"success",data:n}):t.status(404).json({status:"failed",message:`未找到订阅:${r}!`})}).patch(function(e,t){const{name:n}=e.params;let o=e.body;const a=$.read(s);if(a[n]){const e={...a[n],...o};if($.info(`正在更新订阅: ${n}`),n!==o.name){const t=$.read(r);for(const e of Object.keys(t)){const s=t[e].subscriptions.indexOf(n);-1!==s&&(t[e].subscriptions[s]=o.name)}delete a[n],a[o.Line truncated
+6 -16
View File
@@ -1024,22 +1024,6 @@ html, body {
}
}
.v-tabs-bar {
.v-slide-group__wrapper {
overflow: visible;
display: -webkit-inline-box;
contain: inherit;
.v-slide-group__content {
z-index: 2;
}
}
.v-tab:not(:first-child) {
margin-left: 5px;
}
}
.v-expansion-panel {
&:before {
-webkit-box-shadow: none;
@@ -1503,4 +1487,10 @@ html, body {
.v-slide-group__wrapper {
contain: none;
}
}
.v-dialog > .v-card > .v-toolbar {
position: sticky;
top: 0;
z-index: 999;
}
+3 -3
View File
@@ -89,7 +89,7 @@ const flags = new Map([["AC", "🇦🇨"], ["AF", "🇦🇫"], ["AI", "🇦🇮"
export default {
name: "ProxyList",
props: ['url', 'sub'],
props: ['url', 'sub', 'raw'],
components: {VueQRCodeComponent},
data: function () {
return {
@@ -114,7 +114,7 @@ export default {
},
async fetch() {
await axios.get(this.url).then(resp => {
await axios.get(this.raw ? `${this.url}?raw=true` : this.url).then(resp => {
let {data} = resp;
// eslint-disable-next-line no-debugger
this.proxies = data;
@@ -122,7 +122,7 @@ export default {
this.$store.commit("SET_ERROR_MESSAGE", err);
});
await axios.get(`${this.url}?target=URI`).then(resp => {
await axios.get(this.raw ? `${this.url}?target=URI&raw=true` : `${this.url}?target=URI`).then(resp => {
const {data} = resp;
this.uris = data.split("\n");
});
+57 -23
View File
@@ -118,27 +118,54 @@
</v-card-text>
</v-card>
<v-dialog fullscreen hide-overlay transition="dialog-bottom-transition" v-model="showProxyList" scrollable>
<v-card>
<v-card-title class="pa-0">
<v-toolbar>
<v-icon>mdi-cloud</v-icon>
<v-spacer></v-spacer>
<v-toolbar-title class="flex text-xs-center">
<h4>节点列表</h4>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-toolbar-items>
<v-btn icon @click="refreshProxyList" v-if="sub">
<v-icon>refresh</v-icon>
</v-btn>
<v-btn icon @click="showProxyList = false">
<v-icon>mdi-close</v-icon>
</v-btn>
</v-toolbar-items>
</v-toolbar>
</v-card-title>
<v-card-text class="pl-0 pr-0">
<proxy-list :url="url" :sub="sub" ref="proxyList" :key="url"></proxy-list>
<v-card fluid>
<v-toolbar>
<v-icon>mdi-cloud</v-icon>
<v-spacer></v-spacer>
<v-toolbar-title>
<h4>节点列表</h4>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-toolbar-items>
<v-btn icon @click="showProxyList = false">
<v-icon>mdi-close</v-icon>
</v-btn>
</v-toolbar-items>
<template v-slot:extension>
<v-tabs
grow
centered
v-model="tab"
>
<v-tabs-slider color="primary"/>
<v-tab
key="raw"
>
原始节点
</v-tab>
<v-tab
key="processed"
>
生成节点
</v-tab>
</v-tabs>
</template>
</v-toolbar>
<v-card-text>
<v-tabs-items
v-model="tab"
>
<v-tab-item key="raw">
<v-card-text class="pl-0 pr-0">
<proxy-list :url="url" :sub="sub" :raw="true" ref="proxyList" :key="url + 'raw'"></proxy-list>
</v-card-text>
</v-tab-item>
<v-tab-item key="processed">
<v-card-text class="pl-0 pr-0">
<proxy-list :url="url" :sub="sub" ref="proxyList" :key="url"></proxy-list>
</v-card-text>
</v-tab-item>
</v-tabs-items>
</v-card-text>
</v-card>
</v-dialog>
@@ -157,6 +184,7 @@ export default {
showProxyList: false,
url: "",
sub: [],
tab: 1,
editMenu: [
{
title: "复制",
@@ -187,11 +215,11 @@ export default {
return BACKEND_BASE;
},
subscriptions: {
get(){
get() {
const subs = this.$store.state.subscriptions;
return Object.keys(subs).map(k => subs[k]);
},
set(){
set() {
}
},
@@ -272,4 +300,10 @@ export default {
.invert {
filter: invert(100%);
}
.v-dialog > .v-card > .v-toolbar {
position: sticky;
top: 0;
z-index: 999;
}
</style>