mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-12 04:59:03 +08:00
Fixed ESLint issues
This commit is contained in:
parent
3b70cc0bd8
commit
b56f17606e
@ -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;
|
||||
|
@ -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 };
|
||||
}
|
||||
|
@ -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 };
|
||||
|
@ -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);
|
||||
|
@ -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,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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
4
backend/sub-store.min.js
vendored
4
backend/sub-store.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user