支持Clash YAML输入

This commit is contained in:
Peng-YM 2020-08-25 11:18:35 +08:00
parent 8cec472812
commit 1b0f8f124e
9 changed files with 674 additions and 101 deletions

View File

@ -20,14 +20,14 @@
</component>
<component name="ChangeListManager">
<list default="true" id="8b97a098-48b2-4e64-a9ef-522fe2d30b52" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/../web/src/config.js" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../web/src/views/ProxyList.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/../web/package-lock.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/../web/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/App.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/App.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/components/BottomNav.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/components/BottomNav.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/main.js" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/main.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/router/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/router/index.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/sub-store.js" beforeDir="false" afterPath="$PROJECT_DIR$/sub-store.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/components/TopToolbar.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/components/TopToolbar.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/store/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/store/index.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/utils/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/utils/index.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/views/PopUpProxyList.vue" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/views/Subscription.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/views/Subscription.vue" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -80,7 +80,10 @@
<workItem from="1598004165212" duration="400000" />
<workItem from="1598099373952" duration="2155000" />
<workItem from="1598154135550" duration="297000" />
<workItem from="1598154453014" duration="923000" />
<workItem from="1598154453014" duration="3238000" />
<workItem from="1598235270977" duration="126000" />
<workItem from="1598235738199" duration="3192000" />
<workItem from="1598323737081" duration="1554000" />
</task>
<servers />
</component>
@ -100,85 +103,101 @@
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="WindowStateProjectService">
<state width="840" height="374" key="GridCell.Tab.0.bottom" timestamp="1598154511980">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.0.bottom" timestamp="1598325254472">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.0.bottom/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358068" />
<state width="840" height="374" key="GridCell.Tab.0.bottom/70.23.1722.1097@70.23.1722.1097" timestamp="1598154511980" />
<state width="840" height="374" key="GridCell.Tab.0.center" timestamp="1598154511979">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.0.bottom/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254472" />
<state width="840" height="374" key="GridCell.Tab.0.bottom/70.23.1722.1097@70.23.1722.1097" timestamp="1598324500703" />
<state width="842" height="374" key="GridCell.Tab.0.center" timestamp="1598325254471">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.0.center/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358067" />
<state width="840" height="374" key="GridCell.Tab.0.center/70.23.1722.1097@70.23.1722.1097" timestamp="1598154511979" />
<state width="840" height="374" key="GridCell.Tab.0.left" timestamp="1598154511979">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.0.center/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254471" />
<state width="840" height="374" key="GridCell.Tab.0.center/70.23.1722.1097@70.23.1722.1097" timestamp="1598324500702" />
<state width="842" height="374" key="GridCell.Tab.0.left" timestamp="1598325254470">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.0.left/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358067" />
<state width="840" height="374" key="GridCell.Tab.0.left/70.23.1722.1097@70.23.1722.1097" timestamp="1598154511979" />
<state width="840" height="374" key="GridCell.Tab.0.right" timestamp="1598154511980">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.0.left/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254470" />
<state width="840" height="374" key="GridCell.Tab.0.left/70.23.1722.1097@70.23.1722.1097" timestamp="1598324500701" />
<state width="842" height="374" key="GridCell.Tab.0.right" timestamp="1598325254472">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.0.right/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358068" />
<state width="840" height="374" key="GridCell.Tab.0.right/70.23.1722.1097@70.23.1722.1097" timestamp="1598154511980" />
<state width="840" height="374" key="GridCell.Tab.1.bottom" timestamp="1598154432354">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.0.right/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254472" />
<state width="840" height="374" key="GridCell.Tab.0.right/70.23.1722.1097@70.23.1722.1097" timestamp="1598324500702" />
<state width="842" height="374" key="GridCell.Tab.1.bottom" timestamp="1598325254381">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.1.bottom/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358069" />
<state width="840" height="374" key="GridCell.Tab.1.bottom/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432354" />
<state width="840" height="374" key="GridCell.Tab.1.center" timestamp="1598154432353">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.1.bottom/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254381" />
<state width="840" height="374" key="GridCell.Tab.1.bottom/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292666" />
<state width="842" height="374" key="GridCell.Tab.1.center" timestamp="1598325254380">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.1.center/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358069" />
<state width="840" height="374" key="GridCell.Tab.1.center/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432353" />
<state width="840" height="374" key="GridCell.Tab.1.left" timestamp="1598154432352">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.1.center/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254380" />
<state width="840" height="374" key="GridCell.Tab.1.center/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292666" />
<state width="842" height="374" key="GridCell.Tab.1.left" timestamp="1598325254380">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.1.left/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358069" />
<state width="840" height="374" key="GridCell.Tab.1.left/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432352" />
<state width="840" height="374" key="GridCell.Tab.1.right" timestamp="1598154432353">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.1.left/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254380" />
<state width="840" height="374" key="GridCell.Tab.1.left/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292665" />
<state width="842" height="374" key="GridCell.Tab.1.right" timestamp="1598325254380">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.1.right/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358069" />
<state width="840" height="374" key="GridCell.Tab.1.right/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432353" />
<state width="840" height="374" key="GridCell.Tab.2.bottom" timestamp="1598154432356">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.1.right/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254380" />
<state width="840" height="374" key="GridCell.Tab.1.right/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292666" />
<state width="842" height="374" key="GridCell.Tab.2.bottom" timestamp="1598325254381">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.2.bottom/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358071" />
<state width="840" height="374" key="GridCell.Tab.2.bottom/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432356" />
<state width="840" height="374" key="GridCell.Tab.2.center" timestamp="1598154432355">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.2.bottom/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254381" />
<state width="840" height="374" key="GridCell.Tab.2.bottom/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292666" />
<state width="842" height="374" key="GridCell.Tab.2.center" timestamp="1598325254381">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.2.center/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358070" />
<state width="840" height="374" key="GridCell.Tab.2.center/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432355" />
<state width="840" height="374" key="GridCell.Tab.2.left" timestamp="1598154432354">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.2.center/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254381" />
<state width="840" height="374" key="GridCell.Tab.2.center/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292666" />
<state width="842" height="374" key="GridCell.Tab.2.left" timestamp="1598325254381">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.2.left/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358070" />
<state width="840" height="374" key="GridCell.Tab.2.left/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432354" />
<state width="840" height="374" key="GridCell.Tab.2.right" timestamp="1598154432355">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.2.left/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254381" />
<state width="840" height="374" key="GridCell.Tab.2.left/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292666" />
<state width="842" height="374" key="GridCell.Tab.2.right" timestamp="1598325254381">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.2.right/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358070" />
<state width="840" height="374" key="GridCell.Tab.2.right/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432355" />
<state width="840" height="374" key="GridCell.Tab.3.bottom" timestamp="1598154432357">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.2.right/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254381" />
<state width="840" height="374" key="GridCell.Tab.2.right/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292666" />
<state width="842" height="374" key="GridCell.Tab.3.bottom" timestamp="1598325254382">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.3.bottom/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358072" />
<state width="840" height="374" key="GridCell.Tab.3.bottom/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432357" />
<state width="840" height="374" key="GridCell.Tab.3.center" timestamp="1598154432356">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.3.bottom/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254382" />
<state width="840" height="374" key="GridCell.Tab.3.bottom/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292667" />
<state width="842" height="374" key="GridCell.Tab.3.center" timestamp="1598325254382">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.3.center/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358071" />
<state width="840" height="374" key="GridCell.Tab.3.center/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432356" />
<state width="840" height="374" key="GridCell.Tab.3.left" timestamp="1598154432356">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.3.center/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254382" />
<state width="840" height="374" key="GridCell.Tab.3.center/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292667" />
<state width="842" height="374" key="GridCell.Tab.3.left" timestamp="1598325254381">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.3.left/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358071" />
<state width="840" height="374" key="GridCell.Tab.3.left/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432356" />
<state width="840" height="374" key="GridCell.Tab.3.right" timestamp="1598154432357">
<screen x="70" y="23" width="1722" height="1097" />
<state width="842" height="374" key="GridCell.Tab.3.left/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254381" />
<state width="840" height="374" key="GridCell.Tab.3.left/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292667" />
<state width="842" height="374" key="GridCell.Tab.3.right" timestamp="1598325254382">
<screen x="67" y="23" width="1725" height="1097" />
</state>
<state width="840" height="374" key="GridCell.Tab.3.right/0.0.1792.1120@0.0.1792.1120" timestamp="1598115358072" />
<state width="840" height="374" key="GridCell.Tab.3.right/70.23.1722.1097@70.23.1722.1097" timestamp="1598154432357" />
<state width="842" height="374" key="GridCell.Tab.3.right/67.23.1725.1097@67.23.1725.1097" timestamp="1598325254382" />
<state width="840" height="374" key="GridCell.Tab.3.right/70.23.1722.1097@70.23.1722.1097" timestamp="1598233292667" />
</component>
</project>

