bug fixed

This commit is contained in:
Peng-YM 2020-09-01 17:56:24 +08:00
parent 8fc5e58276
commit 2d6aa1ef1a
5 changed files with 2875 additions and 2877 deletions

View File

@ -22,8 +22,9 @@
<list default="true" id="8b97a098-48b2-4e64-a9ef-522fe2d30b52" name="Default Changelist" comment=""> <list default="true" id="8b97a098-48b2-4e64-a9ef-522fe2d30b52" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/sub-store.js" beforeDir="false" afterPath="$PROJECT_DIR$/sub-store.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/SortOperator.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/components/SortOperator.vue" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../web/src/components/ProxyList.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/components/ProxyList.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/config.js" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/config.js" afterDir="false" /> <change beforePath="$PROJECT_DIR$/../web/src/config.js" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/config.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../web/src/views/Subscription.vue" beforeDir="false" afterPath="$PROJECT_DIR$/../web/src/views/Subscription.vue" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -93,6 +94,7 @@
<workItem from="1598900239005" duration="4742000" /> <workItem from="1598900239005" duration="4742000" />
<workItem from="1598931009084" duration="2069000" /> <workItem from="1598931009084" duration="2069000" />
<workItem from="1598946261983" duration="463000" /> <workItem from="1598946261983" duration="463000" />
<workItem from="1598948545209" duration="3969000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -9,8 +9,9 @@
* 3. 订阅拆分组合 * 3. 订阅拆分组合
*/ */
const $ = API("sub-store", true); const $ = API("sub-store", true);
const $code = new Base64Code(); const $app = express();
$.http = HTTP("", {
$.http = HTTP({
headers: { headers: {
"User-Agent": "Quantumult", "User-Agent": "Quantumult",
}, },
@ -18,6 +19,26 @@ $.http = HTTP("", {
// Constants // Constants
const SUBS_KEY = "subs"; const SUBS_KEY = "subs";
const COLLECTIONS_KEY = "collections"; const COLLECTIONS_KEY = "collections";
const AVAILABLE_FILTERS = {
"Keyword Filter": KeywordFilter,
"Useless Filter": UselessFilter,
"Region Filter": RegionFilter,
"Regex Filter": RegexFilter,
"Type Filter": TypeFilter,
"Script Filter": ScriptFilter,
};
const AVAILABLE_OPERATORS = {
"Set Property Operator": SetPropertyOperator,
"Flag Operator": FlagOperator,
"Sort Operator": SortOperator,
"Keyword Sort Operator": KeywordSortOperator,
"Keyword Rename Operator": KeywordRenameOperator,
"Keyword Delete Operator": KeywordDeleteOperator,
"Regex Rename Operator": RegexRenameOperator,
"Regex Delete Operator": RegexDeleteOperator,
"Script Operator": ScriptOperator,
};
// SOME INITIALIZATIONS // SOME INITIALIZATIONS
if (!$.read(SUBS_KEY)) $.write({}, SUBS_KEY); if (!$.read(SUBS_KEY)) $.write({}, SUBS_KEY);
@ -25,20 +46,19 @@ if (!$.read(COLLECTIONS_KEY)) $.write({}, COLLECTIONS_KEY);
// BACKEND API // BACKEND API
$.log("Initializing Express..."); $.log("Initializing Express...");
const $app = express();
// download // download
$app.get("/download/collection/:name", downloadCollection); $app.get("/download/collection/:name", downloadCollection);
$app.get("/download/:name", downloadSub); $app.get("/download/:name", downloadSub);
// refresh
$app.post("/api/refresh", refreshResource);
// subscriptions // subscriptions
$app.route("/api/sub/:name").get(getSub).patch(updateSub).delete(deleteSub); $app.route("/api/sub/:name").get(getSub).patch(updateSub).delete(deleteSub);
$app.route("/api/sub").get(getAllSubs).post(newSub).delete(deleteAllSubs); $app.route("/api/sub").get(getAllSubs).post(newSub).delete(deleteAllSubs);
// refresh
$app.post("/api/refresh", refreshResource);
// collections // collections
$app $app
.route("/api/collection/:name") .route("/api/collection/:name")
@ -56,41 +76,13 @@ $app.all("/", async (req, res) => {
res.send("Hello from Sub-Store! Made with ❤️ by Peng-YM."); res.send("Hello from Sub-Store! Made with ❤️ by Peng-YM.");
}); });
$app.start();
$.log("Express initialized"); $.log("Express initialized");
$app.start();
// SOME CONSTANTS
var DEFAULT_SUPPORTED_PLATFORMS = {
QX: true,
Loon: true,
Surge: true,
Raw: true,
};
var AVAILABLE_FILTERS = {
"Keyword Filter": KeywordFilter,
"Useless Filter": UselessFilter,
"Region Filter": RegionFilter,
"Regex Filter": RegexFilter,
"Type Filter": TypeFilter,
"Script Filter": ScriptFilter,
};
var AVAILABLE_OPERATORS = {
"Set Property Operator": SetPropertyOperator,
"Flag Operator": FlagOperator,
"Sort Operator": SortOperator,
"Keyword Sort Operator": KeywordSortOperator,
"Keyword Rename Operator": KeywordRenameOperator,
"Keyword Delete Operator": KeywordDeleteOperator,
"Regex Rename Operator": RegexRenameOperator,
"Regex Delete Operator": RegexDeleteOperator,
"Script Operator": ScriptOperator,
};
/**************************** API -- Subscriptions ***************************************/ /**************************** API -- Subscriptions ***************************************/
// refresh resource // refresh resource
async function refreshResource(req, res) { async function refreshResource(req, res) {
const Base64 = new Base64Code();
const {url} = req.body; const {url} = req.body;
const raw = await $.http const raw = await $.http
.get(url) .get(url)
@ -101,7 +93,7 @@ async function refreshResource(req, res) {
message: `Cannot refresh remote resource: ${url}\n Reason: ${err}`, message: `Cannot refresh remote resource: ${url}\n Reason: ${err}`,
}); });
}); });
$.write(raw, `#${$code.safeEncode(url)}`); $.write(raw, `#${Base64.safeEncode(url)}`);
res.json({ res.json({
status: "success", status: "success",
}); });
@ -133,7 +125,7 @@ async function downloadSub(req, res) {
async function parseSub(sub, platform) { async function parseSub(sub, platform) {
let raw; let raw;
const key = $code.safeEncode(sub.url); const key = new Base64Code().safeEncode(sub.url);
if (platform === "Raw") { if (platform === "Raw") {
const cache = $.read(`#${key}`); const cache = $.read(`#${key}`);
@ -221,7 +213,7 @@ async function parseSub(sub, platform) {
if (item.type.indexOf("Filter") !== -1) { if (item.type.indexOf("Filter") !== -1) {
const filter = AVAILABLE_FILTERS[item.type]; const filter = AVAILABLE_FILTERS[item.type];
if (filter) { if (filter) {
$filter.addFilters(filter(item.args)); $filter.setFilter(filter(item.args));
proxies = $filter.process(proxies); proxies = $filter.process(proxies);
$.log( $.log(
`Applying filter "${item.type}" with arguments:\n >>> ${ `Applying filter "${item.type}" with arguments:\n >>> ${
@ -232,7 +224,7 @@ async function parseSub(sub, platform) {
} else if (item.type.indexOf("Operator") !== -1) { } else if (item.type.indexOf("Operator") !== -1) {
const operator = AVAILABLE_OPERATORS[item.type]; const operator = AVAILABLE_OPERATORS[item.type];
if (operator) { if (operator) {
$operator.addOperators(operator(item.args)); $operator.setOperator(operator(item.args));
proxies = $operator.process(proxies); proxies = $operator.process(proxies);
$.log( $.log(
`Applying operator "${item.type}" with arguments: \n >>> ${ `Applying operator "${item.type}" with arguments: \n >>> ${
@ -336,6 +328,7 @@ async function newSub(req, res) {
async function updateSub(req, res) { async function updateSub(req, res) {
const {name} = req.params; const {name} = req.params;
$.log(`Updating subscription: ${name}`);
let sub = req.body; let sub = req.body;
const allSubs = $.read(SUBS_KEY); const allSubs = $.read(SUBS_KEY);
if (allSubs[name]) { if (allSubs[name]) {
@ -666,54 +659,52 @@ function ProxyParser(targetPlatform) {
} }
function ProxyFilter() { function ProxyFilter() {
const filters = []; let filter;
function addFilters(...args) { function setFilter(arg) {
args.forEach((a) => filters.push(a)); filter = arg;
} }
// select proxies // select proxies
function process(proxies) { function process(proxies) {
let selected = FULL(proxies.length, true); let selected = FULL(proxies.length, true);
for (const filter of filters) {
try { try {
selected = AND(selected, filter.func(proxies)); selected = AND(selected, filter.func(proxies));
} catch (err) { } catch (err) {
console.log(`Cannot apply filter ${filter.name}\n Reason: ${err}`); console.log(`Cannot apply filter ${filter.name}\n Reason: ${err}`);
} }
}
return proxies.filter((_, i) => selected[i]); return proxies.filter((_, i) => selected[i]);
} }
return { return {
process, process,
addFilters, setFilter,
}; };
} }
function ProxyOperator() { function ProxyOperator() {
const operators = []; let operator;
function addOperators(...args) { function setOperator(arg) {
args.forEach((a) => operators.push(a)); operator = arg;
} }
// run all operators // run all operators
function process(proxies) { function process(proxies) {
let output = objClone(proxies); let output = objClone(proxies);
for (const op of operators) {
try { try {
const output_ = op.func(output); const output_ = operator.func(output);
if (output_) output = output_; if (output_) output = output_;
} catch (err) { } catch (err) {
// print log and skip this operator // print log and skip this operator
console.log(`ERROR: cannot apply operator ${op.name}! Reason: ${err}`); console.log(`ERROR: cannot apply operator ${op.name}! Reason: ${err}`);
} }
}
return output; return output;
} }
return { addOperators, process }; return {setOperator, process};
} }
/**************************** URI Format ***************************************/ /**************************** URI Format ***************************************/
@ -1719,10 +1710,10 @@ function FlagOperator(add = true) {
name: "Flag Operator", name: "Flag Operator",
func: (proxies) => { func: (proxies) => {
return proxies.map((proxy) => { return proxies.map((proxy) => {
if (!add) if (!add) {
// no flag // no flag
proxy.name = removeFlag(proxy.name); proxy.name = removeFlag(proxy.name);
else { } else {
// get flag // get flag
const newFlag = getFlag(proxy.name); const newFlag = getFlag(proxy.name);
// remove old flag // remove old flag
@ -2184,7 +2175,7 @@ function removeFlag(str) {
} }
// objClone an object // objClone an object
function objobjClone(obj) { function objClone(obj) {
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
@ -2271,20 +2262,22 @@ function ENV() {
return {isQX, isLoon, isSurge, isNode, isJSBox, isRequest}; return {isQX, isLoon, isSurge, isNode, isJSBox, isRequest};
} }
function HTTP(baseURL, defaultOptions = {}) { function HTTP(defaultOptions = {}) {
const {isQX, isLoon, isSurge} = ENV(); const {isQX, isLoon, isSurge} = ENV();
const methods = ["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH"]; const methods = ["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH"];
function send(method, options) { function send(method, options) {
options = typeof options === "string" ? { url: options } : options; options = options.hasOwnProperty("url") ? options : {url: options};
options.url = baseURL ? baseURL + options.url : options.url; options.url = defaultOptions.baseURL ? defaultOptions.baseURL + options.url : options.url;
options = {...defaultOptions, ...options}; options = {...defaultOptions, ...options};
const timeout = options.timeout; const timeout = options.timeout;
const events = { const events = {
...{ ...{
onRequest: () => {}, onRequest: () => {
},
onResponse: (resp) => resp, onResponse: (resp) => resp,
onTimeout: () => {}, onTimeout: () => {
},
}, },
...options.events, ...options.events,
}; };
@ -2581,6 +2574,8 @@ function express(port = 3000) {
// dispatch url to route // dispatch url to route
const dispatch = (request, start = 0) => { const dispatch = (request, start = 0) => {
let {method, url, headers, body} = request; let {method, url, headers, body} = request;
console.log("DISPATCHING: " + method + ": " + url);
if (/json/i.test(headers["Content-Type"])) { if (/json/i.test(headers["Content-Type"])) {
body = JSON.parse(body); body = JSON.parse(body);
} }
@ -2614,9 +2609,6 @@ function express(port = 3000) {
body, body,
}; };
const res = Response(); const res = Response();
if (typeof handler.callback === "undefined") {
$.notify("FUCK");
}
handler.callback(req, res, next).catch((err) => { handler.callback(req, res, next).catch((err) => {
res.status(500).json({ res.status(500).json({
status: "failed", status: "failed",
@ -2658,6 +2650,7 @@ function express(port = 3000) {
// start service // start service
app.start = () => { app.start = () => {
console.log(`STARTING TO ROUTE: ${JSON.stringify($request)}`);
dispatch($request); dispatch($request);
}; };

View File

@ -36,7 +36,7 @@ import {axios} from "@/utils";
export default { export default {
name: "ProxyList", name: "ProxyList",
props: ['url'], props: ['url', 'sub'],
data: function (){ data: function (){
return { return {
proxies: [] proxies: []
@ -44,7 +44,7 @@ export default {
}, },
methods: { methods: {
refresh() { refresh() {
axios.post(`/refresh`, {url: this.url}).then(() => { axios.post(`/refresh`, {url: this.sub}).then(() => {
this.fetch(); this.fetch();
}) })
}, },

View File

@ -1,2 +1,3 @@
const DEBUG = process.env.NODE_ENV === "development"; // const DEBUG = process.env.NODE_ENV === "development";
const DEBUG = false;
export const BACKEND_BASE = DEBUG ? `http://192.168.1.134:3000` : `https://sub.store`; export const BACKEND_BASE = DEBUG ? `http://192.168.1.134:3000` : `https://sub.store`;

View File

@ -148,7 +148,7 @@
</v-toolbar> </v-toolbar>
</v-card-title> </v-card-title>
<v-card-text class="pl-0 pr-0"> <v-card-text class="pl-0 pr-0">
<proxy-list :url="url" 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-card> </v-card>
</v-dialog> </v-dialog>
@ -166,6 +166,7 @@ export default {
opened: false, opened: false,
showProxyList: false, showProxyList: false,
url: "", url: "",
sub: [],
editMenu: [ editMenu: [
{ {
title: "复制", title: "复制",
@ -227,7 +228,8 @@ export default {
}, },
preview(item, type = 'sub') { preview(item, type = 'sub') {
if (type === 'sub') { if (type === 'sub') {
this.url = `${BACKEND_BASE}/download/${item.name}` this.url = `${BACKEND_BASE}/download/${item.name}`;
this.sub = [item.url];
} else { } else {
this.url = `${BACKEND_BASE}/download/collection/${item.name}` this.url = `${BACKEND_BASE}/download/collection/${item.name}`
} }