Fixed ESLint issues

This commit is contained in:
Peng-YM committed 2022-05-24 22:24:31 +08:00
1 parent 3a1bc439d0
commit 13dbe900fe
10 files changed
+42 -36

No files matched your search

+15 -11
View File
@@ -1,3 +1,4 @@
/* eslint-disable no-case-declarations */
import { safeLoad } from 'static-js-yaml';
import { Base64 } from 'js-base64';
@@ -12,7 +13,7 @@ const PROXY_PREPROCESSORS = (function () {
const name = 'HTML';
const test = (raw) => /^<!DOCTYPE html>/.test(raw);
// simply discard HTML
const parse = (_) => '';
const parse = () => '';
return { name, test, parse };
}
@@ -61,12 +62,6 @@ const PROXY_PREPROCESSORS = (function () {
// preprocessing for SSD subscription format
const output = [];
let ssdinfo = JSON.parse(Base64.decode(raw.split('ssd://')[1]));
// options (traffic_used, traffic_total, expiry, url)
const traffic_used = ssdinfo.traffic_used; // GB
const traffic_total = ssdinfo.traffic_total; // GB, -1 means unlimited
const expiry = ssdinfo.expiry; // YYYY-MM-DD HH:mm:ss
// default setting
let name = ssdinfo.airport; // name of the airport
let port = ssdinfo.port;
let method = ssdinfo.encryption;
let password = ssdinfo.password;
@@ -124,7 +119,7 @@ const PROXY_PARSERS = (function () {
};
content = content.split('#')[0]; // strip proxy name
// handle IPV4 and IPV6
const serverAndPort = content.match(/@([^\/]*)(\/|$)/)[1];
const serverAndPort = content.match(/@([^/]*)(\/|$)/)[1];
const portIdx = serverAndPort.lastIndexOf(':');
proxy.server = serverAndPort.substring(0, portIdx);
proxy.port = serverAndPort.substring(portIdx + 1);
@@ -1178,9 +1173,10 @@ const PROXY_PROCESSORS = (function () {
};
}
// use base64 encoded script to rename
/** Example script
/** Script Operator
function operator(proxies) {
const {arg1} = $arguments;
// do something
return proxies;
}
@@ -1189,6 +1185,7 @@ const PROXY_PROCESSORS = (function () {
1. This function name should be `operator`!
2. Always declare variables before using them!
*/
// eslint-disable-next-line no-unused-vars
function ScriptOperator(script, targetPlatform, $arguments) {
return {
name: 'Script Operator',
@@ -1196,12 +1193,18 @@ const PROXY_PROCESSORS = (function () {
let output = proxies;
(function () {
// interface to get internal operators
// eslint-disable-next-line no-unused-vars
const $get = (name, args) => {
const item = PROXY_PROCESSORS[name];
return item(args);
};
// eslint-disable-next-line no-unused-vars
const $process = ApplyProcessor;
eval(script);
// eslint-disable-next-line no-undef
output = operator(proxies, targetPlatform);
})();
return output;
@@ -1289,7 +1292,6 @@ const PROXY_PROCESSORS = (function () {
};
}
// use base64 encoded script to filter proxies
/**
Script Example
function func(proxies) {
@@ -1301,6 +1303,7 @@ const PROXY_PROCESSORS = (function () {
1. This function name should be `func`!
2. Always declare variables before using them!
*/
// eslint-disable-next-line no-unused-vars
function ScriptFilter(script, targetPlatform, $arguments) {
return {
name: 'Script Filter',
@@ -1308,6 +1311,7 @@ const PROXY_PROCESSORS = (function () {
let output = FULL(proxies.length, true);
!(function () {
eval(script);
// eslint-disable-next-line no-undef
output = filter(proxies, targetPlatform);
})();
return output;
+4 -2
View File
@@ -1,3 +1,5 @@
import { ApplyProcessor } from './proxy-utils';
import YAML from 'static-js-yaml';
import $ from './app';
const RULE_TYPES_MAPPING = [
@@ -19,7 +21,7 @@ const RULE_PREPROCESSORS = (function () {
const name = 'HTML';
const test = (raw) => /^<!DOCTYPE html>/.test(raw);
// simply discard HTML
const parse = (_) => '';
const parse = () => '';
return { name, test, parse };
}
@@ -226,7 +228,7 @@ const RULE_PRODUCERS = (function () {
return output;
}),
};
return YAML.stringify(conf);
return YAML.dump(conf);
};
return { type, func };
}
+4 -4
View File
@@ -13,7 +13,7 @@ import {
SETTINGS_KEY,
} from './constants';
function register($app) {
export default function register($app) {
// Initialization
if (!$.read(ARTIFACTS_KEY)) $.write({}, ARTIFACTS_KEY);
@@ -66,7 +66,7 @@ async function getArtifact(req, res) {
artifact.updated = new Date().getTime();
const body = JSON.parse(resp.body);
artifact.url = body.files[artifact.name].raw_url.replace(
/\/raw\/[^\/]*\/(.*)/,
/\/raw\/[^/]*\/(.*)/,
'/raw/$1',
);
$.write(allArtifacts, ARTIFACTS_KEY);
@@ -198,7 +198,7 @@ async function cronSyncArtifacts(_, res) {
artifact.updated = new Date().getTime();
// extract real url from gist
artifact.url = body.files[artifact.name].raw_url.replace(
/\/raw\/[^\/]*\/(.*)/,
/\/raw\/[^/]*\/(.*)/,
'/raw/$1',
);
}
@@ -410,4 +410,4 @@ async function produceArtifact(
}
}
export { register, produceArtifact };
export { produceArtifact };
+1 -1
View File
@@ -3,7 +3,7 @@ import { SUBS_KEY, COLLECTIONS_KEY } from './constants';
import { produceArtifact } from './artifacts';
import $ from '../core/app';
export function register($app) {
export default function register($app) {
if (!$.read(COLLECTIONS_KEY)) $.write({}, COLLECTIONS_KEY);
$app.get('/download/collection/:name', downloadCollection);
+10 -12
View File
@@ -9,21 +9,19 @@ import { IP_API } from '../utils/geo';
import Gist from '../utils/gist';
import $ from '../core/app';
import registerSubscriptionRoutes from './subscriptions';
import registerCollectionRoutes from './collections';
import registerArtifactRoutes from './artifacts';
import registerSettingRoutes from './settings';
export default function serve() {
const $app = express();
// register routes
const collections = require('./collections');
collections.register($app);
const subscriptions = require('./subscriptions');
subscriptions.register($app);
const settings = require('./settings');
settings.register($app);
const artifacts = require('./artifacts');
artifacts.register($app);
registerCollectionRoutes($app);
registerSubscriptionRoutes($app);
registerSettingRoutes($app);
registerArtifactRoutes($app);
// utils
$app.get('/api/utils/IP_API/:server', IP_API); // IP-API reverse proxy
@@ -78,10 +76,10 @@ async function gistBackup(req, res) {
});
try {
let content;
const settings = $.read(SETTINGS_KEY);
switch (action) {
case 'upload':
// update syncTime.
const settings = $.read(SETTINGS_KEY);
settings.syncTime = new Date().getTime();
$.write(settings, SETTINGS_KEY);
content = $.read('#sub-store');
+1 -1
View File
@@ -1,7 +1,7 @@
import { SETTINGS_KEY } from './constants';
import $ from '../core/app';
export function register($app) {
export default function register($app) {
if (!$.read(SETTINGS_KEY)) $.write({}, SETTINGS_KEY);
$app.route('/api/settings').get(getSettings).patch(updateSettings);
}
+1 -1
View File
@@ -2,7 +2,7 @@ import { SUBS_KEY, COLLECTIONS_KEY } from './constants';
import { produceArtifact } from './artifacts';
import $ from '../core/app';
export function register($app) {
export default function register($app) {
if (!$.read(SUBS_KEY)) $.write({}, SUBS_KEY);
$app.get('/download/:name', downloadSubscription);
+2 -1
View File
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
import { ENV } from './open-api';
import $ from '../core/app';
@@ -238,7 +239,7 @@ export default function express({ port } = { port: 3000 }) {
function extractURL(url) {
// extract path
const match = url.match(/https?:\/\/[^\/]+(\/[^?]*)/) || [];
const match = url.match(/https?:\/\/[^/]+(\/[^?]*)/) || [];
const path = match[1] || '/';
// extract query string
+2 -1
View File
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
export function ENV() {
const isQX = typeof $task !== 'undefined';
const isLoon = typeof $loon !== 'undefined';
@@ -18,7 +19,7 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
'PATCH',
];
const URL_REGEX =
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
function send(method, options) {
options = typeof options === 'string' ? { url: options } : options;
+2 -2
View File
@@ -6,11 +6,11 @@
* ███████║╚██████╔╝██████╔╝ ███████║ ██║ ╚██████╔╝██║ ██║███████╗
* ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
* Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket!
* @updated: 2022/5/24 下午9:18:57
* @updated: 2022/5/24 下午10:23:56
* @version: 1.5.1
* @author: Peng-YM
* @github: https://github.com/Peng-YM/Sub-Store
* @documentation: https://www.notion.so/Sub-Store-6259586994d34c11a4ced5c406264b46
*/
!function(){var createModuleFactory=function(t){var e;return function(r){return e||t(e={exports:{},parent:r},e.exports),e.exports}},_$settings_43=createModuleFactory((function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.register=function(t){n.default.read(_$constants_41.SETTINGS_KEY)||n.default.write({},_$constants_41.SETTINGS_KEY),t.route("/api/settings").get(s).patch(c)};var r,n=(r=_$app_36)&&r.__esModule?r:{default:r};function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function a(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function s(t,e){var r=n.default.read(_$constants_41.SETTINGS_KEY);e.json(r)}function c(t,e){var r=t.body,o=n.default.read(_$constants_41.SETTINGS_KEY);n.default.write(i(i({},o),r),_$constants_41.SETTINGS_KEY),e.json({status:"success"})}})),_$collections_40=createModuleFactory((function(t,e){"use strict";function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.register=function(t){a.default.read(_$constants_41.COLLECTIONS_KEY)||a.default.write({},_$constants_41.COLLECTIONS_KEY),t.get("/download/collection/:name",p),t.route("/api/collection/:name").get(_).patch(y).delete(v),t.route("/api/collections").get(m).post(d)};var n,o=_$subscriptions_44({}),i=_$artifacts_39({}),a=(n=_$app_36)&&n.__esModule?n:{default:n};function s(){s=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(T){u=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var o=e&&e.prototype instanceof h?e:h,i=Object.create(o.prototype),a=new A(n||[]);return i._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=E(a,r);if(s){if(s===p)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,a),i}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(T){return{type:"throw",arg:T}}}t.wrap=f;var p={};function h(){}function d(){}function _(){}var y={};u(y,i,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(x([])));m&&m!==e&&n.call(m,i)&&(y=m);var g=_.prototype=h.prototype=Object.create(y);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var o;this._invoke=function(i,a){function s(){return new e((function(o,s){!function o(i,a,s,c){var u=l(t[i],t,a);if("throw"!==u.type){var f=u.arg,p=f.value;return p&&"object"==r(p)&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){o("next",t,s,c)}),(function(t){o("throw",t,s,c)})):e.resolve(p).then((function(t){f.value=t,s(f)}),(function(t){return o("throw",t,s,c)}))}c(u.arg)}(i,a,o,s)}))}return o=o?o.then(s,s):s()}}function E(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=l(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function S(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completiLine truncated
!function(){var createModuleFactory=function(t){var e;return function(r){return e||t(e={exports:{},parent:r},e.exports),e.exports}},_$buffer_2=createModuleFactory((function(t,e){(function(t){(function(){"use strict";e.Buffer=r,e.SlowBuffer=function(t){return+t!=t&&(t=0),r.alloc(+t)},e.INSPECT_MAX_BYTES=50;function t(t){if(t>2147483647)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return e.__proto__=r.prototype,e}function r(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return a(t)}return n(t,e,r)}function n(e,n,o){if("string"==typeof e)return function(e,n){if("string"==typeof n&&""!==n||(n="utf8"),!r.isEncoding(n))throw new TypeError("Unknown encoding: "+n);var o=0|c(e,n),a=t(o),i=a.write(e,n);return i!==o&&(a=a.slice(0,i)),a}(e,n);if(ArrayBuffer.isView(e))return i(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(N(e,ArrayBuffer)||e&&N(e.buffer,ArrayBuffer))return function(t,e,n){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(n||0))throw new RangeError('"length" is outside of buffer bounds');var o;return(o=void 0===e&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,e):new Uint8Array(t,e,n)).__proto__=r.prototype,o}(e,n,o);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var a=e.valueOf&&e.valueOf();if(null!=a&&a!==e)return r.from(a,n,o);var u=function(e){if(r.isBuffer(e)){var n=0|s(e.length),o=t(n);return 0===o.length||e.copy(o,0,0,n),o}return void 0!==e.length?"number"!=typeof e.length||j(e.length)?t(0):i(e):"Buffer"===e.type&&Array.isArray(e.data)?i(e.data):void 0}(e);if(u)return u;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return r.from(e[Symbol.toPrimitive]("string"),n,o);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function o(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function a(e){return o(e),t(e<0?0:0|s(e))}function i(e){for(var r=e.length<0?0:0|s(e.length),n=t(r),o=0;o<r;o+=1)n[o]=255&e[o];return n}function s(t){if(t>=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647..toString(16)+" bytes");return 0|t}function c(t,e){if(r.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||N(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var n=t.length,o=arguments.length>2&&!0===arguments[2];if(!o&&0===n)return 0;for(var a=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return k(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return P(t).length;default:if(a)return o?-1:k(t).length;e=(""+e).toLowerCase(),a=!0}}function u(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function p(t,e,n,o,a){if(0===t.length)return-1;if("string"==typeof n?(o=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),j(n=+n)&&(n=a?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(a)return-1;n=t.length-1}else if(n<0){if(!a)return-1;n=0}if("string"==typeof e&&(e=r.from(e,o)),r.isBuffer(e))return 0===e.length?-1:l(t,e,n,o,a);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?a?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):l(t,[e],n,o,a);throw new TypeError("val must be string, number or Buffer")}function l(t,e,r,n,o){var a,i=1,s=t.length,c=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;i=2,s/=2,c/=2,r/=2}function u(t,e){return 1===i?t[e]:t.readUInt16BE(e*i)}if(o){var p=-1;for(a=r;a<s;a++)if(u(t,a)===u(e,-1===p?0:a-p)){if(-1===p&&(p=a),a-p+1===c)return p*i}else-1!==p&&(a-=a-p),p=-1}else for(r+c>s&&(r=s-c),a=r;a>=0;a--){for(var l=!0,f=0;f<c;f++)if(u(t,a+f)!==u(e,f)){l=!1;break}if(l)return a}return-1}function f(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;var a=e.length;n>a/2&&(n=a/2);for(var i=0;i<n;++i){var s=parseInt(e.substr(2*i,2),16);if(j(s))return i;t[r+i]=s}return i}function _(t,e,r,n){return I(k(e,t.length-r),t,r,n)}function h(t,e,r,n){return I(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function d(t,e,r,n){return h(t,e,r,n)}function y(t,e,r,n){return I(P(e),t,r,n)}function m(t,e,r,n){return I(function(t,e){for(var r,n,o,a=[],i=0;i<t.length&&!((e-=2)<0);++i)n=(r=t.charCodeAt(i))>>8Line truncated