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

This commit is contained in:
Peng-YM 2021-01-04 00:03:43 +08:00
parent b092d3fd6a
commit 6c552500c6
5 changed files with 106 additions and 54 deletions

View File

@ -139,6 +139,7 @@ function service() {
async function downloadSubscription(req, res) { async function downloadSubscription(req, res) {
const {name} = req.params; const {name} = req.params;
const {cache} = req.query; const {cache} = req.query;
const {raw} = req.query || "false";
const platform = req.query.target || getPlatformFromHeaders(req.headers) || "JSON"; const platform = req.query.target || getPlatformFromHeaders(req.headers) || "JSON";
const useCache = typeof cache === 'undefined' ? (platform === 'JSON' || platform === 'URI') : cache; const useCache = typeof cache === 'undefined' ? (platform === 'JSON' || platform === 'URI') : cache;
@ -148,7 +149,13 @@ function service() {
const sub = allSubs[name]; const sub = allSubs[name];
if (sub) { if (sub) {
try { 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') { if (platform === 'JSON') {
res.set("Content-Type", "application/json;charset=utf-8").send(output); res.set("Content-Type", "application/json;charset=utf-8").send(output);
} else { } else {
@ -289,6 +296,7 @@ function service() {
async function downloadCollection(req, res) { async function downloadCollection(req, res) {
const {name} = req.params; const {name} = req.params;
const {cache} = req.query || "false"; const {cache} = req.query || "false";
const {raw} = req.query || "false";
const platform = req.query.target || getPlatformFromHeaders(req.headers) || "JSON"; const platform = req.query.target || getPlatformFromHeaders(req.headers) || "JSON";
const useCache = typeof cache === 'undefined' ? (platform === 'JSON' || platform === 'URI') : cache; const useCache = typeof cache === 'undefined' ? (platform === 'JSON' || platform === 'URI') : cache;
@ -299,7 +307,13 @@ function service() {
if (collection) { if (collection) {
try { 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') { if (platform === 'JSON') {
res.set("Content-Type", "application/json;charset=utf-8").send(output); res.set("Content-Type", "application/json;charset=utf-8").send(output);
} else { } else {
@ -445,15 +459,19 @@ function service() {
function createRule(req, res) { function createRule(req, res) {
} }
function deleteRule(req, res) { function deleteRule(req, res) {
} }
function updateRule(req, res) { function updateRule(req, res) {
} }
function getAllRules(req, res) { function getAllRules(req, res) {
} }
function getRule(req, res) { function getRule(req, res) {
} }
@ -790,14 +808,20 @@ function service() {
return body; 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') { if (type === 'subscription') {
const sub = item; const sub = item;
const raw = await getResource(sub.url, useCache); const raw = await getResource(sub.url, useCache);
// parse proxies // parse proxies
let proxies = ProxyUtils.parse(raw); let proxies = ProxyUtils.parse(raw);
if (!noProcessor) {
// apply processors // apply processors
proxies = await ProxyUtils.process(proxies, sub.process || []); proxies = await ProxyUtils.process(proxies, sub.process || []);
}
// produce // produce
return ProxyUtils.produce(proxies, platform); return ProxyUtils.produce(proxies, platform);
} else if (type === 'collection') { } else if (type === 'collection') {
@ -812,16 +836,20 @@ function service() {
const raw = await getResource(sub.url, useCache); const raw = await getResource(sub.url, useCache);
// parse proxies // parse proxies
let currentProxies = ProxyUtils.parse(raw) let currentProxies = ProxyUtils.parse(raw)
if (!noProcessor) {
// apply processors // apply processors
currentProxies = await ProxyUtils.process(currentProxies, sub.process || []); currentProxies = await ProxyUtils.process(currentProxies, sub.process || []);
}
// merge // merge
proxies = proxies.concat(currentProxies); proxies = proxies.concat(currentProxies);
} catch (err) { } catch (err) {
$.error(`处理组合订阅中的子订阅: ${sub.name}时出现错误:${err}! 该订阅已被跳过。`); $.error(`处理组合订阅中的子订阅: ${sub.name}时出现错误:${err}! 该订阅已被跳过。`);
} }
} }
if (!noProcessor) {
// apply own processors // apply own processors
proxies = await ProxyUtils.process(proxies, collection.process || []); proxies = await ProxyUtils.process(proxies, collection.process || []);
}
if (proxies.length === 0) { if (proxies.length === 0) {
throw new Error(`组合订阅中不含有效节点!`); throw new Error(`组合订阅中不含有效节点!`);
} }

File diff suppressed because one or more lines are too long

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 { .v-expansion-panel {
&:before { &:before {
-webkit-box-shadow: none; -webkit-box-shadow: none;
@ -1504,3 +1488,9 @@ html, body {
contain: none; contain: none;
} }
} }
.v-dialog > .v-card > .v-toolbar {
position: sticky;
top: 0;
z-index: 999;
}

View File

@ -89,7 +89,7 @@ const flags = new Map([["AC", "🇦🇨"], ["AF", "🇦🇫"], ["AI", "🇦🇮"
export default { export default {
name: "ProxyList", name: "ProxyList",
props: ['url', 'sub'], props: ['url', 'sub', 'raw'],
components: {VueQRCodeComponent}, components: {VueQRCodeComponent},
data: function () { data: function () {
return { return {
@ -114,7 +114,7 @@ export default {
}, },
async fetch() { 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; let {data} = resp;
// eslint-disable-next-line no-debugger // eslint-disable-next-line no-debugger
this.proxies = data; this.proxies = data;
@ -122,7 +122,7 @@ export default {
this.$store.commit("SET_ERROR_MESSAGE", err); 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; const {data} = resp;
this.uris = data.split("\n"); this.uris = data.split("\n");
}); });

View File

@ -118,28 +118,55 @@
</v-card-text> </v-card-text>
</v-card> </v-card>
<v-dialog fullscreen hide-overlay transition="dialog-bottom-transition" v-model="showProxyList" scrollable> <v-dialog fullscreen hide-overlay transition="dialog-bottom-transition" v-model="showProxyList" scrollable>
<v-card> <v-card fluid>
<v-card-title class="pa-0">
<v-toolbar> <v-toolbar>
<v-icon>mdi-cloud</v-icon> <v-icon>mdi-cloud</v-icon>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-toolbar-title class="flex text-xs-center"> <v-toolbar-title>
<h4>节点列表</h4> <h4>节点列表</h4>
</v-toolbar-title> </v-toolbar-title>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-toolbar-items> <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-btn icon @click="showProxyList = false">
<v-icon>mdi-close</v-icon> <v-icon>mdi-close</v-icon>
</v-btn> </v-btn>
</v-toolbar-items> </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-toolbar>
</v-card-title> <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"> <v-card-text class="pl-0 pr-0">
<proxy-list :url="url" :sub="sub" ref="proxyList" :key="url"></proxy-list> <proxy-list :url="url" :sub="sub" ref="proxyList" :key="url"></proxy-list>
</v-card-text> </v-card-text>
</v-tab-item>
</v-tabs-items>
</v-card-text>
</v-card> </v-card>
</v-dialog> </v-dialog>
</v-container> </v-container>
@ -157,6 +184,7 @@ export default {
showProxyList: false, showProxyList: false,
url: "", url: "",
sub: [], sub: [],
tab: 1,
editMenu: [ editMenu: [
{ {
title: "复制", title: "复制",
@ -272,4 +300,10 @@ export default {
.invert { .invert {
filter: invert(100%); filter: invert(100%);
} }
.v-dialog > .v-card > .v-toolbar {
position: sticky;
top: 0;
z-index: 999;
}
</style> </style>