From 30889f66456c073341ca0dbcb6d3e5e80b88a2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Fri, 15 Nov 2024 16:31:17 +0800 Subject: [PATCH] fix Style --- packages/core/index.js | 2 +- packages/core/src/config.js | 22 +-- packages/core/src/expose.js | 11 +- packages/core/src/index.js | 2 +- packages/core/src/merge.js | 4 +- packages/core/src/modules/index.js | 12 +- packages/core/src/modules/plugin/git/index.js | 1 + packages/core/src/modules/plugin/index.js | 10 +- .../core/src/modules/plugin/node/config.js | 2 +- .../core/src/modules/plugin/node/index.js | 9 +- .../core/src/modules/plugin/overwall/index.js | 4 +- .../core/src/modules/plugin/pip/config.js | 2 +- packages/core/src/modules/plugin/pip/index.js | 3 +- packages/core/src/modules/server/index.js | 8 +- packages/core/src/shell/index.js | 17 +- .../core/src/shell/scripts/enable-loopback.js | 6 +- .../src/shell/scripts/extra-path/index.js | 2 +- .../core/src/shell/scripts/get-npm-env.js | 8 +- .../core/src/shell/scripts/get-system-env.js | 6 +- .../core/src/shell/scripts/kill-by-port.js | 5 +- .../core/src/shell/scripts/set-npm-env.js | 6 +- .../core/src/shell/scripts/set-system-env.js | 6 +- .../shell/scripts/set-system-proxy/index.js | 25 ++- packages/core/src/shell/scripts/setup-ca.js | 15 +- packages/core/src/shell/shell.js | 17 +- packages/core/src/shell/test.js | 3 +- packages/core/src/status.js | 3 +- packages/core/src/utils/util.log.js | 9 +- packages/core/start/index.js | 2 +- packages/core/start/mitmproxy.js | 7 +- packages/core/start/user_config.json5 | 70 +++---- packages/core/test/httpsVerifyTest.js | 10 +- packages/core/test/regex.test.js | 4 +- packages/core/test/requestTest.js | 2 +- packages/gui/package.json | 2 +- packages/gui/pkg/after-all-artifact-build.js | 5 +- packages/gui/pkg/after-pack.js | 2 +- packages/gui/src/background.js | 19 +- packages/gui/src/background/powerMonitor.js | 2 +- packages/gui/src/bridge/api/backend.js | 26 ++- .../src/bridge/api/open-enable-loopback.js | 6 +- packages/gui/src/bridge/auto-start/backend.js | 3 +- packages/gui/src/bridge/auto-start/front.js | 1 - packages/gui/src/bridge/backend.js | 4 +- packages/gui/src/bridge/error/front.js | 7 +- .../gui/src/bridge/file-selector/backend.js | 6 +- .../gui/src/bridge/file-selector/front.js | 3 +- packages/gui/src/bridge/front.js | 7 +- packages/gui/src/bridge/mitmproxy.js | 10 +- packages/gui/src/bridge/on-close/front.js | 26 +-- packages/gui/src/bridge/tongji/backend.js | 8 +- packages/gui/src/bridge/tongji/front.js | 5 +- packages/gui/src/bridge/update/backend.js | 61 +++---- packages/gui/src/bridge/update/front.js | 74 ++++---- packages/gui/src/main.js | 10 +- packages/gui/src/utils/util.apppath.js | 3 +- packages/gui/src/utils/util.log.js | 9 +- .../gui/src/view/components/container.vue | 9 +- packages/gui/src/view/components/setup-ca.vue | 22 +-- packages/gui/src/view/mixins/plugin.js | 2 +- packages/gui/src/view/pages/index.vue | 105 ++++++----- packages/gui/src/view/pages/plugin/git.vue | 8 +- packages/gui/src/view/pages/plugin/node.vue | 40 ++-- .../gui/src/view/pages/plugin/overwall.vue | 22 +-- packages/gui/src/view/pages/plugin/pip.vue | 45 ++--- packages/gui/src/view/pages/proxy.vue | 42 ++--- packages/gui/src/view/pages/server.vue | 172 ++++++++++-------- packages/gui/src/view/pages/setting.vue | 42 +++-- packages/gui/src/view/router/index.js | 8 +- packages/gui/vue.config.js | 8 +- packages/mitmproxy/src/index.js | 11 +- packages/mitmproxy/src/lib/choice/index.js | 4 +- packages/mitmproxy/src/lib/dns/base.js | 6 +- packages/mitmproxy/src/lib/dns/https.js | 9 +- packages/mitmproxy/src/lib/dns/index.js | 4 +- packages/mitmproxy/src/lib/dns/ipaddress.js | 5 +- packages/mitmproxy/src/lib/dns/lookup.js | 1 - packages/mitmproxy/src/lib/dns/preset.js | 6 +- packages/mitmproxy/src/lib/dns/tls.js | 3 +- .../src/lib/interceptor/impl/req/abort.js | 4 +- .../src/lib/interceptor/impl/req/baiduOcr.js | 24 ++- .../src/lib/interceptor/impl/req/cacheReq.js | 8 +- .../src/lib/interceptor/impl/req/proxy.js | 14 +- .../interceptor/impl/req/requestReplace.js | 4 +- .../src/lib/interceptor/impl/res/cacheRes.js | 6 +- .../interceptor/impl/res/responseReplace.js | 7 +- .../src/lib/interceptor/impl/res/script.js | 18 +- packages/mitmproxy/src/lib/monkey/index.js | 11 +- .../mitmproxy/src/lib/proxy/common/config.js | 1 + .../mitmproxy/src/lib/proxy/common/util.js | 19 +- .../middleware/InsertScriptMiddleware.js | 9 +- .../src/lib/proxy/middleware/overwall.js | 27 +-- .../src/lib/proxy/middleware/source/pac.js | 2 +- .../proxy/mitmproxy/createConnectHandler.js | 7 +- .../proxy/mitmproxy/createFakeServerCenter.js | 3 +- .../proxy/mitmproxy/createRequestHandler.js | 29 +-- .../proxy/mitmproxy/createUpgradeHandler.js | 26 +-- .../src/lib/proxy/mitmproxy/dnsLookup.js | 18 +- .../src/lib/proxy/mitmproxy/index.js | 11 +- .../src/lib/proxy/tls/FakeServersCenter.js | 7 +- .../mitmproxy/src/lib/proxy/tls/sniUtil.js | 32 +++- .../mitmproxy/src/lib/proxy/tls/tlsUtils.js | 48 ++--- .../mitmproxy/src/lib/speed/SpeedTester.js | 7 +- packages/mitmproxy/src/lib/speed/index.js | 7 +- packages/mitmproxy/src/options.js | 15 +- packages/mitmproxy/src/utils/util.js | 1 + packages/mitmproxy/src/utils/util.log.js | 4 +- packages/mitmproxy/src/utils/util.match.js | 16 +- packages/mitmproxy/test/baiduOcrTest.js | 4 +- packages/mitmproxy/test/dnsSpeedTest.js | 6 +- .../mitmproxy/test/lib/monkey/indexTest.js | 1 + packages/mitmproxy/test/proxyTest.js | 6 +- packages/mitmproxy/test/sha256Test.js | 1 + test/test.js | 33 ++-- test/testDns.js | 2 +- 115 files changed, 876 insertions(+), 750 deletions(-) diff --git a/packages/core/index.js b/packages/core/index.js index 00a8ca7..c854160 100644 --- a/packages/core/index.js +++ b/packages/core/index.js @@ -3,5 +3,5 @@ module.exports = require('./src') // TODO 这是一个解谜游戏 ↓ ↓ ↓ ↓ ↓ ↓ ,如果你破解了它,请不要公开,好好用它来学习和查资料吧(特别注意:为了你的人身安全,请不要用它来查看和发表不当言论,你懂得)。 /** \u0061\u0048\u0052\u0030\u0063\u0044\u006f\u0076\u004c\u0032\u0052\u006c\u0064\u0069\u0031\u007a\u0061\u0057\u0052\u006c\u0059\u0032\u0046\u0079\u004c\u006d\u0052\u0076\u0059\u0032\u0031\u0070\u0063\u006e\u004a\u0076\u0063\u0069\u0035\u006a\u0062\u0069\u0039\u0035\u0062\u0033\u0056\u006d\u0061\u0057\u0035\u006b\u0061\u0058\u0051\u0076\u0061\u0057\u0035\u006b\u005a\u0058\u0067\u0075\u0061\u0048\u0052\u0074\u0062\u0041\u003d\u003d - **/ + */ // 这个项目里有一点点解谜提示: https://github.com/fast-crud/fast-crud (打开拉到最下面) diff --git a/packages/core/src/config.js b/packages/core/src/config.js index 5d5f714..4cbd74d 100644 --- a/packages/core/src/config.js +++ b/packages/core/src/config.js @@ -1,12 +1,12 @@ const fs = require('fs') -const Shell = require('./shell') -const lodash = require('lodash') -const defConfig = require('./config/index.js') -const jsonApi = require('@docmirror/mitmproxy/src/json') -const request = require('request') const path = require('path') -const log = require('./utils/util.log') +const jsonApi = require('@docmirror/mitmproxy/src/json') +const lodash = require('lodash') +const request = require('request') +const defConfig = require('./config/index.js') const mergeApi = require('./merge.js') +const Shell = require('./shell') +const log = require('./utils/util.log') let configTarget = lodash.cloneDeep(defConfig) @@ -80,7 +80,7 @@ const configApi = { configApi.deleteRemoteConfigFile(suffix) return } - // eslint-disable-next-line handle-callback-err + return new Promise((resolve, reject) => { log.info('开始下载远程配置:', remoteConfigUrl) @@ -131,7 +131,7 @@ const configApi = { if (response) { message = `下载远程配置失败: ${remoteConfigUrl}, message: ${response.message}, code: ${response.statusCode}` } else { - message = '下载远程配置失败: response: ' + response + message = `下载远程配置失败: response: ${response}` } reject(new Error(message)) } @@ -337,7 +337,7 @@ const configApi = { }, async setVariables (type) { const list = await configApi.getVariables(type) - const noSetList = list.filter(item => { + const noSetList = list.filter((item) => { return !item.exists }) if (list.length > 0) { @@ -345,9 +345,9 @@ const configApi = { root_ca_cert_path: configApi.get().server.setting.rootCaFile.certPath } for (const item of noSetList) { - if (item.value.indexOf('${') >= 0) { + if (item.value.includes('${')) { for (const key in context) { - item.value = item.value.replcace(new RegExp('${' + key + '}', 'g'), context[key]) + item.value = item.value.replcace(new RegExp(`\${${key}}`, 'g'), context[key]) } } } diff --git a/packages/core/src/expose.js b/packages/core/src/expose.js index 2f0c179..fb4587a 100644 --- a/packages/core/src/expose.js +++ b/packages/core/src/expose.js @@ -1,10 +1,11 @@ -const status = require('./status') +const lodash = require('lodash') const config = require('./config') const event = require('./event') -const shell = require('./shell') const modules = require('./modules') -const lodash = require('lodash') +const shell = require('./shell') +const status = require('./status') const log = require('./utils/util.log') + const context = { config, shell, @@ -29,14 +30,14 @@ const proxy = setupPlugin('proxy', modules.proxy, context, config) const plugin = {} for (const key in modules.plugin) { const target = modules.plugin[key] - const api = setupPlugin('plugin.' + key, target, context, config) + const api = setupPlugin(`plugin.${key}`, target, context, config) plugin[key] = api } config.resetDefault() const server = modules.server const serverStart = server.start -const newServerStart = ({ mitmproxyPath }) => { +function newServerStart ({ mitmproxyPath }) { return serverStart({ mitmproxyPath, plugins: plugin }) } server.start = newServerStart diff --git a/packages/core/src/index.js b/packages/core/src/index.js index fb4f7d9..4f31826 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -3,7 +3,7 @@ const log = require('./utils/util.log') // process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' // 避免异常崩溃 -process.on('uncaughtException', function (err) { +process.on('uncaughtException', (err) => { if (err.code === 'ECONNABORTED') { // console.error(err.errno) return diff --git a/packages/core/src/merge.js b/packages/core/src/merge.js index 3c7888d..2b6b75b 100644 --- a/packages/core/src/merge.js +++ b/packages/core/src/merge.js @@ -75,8 +75,8 @@ function deleteNullItems (target) { } module.exports = { - doMerge: function (oldObj, newObj) { - return lodash.mergeWith(oldObj, newObj, function (objValue, srcValue) { + doMerge (oldObj, newObj) { + return lodash.mergeWith(oldObj, newObj, (objValue, srcValue) => { if (lodash.isArray(objValue)) { return srcValue } diff --git a/packages/core/src/modules/index.js b/packages/core/src/modules/index.js index e9036fe..a58c4dc 100644 --- a/packages/core/src/modules/index.js +++ b/packages/core/src/modules/index.js @@ -1,11 +1,5 @@ -const server = require('./server') - -const proxy = require('./proxy') - -const plugin = require('./plugin') - module.exports = { - server, - proxy, - plugin + server: require('./server'), + proxy: require('./proxy'), + plugin: require('./plugin') } diff --git a/packages/core/src/modules/plugin/git/index.js b/packages/core/src/modules/plugin/git/index.js index 144fd22..ba1bae7 100644 --- a/packages/core/src/modules/plugin/git/index.js +++ b/packages/core/src/modules/plugin/git/index.js @@ -1,4 +1,5 @@ const pluginConfig = require('./config') + const Plugin = function (context) { const { config, shell, event, log } = context const pluginApi = { diff --git a/packages/core/src/modules/plugin/index.js b/packages/core/src/modules/plugin/index.js index 3b1058e..6a2d246 100644 --- a/packages/core/src/modules/plugin/index.js +++ b/packages/core/src/modules/plugin/index.js @@ -1,8 +1,6 @@ -const node = require('./node') -const git = require('./git') -const overwall = require('./overwall') -const pip = require('./pip') - module.exports = { - node, git, pip, overwall + node: require('./node'), + git: require('./git'), + pip: require('./pip'), + overwall: require('./overwall') } diff --git a/packages/core/src/modules/plugin/node/config.js b/packages/core/src/modules/plugin/node/config.js index 0911467..6dc0544 100644 --- a/packages/core/src/modules/plugin/node/config.js +++ b/packages/core/src/modules/plugin/node/config.js @@ -11,7 +11,7 @@ module.exports = { cafile: false, NODE_EXTRA_CA_CERTS: false, NODE_TLS_REJECT_UNAUTHORIZED: false, - yarnRegistry: 'null', + yarnRegistry: 'default', registry: 'https://registry.npmjs.org'// 可以选择切换官方或者淘宝镜像 }, // intercepts: { diff --git a/packages/core/src/modules/plugin/node/index.js b/packages/core/src/modules/plugin/node/index.js index 98b84d1..7ae63a6 100644 --- a/packages/core/src/modules/plugin/node/index.js +++ b/packages/core/src/modules/plugin/node/index.js @@ -1,5 +1,6 @@ -const nodeConfig = require('./config') const jsonApi = require('@docmirror/mitmproxy/src/json') +const nodeConfig = require('./config') + const NodePlugin = function (context) { const { config, shell, event, log } = context const nodeApi = { @@ -44,7 +45,7 @@ const NodePlugin = function (context) { const cmds = [] for (const item of list) { - if (item.value != null && item.value.length > 0 && item.value !== 'null') { + if (item.value != null && item.value.length > 0 && item.value !== 'default' && item.value !== 'null') { cmds.push(`${command} config set ${item.key} ${item.value}`) } else { cmds.push(`${command} config delete ${item.key}`) @@ -67,7 +68,7 @@ const NodePlugin = function (context) { const cmds = [] log.debug('yarn set:', JSON.stringify(list)) for (const item of list) { - if (item.value != null && item.value.length > 0 && item.value !== 'null') { + if (item.value != null && item.value.length > 0 && item.value !== 'default' && item.value !== 'null') { cmds.push(`yarn config set ${item.key} ${item.value}`) } else { cmds.push(`yarn config delete ${item.key}`) @@ -103,7 +104,7 @@ const NodePlugin = function (context) { async setVariables () { const list = await nodeApi.getVariables() - const noSetList = list.filter(item => { + const noSetList = list.filter((item) => { return !item.exists }) if (noSetList.length > 0) { diff --git a/packages/core/src/modules/plugin/overwall/index.js b/packages/core/src/modules/plugin/overwall/index.js index f2796d8..ad56754 100644 --- a/packages/core/src/modules/plugin/overwall/index.js +++ b/packages/core/src/modules/plugin/overwall/index.js @@ -36,14 +36,12 @@ const Plugin = function (context) { for (const key in conf.targets) { serverConfig.intercepts[key] = { '.*': { - // eslint-disable-next-line no-template-curly-in-string - proxy: main + '/${host}', + proxy: `${main}/\${host}`, backup } } } } - } return api } diff --git a/packages/core/src/modules/plugin/pip/config.js b/packages/core/src/modules/plugin/pip/config.js index d065738..6e3d0b3 100644 --- a/packages/core/src/modules/plugin/pip/config.js +++ b/packages/core/src/modules/plugin/pip/config.js @@ -8,6 +8,6 @@ module.exports = { setting: { command: 'pip', trustedHost: 'pypi.org', - registry: 'https://pypi.org/simple/'// 可以选择切换官方或者淘宝镜像 + registry: 'https://pypi.org/simple/' // 可以选择切换官方或者淘宝镜像 } } diff --git a/packages/core/src/modules/plugin/pip/index.js b/packages/core/src/modules/plugin/pip/index.js index ea3fe13..ef58cbd 100644 --- a/packages/core/src/modules/plugin/pip/index.js +++ b/packages/core/src/modules/plugin/pip/index.js @@ -1,4 +1,5 @@ const pipConfig = require('./config') + const PipPlugin = function (context) { const { config, shell, event, log } = context const api = { @@ -20,7 +21,7 @@ const PipPlugin = function (context) { }, async getPipEnv () { const command = config.get().plugin.pip.setting.command - let ret = await shell.exec([command + ' config list'], { type: 'cmd' }) + let ret = await shell.exec([`${command} config list`], { type: 'cmd' }) if (ret != null) { ret = ret.trim() const lines = ret.split('\n') diff --git a/packages/core/src/modules/server/index.js b/packages/core/src/modules/server/index.js index 70ca0a2..92e81c3 100644 --- a/packages/core/src/modules/server/index.js +++ b/packages/core/src/modules/server/index.js @@ -1,19 +1,19 @@ +const lodash = require('lodash') const config = require('../../config') const event = require('../../event') const status = require('../../status') -const lodash = require('lodash') const fork = require('child_process').fork -const log = require('../../utils/util.log') const fs = require('fs') const path = require('path') const jsonApi = require('@docmirror/mitmproxy/src/json') +const log = require('../../utils/util.log') let server = null function fireStatus (status) { event.fire('status', { key: 'server.enabled', value: status }) } function sleep (time) { - return new Promise(resolve => { + return new Promise((resolve) => { setTimeout(() => { resolve() }, time) @@ -98,7 +98,7 @@ const serverApi = { serverProcess.on('uncaughtException', (err, origin) => { log.error('server process uncaughtException:', err) }) - serverProcess.on('message', function (msg) { + serverProcess.on('message', (msg) => { log.info('收到子进程消息:', JSON.stringify(msg)) if (msg.type === 'status') { fireStatus(msg.event) diff --git a/packages/core/src/shell/index.js b/packages/core/src/shell/index.js index 41355c0..887361f 100644 --- a/packages/core/src/shell/index.js +++ b/packages/core/src/shell/index.js @@ -1,13 +1,14 @@ -const shell = require('./shell') -const killByPort = require('./scripts/kill-by-port') -const setupCa = require('./scripts/setup-ca') -const getSystemEnv = require('./scripts/get-system-env') -const setSystemEnv = require('./scripts/set-system-env') -const getNpmEnv = require('./scripts/get-npm-env') -const setNpmEnv = require('./scripts/set-npm-env') -const setSystemProxy = require('./scripts/set-system-proxy/index') const enableLoopback = require('./scripts/enable-loopback') const extraPath = require('./scripts/extra-path') +const getNpmEnv = require('./scripts/get-npm-env') +const getSystemEnv = require('./scripts/get-system-env') +const killByPort = require('./scripts/kill-by-port') +const setNpmEnv = require('./scripts/set-npm-env') +const setSystemEnv = require('./scripts/set-system-env') +const setSystemProxy = require('./scripts/set-system-proxy/index') +const setupCa = require('./scripts/setup-ca') +const shell = require('./shell') + module.exports = { killByPort, setupCa, diff --git a/packages/core/src/shell/scripts/enable-loopback.js b/packages/core/src/shell/scripts/enable-loopback.js index 42d380d..17310b0 100644 --- a/packages/core/src/shell/scripts/enable-loopback.js +++ b/packages/core/src/shell/scripts/enable-loopback.js @@ -2,7 +2,9 @@ */ const Shell = require('../shell') const extraPath = require('./extra-path') + const execute = Shell.execute + const executor = { async windows (exec) { const loopbackPath = extraPath.getEnableLoopbackPath() @@ -10,10 +12,10 @@ const executor = { await execFile(loopbackPath) }, async linux (exec, { port }) { - throw Error('不支持此操作') + throw new Error('不支持此操作') }, async mac (exec, { port }) { - throw Error('不支持此操作') + throw new Error('不支持此操作') } } diff --git a/packages/core/src/shell/scripts/extra-path/index.js b/packages/core/src/shell/scripts/extra-path/index.js index 959d440..7828450 100644 --- a/packages/core/src/shell/scripts/extra-path/index.js +++ b/packages/core/src/shell/scripts/extra-path/index.js @@ -1,5 +1,5 @@ -const log = require('../../../utils/util.log') const path = require('path') +const log = require('../../../utils/util.log') function getExtraPath () { let extraPath = process.env.DS_EXTRA_PATH diff --git a/packages/core/src/shell/scripts/get-npm-env.js b/packages/core/src/shell/scripts/get-npm-env.js index fcb7833..c78c931 100644 --- a/packages/core/src/shell/scripts/get-npm-env.js +++ b/packages/core/src/shell/scripts/get-npm-env.js @@ -1,9 +1,11 @@ /** * 获取环境变量 */ -const Shell = require('../shell') const jsonApi = require('@docmirror/mitmproxy/src/json') +const Shell = require('../shell') + const execute = Shell.execute + const executor = { async windows (exec) { const ret = await exec(['npm config list --json'], { type: 'cmd' }) @@ -14,10 +16,10 @@ const executor = { return {} }, async linux (exec, { port }) { - throw Error('暂未实现此功能') + throw new Error('暂未实现此功能') }, async mac (exec, { port }) { - throw Error('暂未实现此功能') + throw new Error('暂未实现此功能') } } diff --git a/packages/core/src/shell/scripts/get-system-env.js b/packages/core/src/shell/scripts/get-system-env.js index 849ffb7..f6699c4 100644 --- a/packages/core/src/shell/scripts/get-system-env.js +++ b/packages/core/src/shell/scripts/get-system-env.js @@ -2,7 +2,9 @@ * 获取环境变量 */ const Shell = require('../shell') + const execute = Shell.execute + const executor = { async windows (exec) { const ret = await exec(['set'], { type: 'cmd' }) @@ -19,10 +21,10 @@ const executor = { return map }, async linux (exec, { port }) { - throw Error('暂未实现此功能') + throw new Error('暂未实现此功能') }, async mac (exec, { port }) { - throw Error('暂未实现此功能') + throw new Error('暂未实现此功能') } } diff --git a/packages/core/src/shell/scripts/kill-by-port.js b/packages/core/src/shell/scripts/kill-by-port.js index 1fb687e..af081b3 100644 --- a/packages/core/src/shell/scripts/kill-by-port.js +++ b/packages/core/src/shell/scripts/kill-by-port.js @@ -1,4 +1,5 @@ const Shell = require('../shell') + const execute = Shell.execute const executor = { @@ -9,11 +10,11 @@ const executor = { return true }, async linux (exec, { port }) { - await exec('kill `lsof -i:' + port + " |grep 'dev-sidecar\\|electron\\|@docmirro' |awk '{print $2}'`") + await exec(`kill \`lsof -i:${port} |grep 'dev-sidecar\\|electron\\|@docmirro' |awk '{print $2}'\``) return true }, async mac (exec, { port }) { - await exec('kill `lsof -i:' + port + " |grep 'dev-side\\|Elect' |awk '{print $2}'`") + await exec(`kill \`lsof -i:${port} |grep 'dev-side\\|Elect' |awk '{print $2}'\``) return true } } diff --git a/packages/core/src/shell/scripts/set-npm-env.js b/packages/core/src/shell/scripts/set-npm-env.js index daef7f8..f34120f 100644 --- a/packages/core/src/shell/scripts/set-npm-env.js +++ b/packages/core/src/shell/scripts/set-npm-env.js @@ -2,7 +2,9 @@ * 设置环境变量 */ const Shell = require('../shell') + const execute = Shell.execute + const executor = { async windows (exec, { list }) { const cmds = [] @@ -13,10 +15,10 @@ const executor = { return ret }, async linux (exec, { port }) { - throw Error('暂未实现此功能') + throw new Error('暂未实现此功能') }, async mac (exec, { port }) { - throw Error('暂未实现此功能') + throw new Error('暂未实现此功能') } } diff --git a/packages/core/src/shell/scripts/set-system-env.js b/packages/core/src/shell/scripts/set-system-env.js index 37179ff..ec94f29 100644 --- a/packages/core/src/shell/scripts/set-system-env.js +++ b/packages/core/src/shell/scripts/set-system-env.js @@ -2,7 +2,9 @@ * 设置环境变量 */ const Shell = require('../shell') + const execute = Shell.execute + const executor = { async windows (exec, { list }) { const cmds = [] @@ -22,10 +24,10 @@ const executor = { return ret }, async linux (exec, { port }) { - throw Error('暂未实现此功能') + throw new Error('暂未实现此功能') }, async mac (exec, { port }) { - throw Error('暂未实现此功能') + throw new Error('暂未实现此功能') } } diff --git a/packages/core/src/shell/scripts/set-system-proxy/index.js b/packages/core/src/shell/scripts/set-system-proxy/index.js index 52caed8..27f6cb8 100644 --- a/packages/core/src/shell/scripts/set-system-proxy/index.js +++ b/packages/core/src/shell/scripts/set-system-proxy/index.js @@ -1,16 +1,16 @@ /** * 获取环境变量 */ -const Shell = require('../../shell') const Registry = require('winreg') - -const execute = Shell.execute -const execFile = Shell.execFile -const log = require('../../../utils/util.log') -const extraPath = require('../extra-path/index') +const Shell = require('../../shell') const fs = require('fs') const path = require('path') const request = require('request') +const log = require('../../../utils/util.log') +const extraPath = require('../extra-path/index') + +const execute = Shell.execute +const execFile = Shell.execFile let config = null function loadConfig () { @@ -20,7 +20,6 @@ function loadConfig () { } async function _winUnsetProxy (exec, setEnv) { - // eslint-disable-next-line no-constant-condition const proxyPath = extraPath.getProxyExePath() await execFile(proxyPath, ['set', '1']) @@ -74,12 +73,12 @@ async function downloadDomesticDomainAllowListAsync () { let fileTxt = body try { - if (fileTxt.indexOf('*.') < 0) { + if (!fileTxt.includes('*.')) { fileTxt = Buffer.from(fileTxt, 'base64').toString('utf8') // log.debug('解析 base64 后的 domestic-domain-allowlist:', fileTxt) } } catch (e) { - if (fileTxt.indexOf('*.') < 0) { + if (!fileTxt.includes('*.')) { log.error(`远程 domestic-domain-allowlist.txt 文件内容即不是base64格式,也不是要求的格式,url: ${remoteFileUrl},body: ${body}`) return } @@ -195,7 +194,7 @@ function getProxyExcludeIpStr (split) { try { let domesticDomainAllowList = getDomesticDomainAllowList() if (domesticDomainAllowList) { - domesticDomainAllowList = (domesticDomainAllowList + '\n').replaceAll(/[\r\n]+/g, '\n').replaceAll(/[^\n]*[^*.a-zA-Z\d-\n]+[^\n]*\r?\n/g, '').trim().replaceAll(/\s*\n+\s*/g, split) + domesticDomainAllowList = (`${domesticDomainAllowList}\n`).replaceAll(/[\r\n]+/g, '\n').replaceAll(/[\d*\-.A-Z]*[^\d\n*\-.A-Z][^\n]*\n/gi, '').trim().replaceAll(/\s*\n\s*/g, split) if (domesticDomainAllowList) { excludeIpStr += domesticDomainAllowList log.info('系统代理排除列表拼接国内域名') @@ -224,7 +223,7 @@ async function _winSetProxy (exec, ip, port, setEnv) { let proxyAddr = `https=http://${ip}:${port}` // http if (config.get().proxy.proxyHttp) { - proxyAddr = `http=http://${ip}:${port - 1};` + proxyAddr + proxyAddr = `http=http://${ip}:${port - 1};${proxyAddr}` } // 读取排除域名 @@ -283,12 +282,12 @@ const executor = { setProxyCmd.push(`gsettings set org.gnome.system.proxy.http host ${ip}`) setProxyCmd.push(`gsettings set org.gnome.system.proxy.http port ${port - 1}`) } else { - setProxyCmd.push("gsettings set org.gnome.system.proxy.http host ''") + setProxyCmd.push('gsettings set org.gnome.system.proxy.http host \'\'') setProxyCmd.push('gsettings set org.gnome.system.proxy.http port 0') } // 设置排除域名(ignore-hosts) - const excludeIpStr = getProxyExcludeIpStr("', '") + const excludeIpStr = getProxyExcludeIpStr('\', \'') setProxyCmd.push(`gsettings set org.gnome.system.proxy ignore-hosts "['${excludeIpStr}']"`) await exec(setProxyCmd) diff --git a/packages/core/src/shell/scripts/setup-ca.js b/packages/core/src/shell/scripts/setup-ca.js index 4af30f4..5b28cd3 100644 --- a/packages/core/src/shell/scripts/setup-ca.js +++ b/packages/core/src/shell/scripts/setup-ca.js @@ -1,22 +1,21 @@ const Shell = require('../shell') + const execute = Shell.execute + const executor = { async windows (exec, { certPath }) { - const cmds = ['start "" "' + certPath + '"'] - // eslint-disable-next-line no-unused-vars - const ret = await exec(cmds, { type: 'cmd' }) + const cmds = [`start "" "${certPath}"`] + await exec(cmds, { type: 'cmd' }) return true }, async linux (exec, { certPath }) { const cmds = [`sudo cp ${certPath} /usr/local/share/ca-certificates`, 'sudo update-ca-certificates '] - // eslint-disable-next-line no-unused-vars - const ret = await exec(cmds) + await exec(cmds) return true }, async mac (exec, { certPath }) { - const cmds = ['open "' + certPath + '"'] - // eslint-disable-next-line no-unused-vars - const ret = await exec(cmds, { type: 'cmd' }) + const cmds = [`open "${certPath}"`] + await exec(cmds, { type: 'cmd' }) return true } } diff --git a/packages/core/src/shell/shell.js b/packages/core/src/shell/shell.js index f421df1..95f3b96 100644 --- a/packages/core/src/shell/shell.js +++ b/packages/core/src/shell/shell.js @@ -1,11 +1,14 @@ -const os = require('os') const childProcess = require('child_process') -const _execFile = childProcess.execFile -const PowerShell = require('node-powershell') -const log = require('../utils/util.log') +const os = require('os') const fixPath = require('fix-path') const iconv = require('iconv-lite') +const PowerShell = require('node-powershell') +const log = require('../utils/util.log') + +const _execFile = childProcess.execFile + fixPath() + class SystemShell { static async exec (cmds, args) { throw new Error('You have to implement the method exec!') @@ -63,7 +66,7 @@ class WindowsSystemShell extends SystemShell { } else { let compose = 'echo "test" ' // 'chcp 65001 ' for (const cmd of cmds) { - compose += ' && ' + cmd + compose += ` && ${cmd}` } // compose += '&& exit' const ret = await childExec(compose, args) @@ -77,7 +80,7 @@ function _childExec (composeCmds, options = {}) { return new Promise((resolve, reject) => { const childProcess = require('child_process') log.info('shell:', composeCmds) - childProcess.exec(composeCmds, options, function (error, stdout, stderr) { + childProcess.exec(composeCmds, options, (error, stdout, stderr) => { if (error) { if (options.printErrorLog !== false) { log.error('cmd 命令执行错误:\n===>\ncommands:', composeCmds, '\n error:', error, '\n<===') @@ -100,7 +103,7 @@ function childExec (composeCmds, options = {}) { const childProcess = require('child_process') log.info('shell:', composeCmds) - childProcess.exec(composeCmds, { encoding: binaryEncoding }, function (error, stdout, stderr) { + childProcess.exec(composeCmds, { encoding: binaryEncoding }, (error, stdout, stderr) => { if (error) { // console.log('------', decoder.decode(stderr)) const message = iconv.decode(Buffer.from(stderr, binaryEncoding), encoding) diff --git a/packages/core/src/shell/test.js b/packages/core/src/shell/test.js index 47b9320..a1623ed 100644 --- a/packages/core/src/shell/test.js +++ b/packages/core/src/shell/test.js @@ -34,8 +34,9 @@ // console.error(e) // }) -const request = require('request') const fs = require('fs') +const request = require('request') + request({ url: 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', proxy: 'http://127.0.0.1:31181', diff --git a/packages/core/src/status.js b/packages/core/src/status.js index 62d1a12..362a0dd 100644 --- a/packages/core/src/status.js +++ b/packages/core/src/status.js @@ -1,6 +1,7 @@ -const event = require('./event') const lodash = require('lodash') +const event = require('./event') const log = require('./utils/util.log') + const status = { server: { enabled: false }, proxy: {}, diff --git a/packages/core/src/utils/util.log.js b/packages/core/src/utils/util.log.js index bec2ef1..fc6cc28 100644 --- a/packages/core/src/utils/util.log.js +++ b/packages/core/src/utils/util.log.js @@ -1,14 +1,17 @@ +const path = require('path') const log4js = require('log4js') const config = require('../config/index') + +const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' + function getDefaultConfigBasePath () { return config.server.setting.userBasePath } -const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' -const path = require('path') + const filename = path.join(getDefaultConfigBasePath(), '/logs/core.log') log4js.configure({ appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } }, - categories: { default: { appenders: ['file', 'std'], level: level } } + categories: { default: { appenders: ['file', 'std'], level } } }) const logger = log4js.getLogger('core') module.exports = logger diff --git a/packages/core/start/index.js b/packages/core/start/index.js index 0b4b1cd..b41aaae 100644 --- a/packages/core/start/index.js +++ b/packages/core/start/index.js @@ -1,6 +1,6 @@ +const fs = require('fs') const jsonApi = require('@docmirror/mitmproxy/src/json') const DevSidecar = require('../index') -const fs = require('fs') const log = require('../src/utils/util.log') // 启动服务 diff --git a/packages/core/start/mitmproxy.js b/packages/core/start/mitmproxy.js index 0c48a7e..57cbe5d 100644 --- a/packages/core/start/mitmproxy.js +++ b/packages/core/start/mitmproxy.js @@ -1,9 +1,11 @@ +const fs = require('fs') +const path = require('path') const server = require('@docmirror/mitmproxy') const jsonApi = require('@docmirror/mitmproxy/src/json') -const path = require('path') -const home = process.env.USER_HOME || process.env.HOME || 'C:/Users/Administrator/' const log = require('../src/utils/util.log') +const home = process.env.USER_HOME || process.env.HOME || 'C:/Users/Administrator/' + let configPath if (process.argv && process.argv.length > 3) { configPath = process.argv[2] @@ -11,7 +13,6 @@ if (process.argv && process.argv.length > 3) { configPath = path.join(home, '.dev-sidecar/running.json') } -const fs = require('fs') const configJson = fs.readFileSync(configPath) log.info('读取 running.json by core 成功:', configPath) const config = jsonApi.parse(configJson.toString()) diff --git a/packages/core/start/user_config.json5 b/packages/core/start/user_config.json5 index d257846..56afb1f 100644 --- a/packages/core/start/user_config.json5 +++ b/packages/core/start/user_config.json5 @@ -1,42 +1,42 @@ { - app: { - autoStart: { - enabled: true, + "app": { + "autoStart": { + "enabled": true }, - mode: 'default', + "mode": "default" }, - plugin: { - node: { - setting: { - yarnRegistry: 'null', - }, - }, - git: { - enabled: true, - }, - overwall: { - enabled: false, - targets: { - '*gagedigital.com': true, - '*yonsz.net': true, - '*bootstrapcdn.com': true, - '*cloudflare.com': true, - 'help.yonsz.net': true, - }, - }, - }, - server: { - intercepts: { - 'dev-sidecar.docmirror.cn': { - '.*': { - proxy: 'dev-sidecar-preview.docmirror.cn', - }, - }, - 'test1111.gagedigital.com': { - '.*': { - proxy: 'test1.gagedigital.com', - }, + "plugin": { + "node": { + "setting": { + "yarnRegistry": "null" } }, + "git": { + "enabled": true + }, + "overwall": { + "enabled": false, + "targets": { + "*gagedigital.com": true, + "*yonsz.net": true, + "*bootstrapcdn.com": true, + "*cloudflare.com": true, + "help.yonsz.net": true + } + } + }, + "server": { + "intercepts": { + "dev-sidecar.docmirror.cn": { + ".*": { + "proxy": "dev-sidecar-preview.docmirror.cn" + } + }, + "test1111.gagedigital.com": { + ".*": { + "proxy": "test1.gagedigital.com" + } + } + } } } diff --git a/packages/core/test/httpsVerifyTest.js b/packages/core/test/httpsVerifyTest.js index f2305b4..8f59f7d 100644 --- a/packages/core/test/httpsVerifyTest.js +++ b/packages/core/test/httpsVerifyTest.js @@ -1,5 +1,7 @@ const https = require('https') + process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1' + function request () { return new Promise((resolve, reject) => { const options = { @@ -28,12 +30,12 @@ function request () { }) } // eslint-disable-next-line no-undef -describe('ssl.verify', function () { +describe('ssl.verify', () => { // eslint-disable-next-line no-undef - it('regex.test.js', async function () { - // https.request('https://test1.gagedigital.com/ssltest.php') + it('regex.test.js', async () => { + // https.request('https://test1.gagedigital.com/ssltest.php') await request() - // eslint-disable-next-line no-unused-expressions + // expect(ret).be.ok }) }) diff --git a/packages/core/test/regex.test.js b/packages/core/test/regex.test.js index 83403ff..b616216 100644 --- a/packages/core/test/regex.test.js +++ b/packages/core/test/regex.test.js @@ -1,8 +1,8 @@ const expect = require('chai').expect // eslint-disable-next-line no-undef -describe('test', function () { +describe('test', () => { // eslint-disable-next-line no-undef - it('regexp', function () { + it('regexp', () => { const test = '^/[^/]+/[^/]+(/releases(/.*)?)?$' const reg = new RegExp(test) diff --git a/packages/core/test/requestTest.js b/packages/core/test/requestTest.js index d2914af..6f8777d 100644 --- a/packages/core/test/requestTest.js +++ b/packages/core/test/requestTest.js @@ -1,5 +1,5 @@ -const request = require('request') const HttpsAgent = require('@docmirror/mitmproxy/src/lib/proxy/common/ProxyHttpsAgent') +const request = require('request') const options = { url: 'https://raw.githubusercontent.com/docmirror/dev-sidecar/refs/heads/master/packages/core/src/config/remote_config.json5', diff --git a/packages/gui/package.json b/packages/gui/package.json index 464917a..c897fca 100644 --- a/packages/gui/package.json +++ b/packages/gui/package.json @@ -24,7 +24,7 @@ "@docmirror/dev-sidecar": "^1.8.9", "@docmirror/mitmproxy": "^1.8.9", "@mihomo-party/sysproxy": "^2.0.4", - "@natmri/platform-napi": "^0.0.8", + "@natmri/platform-napi": "^0.0.7", "adm-zip": "^0.5.5", "ant-design-vue": "^1.6.5", "compressing": "^1.5.1", diff --git a/packages/gui/pkg/after-all-artifact-build.js b/packages/gui/pkg/after-all-artifact-build.js index e821c4c..9c61f50 100644 --- a/packages/gui/pkg/after-all-artifact-build.js +++ b/packages/gui/pkg/after-all-artifact-build.js @@ -1,6 +1,6 @@ +const fs = require('fs') const path = require('path') const pkg = require('../package.json') -const fs = require('fs') function appendIntro (context, systemType, latest) { const version = pkg.version @@ -14,8 +14,7 @@ partMiniVersion: 1.7.0 releaseNotes: - 升级日志 - https://download.fastgit.org/docmirror/dev-sidecar/releases/download/v${version}/DevSidecar-${version}.exe -`, - (err) => { +`, (err) => { if (err) { console.log('修改latest 失败') } diff --git a/packages/gui/pkg/after-pack.js b/packages/gui/pkg/after-pack.js index d312c9c..4855117 100644 --- a/packages/gui/pkg/after-pack.js +++ b/packages/gui/pkg/after-pack.js @@ -1,7 +1,7 @@ +const fs = require('fs') const path = require('path') const AdmZip = require('adm-zip') const pkg = require('../package.json') -const fs = require('fs') function writeAppUpdateYmlForLinux () { const publishUrl = process.env.VUE_APP_PUBLISH_URL diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js index b572d6c..16a08e4 100644 --- a/packages/gui/src/background.js +++ b/packages/gui/src/background.js @@ -1,17 +1,15 @@ 'use strict' /* global __static */ import path from 'path' -import { app, protocol, BrowserWindow, Menu, Tray, ipcMain, dialog, powerMonitor, nativeImage, nativeTheme, globalShortcut } from 'electron' +import DevSidecar from '@docmirror/dev-sidecar' +import { app, BrowserWindow, dialog, globalShortcut, ipcMain, Menu, nativeImage, nativeTheme, powerMonitor, protocol, Tray } from 'electron' +import minimist from 'minimist' import { createProtocol } from 'vue-cli-plugin-electron-builder/lib' import backend from './bridge/backend' -import DevSidecar from '@docmirror/dev-sidecar' import log from './utils/util.log' -import minimist from 'minimist' const isWindows = process.platform === 'win32' -// eslint-disable-next-line no-unused-vars const isMac = process.platform === 'darwin' -// import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer' const isDevelopment = process.env.NODE_ENV !== 'production' // 避免其他系统出现异常,只有 Windows 使用 './background/powerMonitor' @@ -21,7 +19,7 @@ const _powerMonitor = isWindows ? require('./background/powerMonitor').powerMoni // be closed automatically when the JavaScript object is garbage collected. let win let winIsHidden = false -// eslint-disable-next-line no-unused-vars + let tray // 防止被内存清理 let forceClose = false DevSidecar.api.config.reload() @@ -123,8 +121,8 @@ function setTray () { showWin() }) - appTray.on('right-click', function () { - setTimeout(function () { + appTray.on('right-click', () => { + setTimeout(() => { appTray.popUpContextMenu(contextMenu) }, 200) }) @@ -184,7 +182,6 @@ function createWindow (startHideWindow) { nodeIntegration: true// process.env.ELECTRON_NODE_INTEGRATION }, show: !startHideWindow, - // eslint-disable-next-line no-undef icon: path.join(__static, 'icon.png') }) winIsHidden = !!startHideWindow @@ -368,7 +365,7 @@ if (app.getLoginItemSettings().wasOpenedAsHidden) { log.info('start args:', args) // 通过启动参数,判断是否隐藏窗口 - const hideWindowArg = args.hideWindow + '' + const hideWindowArg = `${args.hideWindow}` if (hideWindowArg === 'true' || hideWindowArg === '1') { startHideWindow = true } else if (hideWindowArg === 'false' || hideWindowArg === '0') { @@ -483,7 +480,7 @@ if (isDevelopment) { } } // 系统关机和重启时的操作 -process.on('exit', function () { +process.on('exit', () => { log.info('进程结束,退出app') quit() }) diff --git a/packages/gui/src/background/powerMonitor.js b/packages/gui/src/background/powerMonitor.js index dd8b9ac..5c20fca 100644 --- a/packages/gui/src/background/powerMonitor.js +++ b/packages/gui/src/background/powerMonitor.js @@ -1,5 +1,5 @@ +import { acquireShutdownBlock, insertWndProcHook, releaseShutdownBlock, removeWndProcHook, setMainWindowHandle } from '@natmri/platform-napi' import { powerMonitor as _powerMonitor } from 'electron' -import { setMainWindowHandle, insertWndProcHook, removeWndProcHook, releaseShutdownBlock, acquireShutdownBlock } from '@natmri/platform-napi' class PowerMonitor { constructor () { diff --git a/packages/gui/src/bridge/api/backend.js b/packages/gui/src/bridge/api/backend.js index d1d3ab2..703a470 100644 --- a/packages/gui/src/bridge/api/backend.js +++ b/packages/gui/src/bridge/api/backend.js @@ -1,14 +1,16 @@ -import lodash from 'lodash' -import DevSidecar from '@docmirror/dev-sidecar' -import { ipcMain } from 'electron' import fs from 'fs' import path from 'path' +import DevSidecar from '@docmirror/dev-sidecar' +import { ipcMain } from 'electron' +import lodash from 'lodash' + const pk = require('../../../package.json') -const mitmproxyPath = path.join(__dirname, 'mitmproxy.js') -process.env.DS_EXTRA_PATH = path.join(__dirname, '../extra/') const jsonApi = require('@docmirror/mitmproxy/src/json') const log = require('../../utils/util.log') +const mitmproxyPath = path.join(__dirname, 'mitmproxy.js') +process.env.DS_EXTRA_PATH = path.join(__dirname, '../extra/') + const getDefaultConfigBasePath = function () { return DevSidecar.api.config.get().server.setting.userBasePath } @@ -129,7 +131,7 @@ function _deepFindFunction (list, parent, parentKey) { if (item instanceof Function) { list.push(parentKey + key) } else if (item instanceof Object) { - _deepFindFunction(list, item, parentKey + key + '.') + _deepFindFunction(list, item, `${parentKey + key}.`) } } } @@ -184,14 +186,20 @@ export default { // 注册从core里来的事件,并转发给view DevSidecar.api.event.register('status', (event) => { log.info('bridge on status, event:', event) - if (win) win.webContents.send('status', { ...event }) + if (win) { + win.webContents.send('status', { ...event }) + } }) DevSidecar.api.event.register('error', (event) => { log.error('bridge on error, event:', event) - if (win) win.webContents.send('error.core', event) + if (win) { + win.webContents.send('error.core', event) + } }) DevSidecar.api.event.register('speed', (event) => { - if (win) win.webContents.send('speed', event) + if (win) { + win.webContents.send('speed', event) + } }) // 合并用户配置 diff --git a/packages/gui/src/bridge/api/open-enable-loopback.js b/packages/gui/src/bridge/api/open-enable-loopback.js index 666aa8d..dc9ef06 100644 --- a/packages/gui/src/bridge/api/open-enable-loopback.js +++ b/packages/gui/src/bridge/api/open-enable-loopback.js @@ -1,12 +1,14 @@ -import Sudoer from 'electron-sudo' import DevSidecar from '@docmirror/dev-sidecar' +import Sudoer from 'electron-sudo' + export default { async open () { const options = { name: '设置loopback' } const sudoer = new Sudoer(options) const exeFile = DevSidecar.api.shell.extraPath.getEnableLoopbackPath() await sudoer.exec( - exeFile, { env: { PARAM: 'VALUE' } } + exeFile, + { env: { PARAM: 'VALUE' } } ) } } diff --git a/packages/gui/src/bridge/auto-start/backend.js b/packages/gui/src/bridge/auto-start/backend.js index d86b577..7893301 100644 --- a/packages/gui/src/bridge/auto-start/backend.js +++ b/packages/gui/src/bridge/auto-start/backend.js @@ -44,7 +44,8 @@ export default { openAtLogin: true, openAsHidden: true, args: [ - '--hideWindow', '"true"' + '--hideWindow', + '"true"' ] }) } diff --git a/packages/gui/src/bridge/auto-start/front.js b/packages/gui/src/bridge/auto-start/front.js index 2e1a4f2..bd15d58 100644 --- a/packages/gui/src/bridge/auto-start/front.js +++ b/packages/gui/src/bridge/auto-start/front.js @@ -1,4 +1,3 @@ - function install (app, api) { api.ipc.on('auto-start', (event, message) => { if (message.value === true) { diff --git a/packages/gui/src/bridge/backend.js b/packages/gui/src/bridge/backend.js index 78e262c..9884610 100644 --- a/packages/gui/src/bridge/backend.js +++ b/packages/gui/src/bridge/backend.js @@ -1,8 +1,8 @@ import api from './api/backend' +import autoStart from './auto-start/backend' +import fileSelector from './file-selector/backend' import tongji from './tongji/backend' import update from './update/backend' -import fileSelector from './file-selector/backend' -import autoStart from './auto-start/backend' const modules = { api, // 核心接口模块 diff --git a/packages/gui/src/bridge/error/front.js b/packages/gui/src/bridge/error/front.js index fbf2061..f64d3fd 100644 --- a/packages/gui/src/bridge/error/front.js +++ b/packages/gui/src/bridge/error/front.js @@ -13,15 +13,14 @@ function install (app, api) { function handleServerStartError (message, err, app, api) { if (message.value === 'EADDRINUSE') { - // eslint-disable-next-line no-debugger app.$confirm({ title: '端口被占用,代理服务启动失败', content: '是否要杀掉占用进程?您也可以点击取消,然后前往加速服务->基本设置中修改代理端口', onOk () { // TODO 杀掉进程 - api.config.get().then(config => { + api.config.get().then((config) => { console.log('config', config) - api.shell.killByPort({ port: config.server.port }).then(ret => { + api.shell.killByPort({ port: config.server.port }).then((ret) => { app.$message.info('杀掉进程成功,请重试开启代理服务') }) }) @@ -31,7 +30,7 @@ function handleServerStartError (message, err, app, api) { } }) } else { - app.$message.error('加速服务启动失败:' + message.message) + app.$message.error(`加速服务启动失败:${message.message}`) } } diff --git a/packages/gui/src/bridge/file-selector/backend.js b/packages/gui/src/bridge/file-selector/backend.js index 3acba92..0c6269e 100644 --- a/packages/gui/src/bridge/file-selector/backend.js +++ b/packages/gui/src/bridge/file-selector/backend.js @@ -1,18 +1,18 @@ export default { install (context) { const { ipcMain, dialog, log } = context - ipcMain.on('file-selector', function (event, message) { + ipcMain.on('file-selector', (event, message) => { if (message.key === 'open') { dialog.showOpenDialog({ properties: ['openFile'], ...message - }).then(result => { + }).then((result) => { if (result.canceled) { event.sender.send('file-selector', { key: 'canceled' }) } else { event.sender.send('file-selector', { key: 'selected', value: result.filePaths }) } - }).catch(err => { + }).catch((err) => { log.error('选择文件失败:', err) }) } diff --git a/packages/gui/src/bridge/file-selector/front.js b/packages/gui/src/bridge/file-selector/front.js index 284cdce..8123556 100644 --- a/packages/gui/src/bridge/file-selector/front.js +++ b/packages/gui/src/bridge/file-selector/front.js @@ -1,9 +1,8 @@ - function install (app, api) { api.fileSelector = { open (value, options) { return new Promise((resolve, reject) => { - api.ipc.send('file-selector', { key: 'open', value: value, ...options }) + api.ipc.send('file-selector', { key: 'open', value, ...options }) api.ipc.on('file-selector', (event, message) => { console.log('selector', message) if (message.key === 'selected') { diff --git a/packages/gui/src/bridge/front.js b/packages/gui/src/bridge/front.js index 7224a30..becbde7 100644 --- a/packages/gui/src/bridge/front.js +++ b/packages/gui/src/bridge/front.js @@ -1,10 +1,11 @@ // import api from './api/front' +import autoStart from './auto-start/front' import error from './error/front' +import fileSelector from './file-selector/front' +import onClose from './on-close/front' import tongji from './tongji/front' import update from './update/front' -import fileSelector from './file-selector/front' -import autoStart from './auto-start/front' -import onClose from './on-close/front' + const modules = { // api, // 核心接口模块 error, diff --git a/packages/gui/src/bridge/mitmproxy.js b/packages/gui/src/bridge/mitmproxy.js index 590829a..5590874 100644 --- a/packages/gui/src/bridge/mitmproxy.js +++ b/packages/gui/src/bridge/mitmproxy.js @@ -1,10 +1,10 @@ -// eslint-disable-next-line no-unused-vars -const log = require('../utils/util.log') -const server = require('@docmirror/mitmproxy') -const jsonApi = require('@docmirror/mitmproxy/src/json') -const configPath = process.argv[2] const fs = require('fs') const path = require('path') +const server = require('@docmirror/mitmproxy') +const jsonApi = require('@docmirror/mitmproxy/src/json') +const log = require('../utils/util.log') + +const configPath = process.argv[2] const configJson = fs.readFileSync(configPath) log.info('读取 running.json by gui bridge 成功:', configPath) const config = jsonApi.parse(configJson.toString()) diff --git a/packages/gui/src/bridge/on-close/front.js b/packages/gui/src/bridge/on-close/front.js index 1a14fdb..c707989 100644 --- a/packages/gui/src/bridge/on-close/front.js +++ b/packages/gui/src/bridge/on-close/front.js @@ -12,19 +12,21 @@ function install (app, api) { } app.$confirm({ title: '关闭策略', - content: h =>
-
- - 直接关闭 - 最小化到系统托盘 - + content: (h) => ( +
+
+ + 直接关闭 + 最小化到系统托盘 + +
+
+ + 记住本次选择,不再提示 + +
-
- - 记住本次选择,不再提示 - < /a-checkbox> -
-
, + ), async onOk () { console.log('OK. closeType=', closeType) if (doSave) { diff --git a/packages/gui/src/bridge/tongji/backend.js b/packages/gui/src/bridge/tongji/backend.js index 294badb..f08b026 100644 --- a/packages/gui/src/bridge/tongji/backend.js +++ b/packages/gui/src/bridge/tongji/backend.js @@ -1,9 +1,8 @@ - /** * first step * @param {*} ipcMain */ -const ebtMain = (ipcMain) => { +function ebtMain (ipcMain) { const isDevelopment = process.env.NODE_ENV !== 'production' const request = require('request') /* istanbul ignore else */ @@ -21,15 +20,14 @@ const ebtMain = (ipcMain) => { headers: { Referer: 'https://hm.baidu.com/' } - }, - (err, response, body) => { + }, (err, response, body) => { if (err) { console.error('百度统计请求出错', err) return } const rource = '(h.c.b.su=h.c.b.u||document.location.href),h.c.b.u=f.protocol+"//"+document.location.host+' /* istanbul ignore else */ - if (body && body.indexOf(rource) >= 0) { + if (body && body.includes(rource)) { // step 3 let text = body diff --git a/packages/gui/src/bridge/tongji/front.js b/packages/gui/src/bridge/tongji/front.js index 023db8b..7aaa485 100644 --- a/packages/gui/src/bridge/tongji/front.js +++ b/packages/gui/src/bridge/tongji/front.js @@ -1,11 +1,10 @@ - /** * second step * @param {*} ipcRenderer * @param {*} siteId * @param {*} router */ -const ebtRenderer = (ipcRenderer, siteId, router) => { +function ebtRenderer (ipcRenderer, siteId, router) { /* istanbul ignore else */ if (!(ipcRenderer && ipcRenderer.on && ipcRenderer.send)) { throw new TypeError('require ipcRenderer') @@ -38,7 +37,7 @@ const ebtRenderer = (ipcRenderer, siteId, router) => { router.beforeEach((to, _, next) => { /* istanbul ignore else */ if (to.path) { - window._hmt.push(['_trackPageview', '/#' + to.fullPath]) + window._hmt.push(['_trackPageview', `/#${to.fullPath}`]) console.log('baidu trace', to.fullPath) } diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js index 6847d08..c633446 100644 --- a/packages/gui/src/bridge/update/backend.js +++ b/packages/gui/src/bridge/update/backend.js @@ -1,16 +1,15 @@ +import fs from 'fs' +import path from 'path' +import DevSidecar from '@docmirror/dev-sidecar' +import AdmZip from 'adm-zip' import { ipcMain } from 'electron' import { autoUpdater } from 'electron-updater' -import path from 'path' import request from 'request' import progress from 'request-progress' -import fs from 'fs' -import AdmZip from 'adm-zip' -import log from '../../utils/util.log' -import appPathUtil from '../../utils/util.apppath' import pkg from '../../../package.json' -import DevSidecar from '@docmirror/dev-sidecar' +import appPathUtil from '../../utils/util.apppath' +import log from '../../utils/util.log' -// eslint-disable-next-line no-unused-vars const isMac = process.platform === 'darwin' const isLinux = process.platform === 'linux' @@ -24,16 +23,16 @@ function downloadFile (uri, filePath, onProgress, onSuccess, onError) { // delay: 1000, // Only start to emit after 1000ms delay, defaults to 0ms // lengthHeader: 'x-transfer-length' // Length header to use, defaults to content-length }) - .on('progress', function (state) { + .on('progress', (state) => { onProgress(state.percent * 100) log.log('progress', state.percent) }) - .on('error', function (err) { + .on('error', (err) => { // Do something with err log.error('下载升级包失败:', err) onError(err) }) - .on('end', function () { + .on('end', () => { // Do something after request finishes onSuccess() }) @@ -44,9 +43,9 @@ function parseVersion (version) { const matched = version.match(/^v?(\d+\.\d+\.\d+)(.*)$/) const versionArr = matched[1].split('.') return { - major: parseInt(versionArr[0]), - minor: parseInt(versionArr[1]), - patch: parseInt(versionArr[2]), + major: Number.parseInt(versionArr[0]), + minor: Number.parseInt(versionArr[1]), + patch: Number.parseInt(versionArr[2]), suffix: matched[2] } } @@ -141,11 +140,11 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { // 检查更新 const releasesApiUrl = 'https://api.github.com/repos/docmirror/dev-sidecar/releases' async function checkForUpdatesFromGitHub () { - request(releasesApiUrl, { headers: { 'User-Agent': 'DS/' + curVersion, 'Server-Name': 'baidu.com' } }, (error, response, body) => { + request(releasesApiUrl, { headers: { 'User-Agent': `DS/${curVersion}`, 'Server-Name': 'baidu.com' } }, (error, response, body) => { try { if (error) { log.error('检查更新失败:', error) - const errorMsg = '检查更新失败:' + error + const errorMsg = `检查更新失败:${error}` win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: errorMsg }) return } @@ -203,7 +202,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { value: { version, releaseNotes: versionData.body - ? (versionData.body.replace(/\r\n/g, '\n').replace(/https:\/\/github.com\/docmirror\/dev-sidecar/g, '').replace(/(?<=(^|\n))[ \t]*[ #]*#\s*/g, '') || '无') + ? (versionData.body.replace(/\r\n/g, '\n').replace(/https:\/\/github.com\/docmirror\/dev-sidecar/g, '').replace(/(?<=(^|\n))[ \t]*(?:#[ #]*)?#\s*/g, '') || '无') : '无' } }) @@ -229,15 +228,15 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { let message if (response) { - message = '检查更新失败: ' + (bodyObj && bodyObj.message ? bodyObj.message : response.message) + ', code: ' + response.statusCode + message = `检查更新失败: ${bodyObj && bodyObj.message ? bodyObj.message : response.message}, code: ${response.statusCode}` } else { - message = '检查更新失败: ' + (bodyObj && bodyObj.message ? bodyObj.message : body) + message = `检查更新失败: ${bodyObj && bodyObj.message ? bodyObj.message : body}` } win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: message }) } } catch (e) { log.error('检查更新失败:', e) - win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: '检查更新失败:' + e.message }) + win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: `检查更新失败:${e.message}` }) } }) } @@ -252,10 +251,10 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { } catch (e) { fs.mkdirSync(fileDir) } - const filePath = path.join(fileDir, value.version + '.zip') + const filePath = path.join(fileDir, `${value.version}.zip`) downloadFile(value.partPackage, filePath, (data) => { - win.webContents.send('update', { key: 'progress', value: parseInt(data) }) + win.webContents.send('update', { key: 'progress', value: Number.parseInt(data) }) }, () => { // 文件下载完成 win.webContents.send('update', { key: 'progress', value: 100 }) @@ -263,10 +262,10 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { partPackagePath = filePath win.webContents.send('update', { key: 'downloaded', - value: value + value }) }, (error) => { - sendUpdateMessage({ key: 'error', value: error, error: error }) + sendUpdateMessage({ key: 'error', value: error, error }) }) } @@ -294,30 +293,30 @@ function updateHandle (app, api, win, beforeQuit, quit, log) { } } - autoUpdater.on('error', function (error) { + autoUpdater.on('error', (error) => { log.warn('autoUpdater error:', error) - sendUpdateMessage({ key: 'error', value: error, error: error }) + sendUpdateMessage({ key: 'error', value: error, error }) // dialog.showErrorBox('Error: ', error == null ? 'unknown' : (error.stack || error).toString()) }) - autoUpdater.on('checking-for-update', function () { + autoUpdater.on('checking-for-update', () => { log.info('autoUpdater checking-for-update') sendUpdateMessage({ key: 'checking', value: message.checking }) }) - autoUpdater.on('update-available', function (info) { + autoUpdater.on('update-available', (info) => { log.info('autoUpdater update-available') sendUpdateMessage({ key: 'available', value: info }) }) - autoUpdater.on('update-not-available', function () { + autoUpdater.on('update-not-available', () => { log.info('autoUpdater update-not-available') sendUpdateMessage({ key: 'notAvailable', value: message.updateNotAva }) }) // 更新下载进度 - autoUpdater.on('download-progress', function (progressObj) { + autoUpdater.on('download-progress', (progressObj) => { log.info('autoUpdater download-progress') - win.webContents.send('update', { key: 'progress', value: parseInt(progressObj.percent) }) + win.webContents.send('update', { key: 'progress', value: Number.parseInt(progressObj.percent) }) }) // 更新完成,重启应用 - autoUpdater.on('update-downloaded', function (info) { + autoUpdater.on('update-downloaded', (info) => { log.info('download complete, version:', info.version) win.webContents.send('update', { key: 'downloaded', diff --git a/packages/gui/src/bridge/update/front.js b/packages/gui/src/bridge/update/front.js index 60f1370..bb298d7 100644 --- a/packages/gui/src/bridge/update/front.js +++ b/packages/gui/src/bridge/update/front.js @@ -80,11 +80,13 @@ function install (app, api) { cancelText: '取消', okText: '打开链接', width: 420, - content: h => { - return
-
请前往 github项目release页面 下载新版本手动安装
-
https://github.com/docmirror/dev-sidecar/releases
-
+ content: (h) => { + return ( +
+
请前往 github项目release页面 下载新版本手动安装
+
https://github.com/docmirror/dev-sidecar/releases
+
+ ) }, onOk () { openGithubUrl() @@ -141,31 +143,35 @@ function install (app, api) { } console.log(value) app.$confirm({ - title: '发现新版本:v' + value.version, + title: `发现新版本:v${value.version}`, cancelText: '暂不升级', okText: '升级', width: 700, - content: h => { + content: (h) => { if (value.releaseNotes) { const notes = [] if (typeof value.releaseNotes === 'string') { const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n') - return
-
发布公告:https://github.com/docmirror/dev-sidecar/releases
-
-
-                {releaseNotes}
-              
-
+ return ( +
+
发布公告:https://github.com/docmirror/dev-sidecar/releases
+
+
+                  {releaseNotes}
+                
+
+ ) } else { for (const note of value.releaseNotes) { notes.push(
  • {note}
  • ) } - return
    -
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    -
    更新内容:
    -
      {notes}
    -
    + return ( +
    +
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    +
    更新内容:
    +
      {notes}
    +
    + ) } } }, @@ -187,27 +193,31 @@ function install (app, api) { cancelText: '暂不升级', okText: '立即升级', width: 700, - content: h => { + content: (h) => { if (value.releaseNotes) { const notes = [] if (typeof value.releaseNotes === 'string') { const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n') - return
    -
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    -
    -
    -                {releaseNotes}
    -              
    -
    + return ( +
    +
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    +
    +
    +                  {releaseNotes}
    +                
    +
    + ) } else { for (const note of value.releaseNotes) { notes.push(
  • {note}
  • ) } - return
    -
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    -
    更新内容:
    -
      {notes}
    -
    + return ( +
    +
    发布公告:https://github.com/docmirror/dev-sidecar/releases
    +
    更新内容:
    +
      {notes}
    +
    + ) } } }, diff --git a/packages/gui/src/main.js b/packages/gui/src/main.js index 14e34d1..1cccb2d 100644 --- a/packages/gui/src/main.js +++ b/packages/gui/src/main.js @@ -1,11 +1,11 @@ -import Vue from 'vue' -import App from './view/App.vue' import antd from 'ant-design-vue' -import 'ant-design-vue/dist/antd.css' -import view from './view' +import Vue from 'vue' import VueRouter from 'vue-router' -import routes from './view/router' +import view from './view' +import App from './view/App.vue' import DsContainer from './view/components/container' +import routes from './view/router' +import 'ant-design-vue/dist/antd.css' import './view/style/index.scss' import './view/style/theme/dark.scss' // 暗色主题 diff --git a/packages/gui/src/utils/util.apppath.js b/packages/gui/src/utils/util.apppath.js index 10ac6b9..5ec0e33 100644 --- a/packages/gui/src/utils/util.apppath.js +++ b/packages/gui/src/utils/util.apppath.js @@ -1,5 +1,6 @@ -import path from 'path' import os from 'os' +import path from 'path' + function getSystemPlatform () { switch (os.platform()) { case 'darwin': diff --git a/packages/gui/src/utils/util.log.js b/packages/gui/src/utils/util.log.js index 533a666..f9e15f6 100644 --- a/packages/gui/src/utils/util.log.js +++ b/packages/gui/src/utils/util.log.js @@ -1,10 +1,13 @@ -const log4js = require('log4js') +const path = require('path') const DevSidecar = require('@docmirror/dev-sidecar') +const log4js = require('log4js') + +const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' + const getDefaultConfigBasePath = function () { return DevSidecar.api.config.get().server.setting.userBasePath } -const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info' -const path = require('path') + const filename = path.join(getDefaultConfigBasePath(), '/logs/gui.log') log4js.configure({ appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } }, diff --git a/packages/gui/src/view/components/container.vue b/packages/gui/src/view/components/container.vue index de1fd77..4aa02b7 100644 --- a/packages/gui/src/view/components/container.vue +++ b/packages/gui/src/view/components/container.vue @@ -1,15 +1,15 @@ @@ -49,5 +49,4 @@ export default { padding:15px; } } - diff --git a/packages/gui/src/view/components/setup-ca.vue b/packages/gui/src/view/components/setup-ca.vue index fa7749d..147d16d 100644 --- a/packages/gui/src/view/components/setup-ca.vue +++ b/packages/gui/src/view/components/setup-ca.vue @@ -1,6 +1,6 @@