View File

@ -8,7 +8,6 @@
* 2. 节点过滤重命名排序等
* 3. 订阅拆分组合
*/
const $ = API("sub-store");
// Constants
const SUBS_KEY = "subs";
@ -233,9 +232,16 @@ async function updateSub(req, res) {
async function deleteSub(req, res) {
const {name} = req.params;
// delete from subscriptions
let allSubs = $.read(SUBS_KEY);
delete allSubs[name];
$.write(allSubs, SUBS_KEY);
// delete from collections
let allCols = $.read(COLLECTIONS_KEY);
for (const k of Object.keys(allCols)) {
allCols[k].subscriptions = allCols[k].subscriptions.filter(s => s !== name);
}
$.write(allCols, COLLECTIONS_KEY);
res.json({
status: "success"
});
@ -458,24 +464,42 @@ function ProxyParser(targetPlatform) {
if (raw.indexOf("DOCTYPE html") !== -1) {
// HTML format, maybe a wrong URL!
throw new Error("Invalid format HTML!");
} else if (raw.indexOf("proxies") !== -1) {
// Clash YAML format
// codes are modified from @KOP-XIAO
// https://github.com/KOP-XIAO/QuantumultX
if (raw.indexOf("{") !== -1) {
raw = raw.replace(/: {/g, ": {, ")
.replace(/, (host|path|tls|mux|skip)/g,", $1")
.replace(/{name: /g,"{name: \"")
.replace(/, server:/g,"\", server:")
.replace(/{|}/g,"")
.replace(/,/g,"\n ")
}
raw = raw.replace(/ -\n.*name/g," - name");
const proxies = YAML.eval(raw).proxies;
output = proxies.map(p => JSON.stringify(p));
}
// check if content is based64 encoded
const Base64 = new Base64Code();
const keys = ["dm1lc3M", "c3NyOi8v", "dHJvamFu", "c3M6Ly", "c3NkOi8v"];
if (keys.some(k => raw.indexOf(k) !== -1)) {
output = Base64.safeDecode(raw);
} else {
output = raw;
}
output = output.split("\n");
for (let i = 0; i < output.length; i++) {
output[i] = output[i].trim(); // trim lines
else {
// check if content is based64 encoded
const Base64 = new Base64Code();
const keys = ["dm1lc3M", "c3NyOi8v", "dHJvamFu", "c3M6Ly", "c3NkOi8v"];
if (keys.some(k => raw.indexOf(k) !== -1)) {
output = Base64.safeDecode(raw);
} else {
output = raw;
}
output = output.split("\n");
for (let i = 0; i < output.length; i++) {
output[i] = output[i].trim(); // trim lines
}
}
return output.join("\n");
}
// Parsers
addParsers(
Clash_All,
// URI format parsers
URI_SS, URI_SSR, URI_VMess, URI_Trojan,
// Quantumult X platform
@ -731,6 +755,15 @@ function URI_Trojan() {
return {patternTest, func};
}
/**************************** Clash ***************************************/
function Clash_All() {
const patternTest = (line) => {
return line.indexOf("{") !== -1;
}
const func = line => JSON.parse(line);
return {patternTest, func};
}
/**************************** Quantumult X ***************************************/
function QX_SS() {
const patternTest = (line) => {
@ -1354,7 +1387,7 @@ function SetPropertyOperator(key, val) {
}
// add or remove flag for proxies
function FlagOperator(type) {
function FlagOperator(type = 1) {
return {
name: "Flag Operator",
func: proxies => {
@ -1751,7 +1784,7 @@ function FULL(length, bool) {
// source: https://stackoverflow.com/questions/105034/how-to-create-guid-uuid
function UUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
@ -2075,6 +2108,7 @@ function express(port = 3000) {
const DEFAULT_HEADERS = {
"Content-Type": "text/plain;charset=UTF-8",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept"
};
@ -2461,4 +2495,448 @@ function Base64Code() {
this.safeDecode = function (a) {
return this.decode(a.replace(/-/g, "+").replace(/_/g, "/"));
}
}
}
/*
YAML parser for Javascript
Author: Diogo Costa
This program is released under the MIT License
*/
var YAML =
(function () {
var errors = [],
reference_blocks = [],
processing_time = 0,
regex =
{
"regLevel": new RegExp("^([\\s\\-]+)"),
"invalidLine": new RegExp("^\\-\\-\\-|^\\.\\.\\.|^\\s*#.*|^\\s*$"),
"dashesString": new RegExp("^\\s*\\\"([^\\\"]*)\\\"\\s*$"),
"quotesString": new RegExp("^\\s*\\\'([^\\\']*)\\\'\\s*$"),
"float": new RegExp("^[+-]?[0-9]+\\.[0-9]+(e[+-]?[0-9]+(\\.[0-9]+)?)?$"),
"integer": new RegExp("^[+-]?[0-9]+$"),
"array": new RegExp("\\[\\s*(.*)\\s*\\]"),
"map": new RegExp("\\{\\s*(.*)\\s*\\}"),
"key_value": new RegExp("([a-z0-9_-][ a-z0-9_-]*):( .+)", "i"),
"single_key_value": new RegExp("^([a-z0-9_-][ a-z0-9_-]*):( .+?)$", "i"),
"key": new RegExp("([a-z0-9_-][ a-z0-9_-]*):( .+)?", "i"),
"item": new RegExp("^-\\s+"),
"trim": new RegExp("^\\s+|\\s+$"),
"comment": new RegExp("([^\\\'\\\"#]+([\\\'\\\"][^\\\'\\\"]*[\\\'\\\"])*)*(#.*)?")
};
/**
* @class A block of lines of a given level.
* @param {int} lvl The block's level.
* @private
*/
function Block(lvl) {
return {
/* The block's parent */
parent: null,
/* Number of children */
length: 0,
/* Block's level */
level: lvl,
/* Lines of code to process */
lines: [],
/* Blocks with greater level */
children: [],
/* Add a block to the children collection */
addChild: function (obj) {
this.children.push(obj);
obj.parent = this;
++this.length;
}
};
}
function parser(str) {
var regLevel = regex["regLevel"];
var invalidLine = regex["invalidLine"];
var lines = str.split("\n");
var m;
var level = 0, curLevel = 0;
var blocks = [];
var result = new Block(-1);
var currentBlock = new Block(0);
result.addChild(currentBlock);
var levels = [];
var line = "";
blocks.push(currentBlock);
levels.push(level);
for (var i = 0, len = lines.length; i < len; ++i) {
line = lines[i];
if (line.match(invalidLine)) {
continue;
}
if (m = regLevel.exec(line)) {
level = m[1].length;
} else
level = 0;
if (level > curLevel) {
var oldBlock = currentBlock;
currentBlock = new Block(level);
oldBlock.addChild(currentBlock);
blocks.push(currentBlock);
levels.push(level);
} else if (level < curLevel) {
var added = false;
var k = levels.length - 1;
for (; k >= 0; --k) {
if (levels[k] == level) {
currentBlock = new Block(level);
blocks.push(currentBlock);
levels.push(level);
if (blocks[k].parent != null)
blocks[k].parent.addChild(currentBlock);
added = true;
break;
}
}
if (!added) {
errors.push("Error: Invalid indentation at line " + i + ": " + line);
return;
}
}
currentBlock.lines.push(line.replace(regex["trim"], ""));
curLevel = level;
}
return result;
}
function processValue(val) {
val = val.replace(regex["trim"], "");
var m = null;
if (val == 'true') {
return true;
} else if (val == 'false') {
return false;
} else if (val == '.NaN') {
return Number.NaN;
} else if (val == 'null') {
return null;
} else if (val == '.inf') {
return Number.POSITIVE_INFINITY;
} else if (val == '-.inf') {
return Number.NEGATIVE_INFINITY;
} else if (m = val.match(regex["dashesString"])) {
return m[1];
} else if (m = val.match(regex["quotesString"])) {
return m[1];
} else if (m = val.match(regex["float"])) {
return parseFloat(m[0]);
} else if (m = val.match(regex["integer"])) {
return parseInt(m[0]);
} else if (!isNaN(m = Date.parse(val))) {
return new Date(m);
} else if (m = val.match(regex["single_key_value"])) {
var res = {};
res[m[1]] = processValue(m[2]);
return res;
} else if (m = val.match(regex["array"])) {
var count = 0, c = ' ';
var res = [];
var content = "";
var str = false;
for (var j = 0, lenJ = m[1].length; j < lenJ; ++j) {
c = m[1][j];
if (c == '\'' || c == '"') {
if (str === false) {
str = c;
content += c;
continue;
} else if ((c == '\'' && str == '\'') || (c == '"' && str == '"')) {
str = false;
content += c;
continue;
}
} else if (str === false && (c == '[' || c == '{')) {
++count;
} else if (str === false && (c == ']' || c == '}')) {
--count;
} else if (str === false && count == 0 && c == ',') {
res.push(processValue(content));
content = "";
continue;
}
content += c;
}
if (content.length > 0)
res.push(processValue(content));
return res;
} else if (m = val.match(regex["map"])) {
var count = 0, c = ' ';
var res = [];
var content = "";
var str = false;
for (var j = 0, lenJ = m[1].length; j < lenJ; ++j) {
c = m[1][j];
if (c == '\'' || c == '"') {
if (str === false) {
str = c;
content += c;
continue;
} else if ((c == '\'' && str == '\'') || (c == '"' && str == '"')) {
str = false;
content += c;
continue;
}
} else if (str === false && (c == '[' || c == '{')) {
++count;
} else if (str === false && (c == ']' || c == '}')) {
--count;
} else if (str === false && count == 0 && c == ',') {
res.push(content);
content = "";
continue;
}
content += c;
}
if (content.length > 0)
res.push(content);
var newRes = {};
for (var j = 0, lenJ = res.length; j < lenJ; ++j) {
if (m = res[j].match(regex["key_value"])) {
newRes[m[1]] = processValue(m[2]);
}
}
return newRes;
} else
return val;
}
function processFoldedBlock(block) {
var lines = block.lines;
var children = block.children;
var str = lines.join(" ");
var chunks = [str];
for (var i = 0, len = children.length; i < len; ++i) {
chunks.push(processFoldedBlock(children[i]));
}
return chunks.join("\n");
}
function processLiteralBlock(block) {
var lines = block.lines;
var children = block.children;
var str = lines.join("\n");
for (var i = 0, len = children.length; i < len; ++i) {
str += processLiteralBlock(children[i]);
}
return str;
}
function processBlock(blocks) {
var m = null;
var res = {};
var lines = null;
var children = null;
var currentObj = null;
var level = -1;
var processedBlocks = [];
var isMap = true;
for (var j = 0, lenJ = blocks.length; j < lenJ; ++j) {
if (level != -1 && level != blocks[j].level)
continue;
processedBlocks.push(j);
level = blocks[j].level;
lines = blocks[j].lines;
children = blocks[j].children;
currentObj = null;
for (var i = 0, len = lines.length; i < len; ++i) {
var line = lines[i];
if (m = line.match(regex["key"])) {
var key = m[1];
if (key[0] == '-') {
key = key.replace(regex["item"], "");
if (isMap) {
isMap = false;
if (typeof (res.length) === "undefined") {
res = [];
}
}
if (currentObj != null) res.push(currentObj);
currentObj = {};
isMap = true;
}
if (typeof m[2] != "undefined") {
var value = m[2].replace(regex["trim"], "");
if (value[0] == '&') {
var nb = processBlock(children);
if (currentObj != null) currentObj[key] = nb;
else res[key] = nb;
reference_blocks[value.substr(1)] = nb;
} else if (value[0] == '|') {
if (currentObj != null) currentObj[key] = processLiteralBlock(children.shift());
else res[key] = processLiteralBlock(children.shift());
} else if (value[0] == '*') {
var v = value.substr(1);
var no = {};
if (typeof reference_blocks[v] == "undefined") {
errors.push("Reference '" + v + "' not found!");
} else {
for (var k in reference_blocks[v]) {
no[k] = reference_blocks[v][k];
}
if (currentObj != null) currentObj[key] = no;
else res[key] = no;
}
} else if (value[0] == '>') {
if (currentObj != null) currentObj[key] = processFoldedBlock(children.shift());
else res[key] = processFoldedBlock(children.shift());
} else {
if (currentObj != null) currentObj[key] = processValue(value);
else res[key] = processValue(value);
}
} else {
if (currentObj != null) currentObj[key] = processBlock(children);
else res[key] = processBlock(children);
}
} else if (line.match(/^-\s*$/)) {
if (isMap) {
isMap = false;
if (typeof (res.length) === "undefined") {
res = [];
}
}
if (currentObj != null) res.push(currentObj);
currentObj = {};
isMap = true;
continue;
} else if (m = line.match(/^-\s*(.*)/)) {
if (currentObj != null)
currentObj.push(processValue(m[1]));
else {
if (isMap) {
isMap = false;
if (typeof (res.length) === "undefined") {
res = [];
}
}
res.push(processValue(m[1]));
}
continue;
}
}
if (currentObj != null) {
if (isMap) {
isMap = false;
if (typeof (res.length) === "undefined") {
res = [];
}
}
res.push(currentObj);
}
}
for (var j = processedBlocks.length - 1; j >= 0; --j) {
blocks.splice.call(blocks, processedBlocks[j], 1);
}
return res;
}
function semanticAnalysis(blocks) {
var res = processBlock(blocks.children);
return res;
}
function preProcess(src) {
var m;
var lines = src.split("\n");
var r = regex["comment"];
for (var i in lines) {
if (m = (typeof lines[i] === 'string' && lines[i].match(r))) {
/* var cmt = "";
if(typeof m[3] != "undefined")
lines[i] = m[1];
else if(typeof m[3] != "undefined")
lines[i] = m[3];
else
lines[i] = "";
*/
if (typeof m[3] !== "undefined") {
lines[i] = m[0].substr(0, m[0].length - m[3].length);
}
}
}
return lines.join("\n");
}
function eval(str) {
errors = [];
reference_blocks = [];
processing_time = (new Date()).getTime();
var pre = preProcess(str)
var doc = parser(pre);
var res = semanticAnalysis(doc);
processing_time = (new Date()).getTime() - processing_time;
return res;
}
return {
/**
* Parse a YAML file from a string.
* @param {String} str String with the YAML file contents.
* @function
*/
eval: eval,
/**
* Get errors found when parsing the last file.
* @function
* @returns Errors found when parsing the last file.
*/
getErrors: function () {
return errors;
},
/**
* Get the time it took to parse the last file.
* @function
* @returns Time in milliseconds.
*/
getProcessingTime: function () {
return processing_time;
}
}
})();

View File

@ -1,6 +1,5 @@
<template>
<div>
<v-navigation-drawer
app
fixed

3
web/src/config.js Normal file
View File

@ -0,0 +1,3 @@
const DEBUG = true;
export const BACKEND_BASE = DEBUG ? `http://127.0.0.1:3000` : `http://sub.store`;

View File

@ -52,9 +52,13 @@ const store = new Vuex.Store({
});
},
// update subscriptions
async UPDATE_SUBSCRIPTION({commit}, {name, sub}) {
async UPDATE_SUBSCRIPTION({commit, dispatch}, {name, sub}) {
axios.patch(`/sub/${name}`, sub).then(() => {
commit("FETCH_SUBSCRIPTIONS");
dispatch("FETCH_SUBSCRIPTIONS");
dispatch("FETCH_COLLECTIONS");
commit("SET_SUCCESS_MESSAGE", `成功更新订阅${sub.name || name}`);
}).catch(err => {
commit("SET_ERROR_MESSAGE", err);
});
},
// new subscription
@ -62,8 +66,14 @@ const store = new Vuex.Store({
},
// delete subscription
async DELETE_SUBSCRIPTION() {
async DELETE_SUBSCRIPTION({commit, dispatch}, name) {
axios.delete(`/sub/${name}`).then(() => {
dispatch("FETCH_SUBSCRIPTIONS");
dispatch("FETCH_COLLECTIONS");
commit("SET_SUCCESS_MESSAGE", `成功删除订阅${name}`);
}).catch(err => {
commit("SET_ERROR_MESSAGE", err);
})
},
// update collection
async UPDATE_COLLECTION() {

View File

@ -1,7 +1,8 @@
import Axios from 'axios';
import {BACKEND_BASE} from "@/config";
export const axios = Axios.create({
// baseURL: 'http://sub.store/api',
baseURL: 'http://127.0.0.1:3000/api',
baseURL: `${BACKEND_BASE}/api`,
timeout: 1000
});

View File

@ -1,13 +0,0 @@
<template>
<v-container></v-container>
</template>
<script>
export default {
name: "PopUpProxyList"
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,40 @@
<template>
<v-list>
<v-list-item v-for="proxy in proxies" :key="proxy.name">
<v-list-item-content>
<v-list-item-title v-text="proxy.name" class="wrap-text"></v-list-item-title>
<v-list-item-subtitle v-text="getType(proxy.type)"></v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn icon>
<v-icon color="grey lighten-1">mdi-information</v-icon>
</v-btn>
</v-list-item-action>
</v-list-item>
</v-list>
</template>
<script>
export default {
name: "ProxyList",
props: ['proxies'],
methods: {
getType(type) {
switch (type) {
case 'ss':
return 'shadowsocks'
case 'ssr':
return 'shadowsocksr'
default:
return type
}
}
}
}
</script>
<style scoped>
.wrap-text {
white-space: normal;
}
</style>

View File

@ -8,9 +8,8 @@
:key="sub.name"
@click="preview(sub)"
>
<v-list-item-avatar>
<v-img
src="https://avatars2.githubusercontent.com/u/21050064?s=460&u=40a74913dd0a3d00670d05148c3a08c787470021&v=4"></v-img>
<v-list-item-avatar dark>
<v-icon>mdi-cloud</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-text="sub.name" class="font-weight-medium"></v-list-item-title>
@ -47,12 +46,11 @@
<v-list-item
v-for="collection in collections"
:key="collection.name"
@click="preview(collection)"
@click="preview(collection, type='collection')"
dense
>
<v-list-item-avatar>
<v-img
src="https://avatars2.githubusercontent.com/u/21050064?s=460&u=40a74913dd0a3d00670d05148c3a08c787470021&v=4"></v-img>
<v-list-item-avatar dark>
<v-icon>mdi-cloud</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-text="collection.name" class="font-weight-medium"></v-list-item-title>
@ -97,6 +95,7 @@
</v-list>
<v-fab-transition>
<v-speed-dial
v-if="!showProxyList"
v-model="opened"
direction="top"
right
@ -122,14 +121,37 @@
</v-btn>
</v-speed-dial>
</v-fab-transition>
<v-dialog fullscreen hide-overlay transition="dialog-bottom-transition" v-model="showProxyList">
<v-card>
<v-toolbar dark color="primary">
<v-icon>mdi-cloud</v-icon>
<v-spacer></v-spacer>
<v-toolbar-title>节点列表</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>
</v-toolbar>
<proxy-list :proxies="proxies"></proxy-list>
</v-card>
</v-dialog>
</v-container>
</template>
<script>
import ProxyList from "@/views/ProxyList";
import {BACKEND_BASE} from "@/config";
import {axios} from "@/utils";
export default {
components: {ProxyList},
data: () => {
return {
opened: false,
showProxyList: false,
proxies: [],
editMenu: [
{
title: "复制",
@ -163,13 +185,14 @@ export default {
console.log(`${action} --> ${sub.name}`);
switch (action) {
case 'COPY':
this.$clipboard(`http://127.0.0.1:3000/download/${sub.name}`);
this.$clipboard(`${BACKEND_BASE}/download/${sub.name}`);
this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制订阅链接");
break
case 'EDIT':
this.$router.push(`/sub-edit/${sub.name}`);
break
case 'DELETE':
this.$store.dispatch("DELETE_SUBSCRIPTION", sub.name);
break
}
},
@ -177,17 +200,30 @@ export default {
console.log(`${action} --> ${collection.name}`);
switch (action) {
case 'COPY':
this.$clipboard(`http://127.0.0.1:3000/download/collection/${collection.name}`);
this.$clipboard(`${BACKEND_BASE}/download/collection/${collection.name}`);
this.$store.commit("SET_SUCCESS_MESSAGE", "成功复制订阅链接");
break
case 'EDIT':
break
case 'DELETE':
this.$store.dispatch("DELETE_COLLECTION", collection.name);
break
}
},
preview(item) {
console.log(`PREVIEW: ${item.name}`);
preview(item, type = 'sub') {
let url;
if (type === 'sub') {
url = `${BACKEND_BASE}/download/${item.name}`
} else {
url = `${BACKEND_BASE}/download/collection/${item.name}`
}
axios.get(url).then(resp => {
const {data} = resp;
this.proxies = data.split("\n").map(p => JSON.parse(p));
this.showProxyList = true;
}).catch(err => {
this.$store.commit("SET_ERROR_MESSAGE", err);
})
},
}
}