From 451b1307529d53905973e69f05b83ebea10f84fd Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Sat, 16 Nov 2024 01:08:35 +0800
Subject: [PATCH 01/20] upgrade and clean deps
---
packages/core/package.json | 58 +++------------------------------
packages/gui/babel.config.js | 4 +--
packages/gui/package.json | 47 +++++---------------------
packages/mitmproxy/package.json | 52 ++++-------------------------
4 files changed, 21 insertions(+), 140 deletions(-)
diff --git a/packages/core/package.json b/packages/core/package.json
index 587e942b9e..8dcf38f0e3 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -17,67 +17,17 @@
"test": "mocha"
},
"dependencies": {
+ "spawn-sync": "^2.0.0",
"@docmirror/mitmproxy": "workspace:*",
- "agentkeepalive": "^2.1.1",
- "babel-preset-es2020": "^1.0.2",
- "charset": "^1.0.0",
- "child_process": "^1.0.2",
- "colors": "^1.1.2",
- "commander": "^2.9.0",
- "debug": "^4.1.1",
- "dns-over-http": "^0.2.0",
- "dns-over-tls": "^0.0.8",
"fix-path": "^3.0.0",
- "iconv-lite": "^0.4.13",
- "is-browser": "^2.1.0",
- "jschardet": "^1.4.1",
- "json5": "^2.2.3",
+ "iconv-lite": "^0.6.3",
"lodash": "^4.17.20",
"log4js": "^6.3.0",
- "lru-cache": "^6.0.0",
- "mkdirp": "^0.5.1",
- "node-cmd": "^3.0.0",
- "node-forge": "^0.8.2",
"node-powershell": "^4.0.0",
- "require-context": "^1.1.0",
- "spawn-sync": "^2.0.0",
- "through2": "^2.0.1",
- "tunnel-agent": "^0.4.3",
- "util": "^0.12.3",
- "validator": "^13.1.17",
- "winreg": "^1.2.4"
+ "winreg": "^1.2.5"
},
"devDependencies": {
- "@vue/cli-plugin-eslint": "^4.5.0",
- "@vue/eslint-config-standard": "^5.1.2",
- "babel-eslint": "^10.1.0",
"chai": "^4.3.4",
- "eslint": "^6.7.2",
- "eslint-plugin-import": "^2.20.2",
- "eslint-plugin-node": "^11.1.0",
- "eslint-plugin-promise": "^4.2.1",
- "eslint-plugin-standard": "^4.0.0",
- "eslint-plugin-vue": "^6.2.2",
"mocha": "^8.2.1"
- },
- "eslintConfig": {
- "root": true,
- "env": {
- "node": true
- },
- "extends": [
- "plugin:vue/essential",
- "@vue/standard"
- ],
- "parserOptions": {
- "parser": "babel-eslint"
- },
- "rules": {}
- },
- "browserslist": [
- "> 1%",
- "last 2 versions",
- "not dead"
- ],
- "gitHead": "30ecf21cb001fb8d821e575d476ca0ffb4ff086e"
+ }
}
diff --git a/packages/gui/babel.config.js b/packages/gui/babel.config.js
index df195386eb..4c3a7a3e4d 100644
--- a/packages/gui/babel.config.js
+++ b/packages/gui/babel.config.js
@@ -1,5 +1,5 @@
module.exports = {
presets: [
- '@vue/cli-plugin-babel/preset',
- ],
+ '@vue/babel-preset-jsx'
+ ]
}
diff --git a/packages/gui/package.json b/packages/gui/package.json
index 145f67dd9d..f46fee10af 100644
--- a/packages/gui/package.json
+++ b/packages/gui/package.json
@@ -27,65 +27,36 @@
"@natmri/platform-napi": "^0.0.7",
"adm-zip": "^0.5.5",
"ant-design-vue": "^1.6.5",
- "compressing": "^1.5.1",
- "core-js": "^3.6.5",
"electron-baidu-tongji": "^1.0.5",
- "electron-reload": "^1.5.0",
- "electron-store": "^6.0.1",
"electron-sudo": "^4.0.12",
"electron-updater": "^4.3.5",
- "es-abstract": "^1.17.7",
- "extract-zip": "^2.0.1",
- "iconv-lite": "^0.6.2",
"json5": "^2.2.3",
"lodash": "^4.17.20",
"log4js": "^6.3.0",
"request-progress": "^3.0.0",
"sass": "^1.27.1",
"sass-loader": "^10.0.4",
- "vue": "^2.6.11",
+ "vue": "^2.7.16",
"vue-json-editor-fix-cn": "^1.4.3",
"vue-router": "^3.4.8"
},
"devDependencies": {
- "@vue/cli-plugin-babel": "^4.5.0",
- "@vue/cli-plugin-eslint": "^4.5.0",
- "@vue/cli-service": "^4.5.0",
- "@vue/eslint-config-standard": "^5.1.2",
- "babel-eslint": "^10.1.0",
+ "@babel/plugin-syntax-jsx": "^7.25.9",
+ "@vue/babel-helper-vue-jsx-merge-props": "^1.4.0",
+ "@vue/babel-preset-jsx": "^1.4.0",
+ "@vue/cli-plugin-babel": "^4.5.19",
+ "@vue/cli-service": "^4.5.19",
"electron": "^17.4.11",
"electron-builder": "^25.0.6",
- "electron-devtools-installer": "^3.1.0",
+ "electron-devtools-installer": "^3.2.0",
"electron-icon-builder": "^2.0.1",
- "eslint": "^6.7.2",
- "eslint-plugin-import": "^2.20.2",
- "eslint-plugin-node": "^11.1.0",
- "eslint-plugin-promise": "^4.2.1",
- "eslint-plugin-standard": "^4.0.0",
- "eslint-plugin-vue": "^6.2.2",
"json5-loader": "^4.0.1",
"vue-cli-plugin-electron-builder": "^2.1.1",
- "vue-template-compiler": "^2.6.11"
- },
- "eslintConfig": {
- "root": true,
- "env": {
- "node": true
- },
- "extends": [
- "plugin:vue/essential",
- "@vue/standard"
- ],
- "parserOptions": {
- "parser": "babel-eslint"
- },
- "rules": {}
+ "vue-template-compiler": "2.7.16"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
- ],
- "__npminstall_done": false,
- "gitHead": "30ecf21cb001fb8d821e575d476ca0ffb4ff086e"
+ ]
}
diff --git a/packages/mitmproxy/package.json b/packages/mitmproxy/package.json
index 2e921ad64a..0098226578 100644
--- a/packages/mitmproxy/package.json
+++ b/packages/mitmproxy/package.json
@@ -11,14 +11,10 @@
"main": "src/index.js",
"scripts": {},
"dependencies": {
- "agentkeepalive": "^2.1.1",
- "axios": "^0.21.1",
+ "agentkeepalive": "^4.5.0",
+ "axios": "^1.7.7",
"baidu-aip-sdk": "^4.16.16",
- "child_process": "^1.0.2",
- "colors": "^1.1.2",
- "commander": "^2.9.0",
"crypto-js": "^4.0.0",
- "debug": "^4.1.1",
"dns-over-http": "^0.2.0",
"dns-over-tls": "^0.0.9",
"is-browser": "^2.1.0",
@@ -27,45 +23,9 @@
"log4js": "^6.3.0",
"lru-cache": "^6.0.0",
"mkdirp": "^0.5.1",
- "node-cmd": "^3.0.0",
- "node-forge": "^0.8.2",
- "require-context": "^1.1.0",
+ "node-forge": "^1.3.1",
"stream-throttle": "^0.1.3",
- "through2": "^2.0.1",
- "tunnel-agent": "^0.4.3",
- "util": "^0.12.3",
- "validator": "^13.1.17"
- },
- "devDependencies": {
- "@vue/cli-plugin-babel": "^4.5.0",
- "@vue/cli-plugin-eslint": "^4.5.0",
- "@vue/eslint-config-standard": "^5.1.2",
- "babel-eslint": "^10.1.0",
- "eslint": "^6.7.2",
- "eslint-plugin-import": "^2.20.2",
- "eslint-plugin-node": "^11.1.0",
- "eslint-plugin-promise": "^4.2.1",
- "eslint-plugin-standard": "^4.0.0",
- "eslint-plugin-vue": "^6.2.2"
- },
- "eslintConfig": {
- "root": true,
- "env": {
- "node": true
- },
- "extends": [
- "plugin:vue/essential",
- "@vue/standard"
- ],
- "parserOptions": {
- "parser": "babel-eslint"
- },
- "rules": {}
- },
- "browserslist": [
- "> 1%",
- "last 2 versions",
- "not dead"
- ],
- "gitHead": "30ecf21cb001fb8d821e575d476ca0ffb4ff086e"
+ "through2": "^4.0.2",
+ "tunnel-agent": "^0.6.0"
+ }
}
From 60bb3c9c684381db283503d0b1f62db194023ce1 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Sat, 16 Nov 2024 01:48:54 +0800
Subject: [PATCH 02/20] upgrade deps
---
packages/gui/package.json | 12 +++++-------
packages/gui/src/view/App.vue | 2 +-
packages/gui/vue.config.js | 2 ++
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/packages/gui/package.json b/packages/gui/package.json
index f46fee10af..fb8f0cdfa1 100644
--- a/packages/gui/package.json
+++ b/packages/gui/package.json
@@ -34,8 +34,8 @@
"lodash": "^4.17.20",
"log4js": "^6.3.0",
"request-progress": "^3.0.0",
- "sass": "^1.27.1",
- "sass-loader": "^10.0.4",
+ "sass": "^1.81.0",
+ "sass-loader": "^16.0.3",
"vue": "^2.7.16",
"vue-json-editor-fix-cn": "^1.4.3",
"vue-router": "^3.4.8"
@@ -44,15 +44,13 @@
"@babel/plugin-syntax-jsx": "^7.25.9",
"@vue/babel-helper-vue-jsx-merge-props": "^1.4.0",
"@vue/babel-preset-jsx": "^1.4.0",
- "@vue/cli-plugin-babel": "^4.5.19",
- "@vue/cli-service": "^4.5.19",
+ "@vue/cli-plugin-babel": "^5.0.8",
+ "@vue/cli-service": "^5.0.8",
"electron": "^17.4.11",
"electron-builder": "^25.0.6",
- "electron-devtools-installer": "^3.2.0",
"electron-icon-builder": "^2.0.1",
"json5-loader": "^4.0.1",
- "vue-cli-plugin-electron-builder": "^2.1.1",
- "vue-template-compiler": "2.7.16"
+ "vue-cli-plugin-electron-builder": "^2.1.1"
},
"browserslist": [
"> 1%",
diff --git a/packages/gui/src/view/App.vue b/packages/gui/src/view/App.vue
index 17b666cd56..059c1c3135 100644
--- a/packages/gui/src/view/App.vue
+++ b/packages/gui/src/view/App.vue
@@ -119,7 +119,7 @@ body{
padding:5px;
border-bottom: #eee solid 1px;
height:60px;
- background-image: url("/logo/logo-lang.svg");
+ background-image: url("../../public/logo/logo-lang.svg");
background-size: auto 50px;
background-repeat: no-repeat;
background-position: 5px center;
diff --git a/packages/gui/vue.config.js b/packages/gui/vue.config.js
index df53d2cbd0..9a39c7c760 100644
--- a/packages/gui/vue.config.js
+++ b/packages/gui/vue.config.js
@@ -35,6 +35,8 @@ module.exports = {
},
pluginOptions: {
electronBuilder: {
+ // Ref: https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/1891
+ customFileProtocol: './',
externals: [
'@mihomo-party/sysproxy',
'@mihomo-party/sysproxy-win32-ia32-msvc',
From 21ae3a629e71c489838f05922902d248493a1469 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Sat, 16 Nov 2024 10:13:03 +0800
Subject: [PATCH 03/20] upgrade deps
---
packages/gui/package.json | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/packages/gui/package.json b/packages/gui/package.json
index fb8f0cdfa1..adb80f7a79 100644
--- a/packages/gui/package.json
+++ b/packages/gui/package.json
@@ -25,8 +25,8 @@
"@docmirror/mitmproxy": "workspace:*",
"@mihomo-party/sysproxy": "^2.0.4",
"@natmri/platform-napi": "^0.0.7",
- "adm-zip": "^0.5.5",
- "ant-design-vue": "^1.6.5",
+ "adm-zip": "^0.5.16",
+ "ant-design-vue": "^1.7.8",
"electron-baidu-tongji": "^1.0.5",
"electron-sudo": "^4.0.12",
"electron-updater": "^4.3.5",
@@ -38,7 +38,7 @@
"sass-loader": "^16.0.3",
"vue": "^2.7.16",
"vue-json-editor-fix-cn": "^1.4.3",
- "vue-router": "^3.4.8"
+ "vue-router": "^3.6.5"
},
"devDependencies": {
"@babel/plugin-syntax-jsx": "^7.25.9",
@@ -46,7 +46,7 @@
"@vue/babel-preset-jsx": "^1.4.0",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-service": "^5.0.8",
- "electron": "^17.4.11",
+ "electron": "^19.1.9",
"electron-builder": "^25.0.6",
"electron-icon-builder": "^2.0.1",
"json5-loader": "^4.0.1",
From ea2d62572b38cca945ba32ebdb85a6898f8399ce Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Sat, 16 Nov 2024 23:16:57 +0800
Subject: [PATCH 04/20] upgrade `log4js`
---
packages/core/package.json | 4 ++--
packages/core/src/utils/util.log.js | 15 +-----------
packages/core/src/utils/util.logger.js | 30 ++++++++++++++++++++++++
packages/gui/package.json | 1 -
packages/gui/src/utils/util.log.js | 16 ++-----------
packages/mitmproxy/package.json | 2 +-
packages/mitmproxy/src/utils/util.log.js | 12 ++--------
7 files changed, 38 insertions(+), 42 deletions(-)
create mode 100644 packages/core/src/utils/util.logger.js
diff --git a/packages/core/package.json b/packages/core/package.json
index 8dcf38f0e3..c38a4ce0d1 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -18,15 +18,15 @@
},
"dependencies": {
"spawn-sync": "^2.0.0",
- "@docmirror/mitmproxy": "workspace:*",
"fix-path": "^3.0.0",
"iconv-lite": "^0.6.3",
"lodash": "^4.17.20",
- "log4js": "^6.3.0",
+ "log4js": "^6.9.1",
"node-powershell": "^4.0.0",
"winreg": "^1.2.5"
},
"devDependencies": {
+ "@docmirror/mitmproxy": "workspace:*",
"chai": "^4.3.4",
"mocha": "^8.2.1"
}
diff --git a/packages/core/src/utils/util.log.js b/packages/core/src/utils/util.log.js
index 306d04c169..20e107882c 100644
--- a/packages/core/src/utils/util.log.js
+++ b/packages/core/src/utils/util.log.js
@@ -1,17 +1,4 @@
-const path = require('path')
-const log4js = require('log4js')
-const config = require('../config/index')
+const log4js = require('./util.logger')
-const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info'
-
-function getDefaultConfigBasePath () {
- return config.server.setting.userBasePath
-}
-
-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 } },
-})
const logger = log4js.getLogger('core')
module.exports = logger
diff --git a/packages/core/src/utils/util.logger.js b/packages/core/src/utils/util.logger.js
new file mode 100644
index 0000000000..749449a187
--- /dev/null
+++ b/packages/core/src/utils/util.logger.js
@@ -0,0 +1,30 @@
+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 coreLogFilename = path.join(getDefaultConfigBasePath(), '/logs/core.log')
+const guiLogFilename = path.join(getDefaultConfigBasePath(), '/logs/gui.log')
+const serverLogFilename = path.join(getDefaultConfigBasePath(), '/logs/server.log')
+
+log4js.configure({
+ appenders: {
+ std: { type: 'stdout' },
+ core: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: coreLogFilename },
+ gui: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: guiLogFilename },
+ server: { level: 'debug', type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: serverLogFilename }
+ },
+ categories: {
+ default: { appenders: ['std'], level },
+ core: { appenders: ['core', 'std'], level },
+ gui: { appenders: ['gui', 'std'], level },
+ server: { appenders: ['server', 'std'], level }
+ },
+})
+
+module.exports = log4js
diff --git a/packages/gui/package.json b/packages/gui/package.json
index adb80f7a79..f84eda47c2 100644
--- a/packages/gui/package.json
+++ b/packages/gui/package.json
@@ -32,7 +32,6 @@
"electron-updater": "^4.3.5",
"json5": "^2.2.3",
"lodash": "^4.17.20",
- "log4js": "^6.3.0",
"request-progress": "^3.0.0",
"sass": "^1.81.0",
"sass-loader": "^16.0.3",
diff --git a/packages/gui/src/utils/util.log.js b/packages/gui/src/utils/util.log.js
index a744d88a5a..cdf77c997c 100644
--- a/packages/gui/src/utils/util.log.js
+++ b/packages/gui/src/utils/util.log.js
@@ -1,17 +1,5 @@
-const path = require('path')
-const DevSidecar = require('@docmirror/dev-sidecar')
-const log4js = require('log4js')
+const log4js = require('@docmirror/dev-sidecar/src/utils/util.logger')
-const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info'
-
-const getDefaultConfigBasePath = function () {
- return DevSidecar.api.config.get().server.setting.userBasePath
-}
-
-const filename = path.join(getDefaultConfigBasePath(), '/logs/gui.log')
-log4js.configure({
- appenders: { std: { type: 'stdout' }, file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } },
- categories: { default: { appenders: ['file', 'std'], level } },
-})
const logger = log4js.getLogger('gui')
+
module.exports = logger
diff --git a/packages/mitmproxy/package.json b/packages/mitmproxy/package.json
index 0098226578..8fa36a85ef 100644
--- a/packages/mitmproxy/package.json
+++ b/packages/mitmproxy/package.json
@@ -11,6 +11,7 @@
"main": "src/index.js",
"scripts": {},
"dependencies": {
+ "@docmirror/dev-sidecar": "workspace:*",
"agentkeepalive": "^4.5.0",
"axios": "^1.7.7",
"baidu-aip-sdk": "^4.16.16",
@@ -20,7 +21,6 @@
"is-browser": "^2.1.0",
"json5": "^2.2.3",
"lodash": "^4.17.20",
- "log4js": "^6.3.0",
"lru-cache": "^6.0.0",
"mkdirp": "^0.5.1",
"node-forge": "^1.3.1",
diff --git a/packages/mitmproxy/src/utils/util.log.js b/packages/mitmproxy/src/utils/util.log.js
index c9117f9b47..cb9a3e43ec 100644
--- a/packages/mitmproxy/src/utils/util.log.js
+++ b/packages/mitmproxy/src/utils/util.log.js
@@ -1,13 +1,5 @@
-const path = require('path')
-const log4js = require('log4js')
-const proxyConfig = require('../lib/proxy/common/config')
+const log4js = require('@docmirror/dev-sidecar/src/utils/util.logger')
-const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info'
-
-const filename = path.join(proxyConfig.getDefaultCABasePath(), '/logs/server.log')
-log4js.configure({
- appenders: { std: { type: 'stdout', level: 'debug' }, file: { level: 'debug', type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename } },
- categories: { default: { appenders: ['file', 'std'], level } },
-})
const logger = log4js.getLogger('server')
+
module.exports = logger
From bb7a2d0df9a61c23fa51cc0173d9b71604b49a06 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Sun, 17 Nov 2024 00:59:44 +0800
Subject: [PATCH 05/20] `cli` package
---
packages/cli/LICENSE | 373 ++++++++++++++++++
packages/cli/cli.js | 3 +
packages/cli/package.json | 23 ++
packages/{core/start => cli/src}/banner.txt | 0
packages/{core/start => cli/src}/index.js | 11 +-
packages/{core/start => cli/src}/mitmproxy.js | 0
.../{core/start => cli/src}/user_config.json5 | 0
packages/core/package.json | 2 -
8 files changed, 404 insertions(+), 8 deletions(-)
create mode 100644 packages/cli/LICENSE
create mode 100644 packages/cli/cli.js
create mode 100644 packages/cli/package.json
rename packages/{core/start => cli/src}/banner.txt (100%)
rename packages/{core/start => cli/src}/index.js (67%)
rename packages/{core/start => cli/src}/mitmproxy.js (100%)
rename packages/{core/start => cli/src}/user_config.json5 (100%)
diff --git a/packages/cli/LICENSE b/packages/cli/LICENSE
new file mode 100644
index 0000000000..a612ad9813
--- /dev/null
+++ b/packages/cli/LICENSE
@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+ means each individual or legal entity that creates, contributes to
+ the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+ means the combination of the Contributions of others (if any) used
+ by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+ means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+ means Source Code Form to which the initial Contributor has attached
+ the notice in Exhibit A, the Executable Form of such Source Code
+ Form, and Modifications of such Source Code Form, in each case
+ including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+ means
+
+ (a) that the initial Contributor has attached the notice described
+ in Exhibit B to the Covered Software; or
+
+ (b) that the Covered Software was made available under the terms of
+ version 1.1 or earlier of the License, but not also under the
+ terms of a Secondary License.
+
+1.6. "Executable Form"
+ means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+ means a work that combines Covered Software with other material, in
+ a separate file or files, that is not Covered Software.
+
+1.8. "License"
+ means this document.
+
+1.9. "Licensable"
+ means having the right to grant, to the maximum extent possible,
+ whether at the time of the initial grant or subsequently, any and
+ all of the rights conveyed by this License.
+
+1.10. "Modifications"
+ means any of the following:
+
+ (a) any file in Source Code Form that results from an addition to,
+ deletion from, or modification of the contents of Covered
+ Software; or
+
+ (b) any new file in Source Code Form that contains any Covered
+ Software.
+
+1.11. "Patent Claims" of a Contributor
+ means any patent claim(s), including without limitation, method,
+ process, and apparatus claims, in any patent Licensable by such
+ Contributor that would be infringed, but for the grant of the
+ License, by the making, using, selling, offering for sale, having
+ made, import, or transfer of either its Contributions or its
+ Contributor Version.
+
+1.12. "Secondary License"
+ means either the GNU General Public License, Version 2.0, the GNU
+ Lesser General Public License, Version 2.1, the GNU Affero General
+ Public License, Version 3.0, or any later versions of those
+ licenses.
+
+1.13. "Source Code Form"
+ means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+ means an individual or a legal entity exercising rights under this
+ License. For legal entities, "You" includes any entity that
+ controls, is controlled by, or is under common control with You. For
+ purposes of this definition, "control" means (a) the power, direct
+ or indirect, to cause the direction or management of such entity,
+ whether by contract or otherwise, or (b) ownership of more than
+ fifty percent (50%) of the outstanding shares or beneficial
+ ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+ Licensable by such Contributor to use, reproduce, make available,
+ modify, display, perform, distribute, and otherwise exploit its
+ Contributions, either on an unmodified basis, with Modifications, or
+ as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+ for sale, have made, import, and otherwise transfer either its
+ Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+ or
+
+(b) for infringements caused by: (i) Your and any other third party's
+ modifications of Covered Software, or (ii) the combination of its
+ Contributions with other software (except as part of its Contributor
+ Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+ its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+ Form, as described in Section 3.1, and You must inform recipients of
+ the Executable Form how they can obtain a copy of such Source Code
+ Form by reasonable means in a timely manner, at a charge no more
+ than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+ License, or sublicense it under different terms, provided that the
+ license for the Executable Form does not attempt to limit or alter
+ the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+* *
+* 6. Disclaimer of Warranty *
+* ------------------------- *
+* *
+* Covered Software is provided under this License on an "as is" *
+* basis, without warranty of any kind, either expressed, implied, or *
+* statutory, including, without limitation, warranties that the *
+* Covered Software is free of defects, merchantable, fit for a *
+* particular purpose or non-infringing. The entire risk as to the *
+* quality and performance of the Covered Software is with You. *
+* Should any Covered Software prove defective in any respect, You *
+* (not any Contributor) assume the cost of any necessary servicing, *
+* repair, or correction. This disclaimer of warranty constitutes an *
+* essential part of this License. No use of any Covered Software is *
+* authorized under this License except under this disclaimer. *
+* *
+************************************************************************
+
+************************************************************************
+* *
+* 7. Limitation of Liability *
+* -------------------------- *
+* *
+* Under no circumstances and under no legal theory, whether tort *
+* (including negligence), contract, or otherwise, shall any *
+* Contributor, or anyone who distributes Covered Software as *
+* permitted above, be liable to You for any direct, indirect, *
+* special, incidental, or consequential damages of any character *
+* including, without limitation, damages for lost profits, loss of *
+* goodwill, work stoppage, computer failure or malfunction, or any *
+* and all other commercial damages or losses, even if such party *
+* shall have been informed of the possibility of such damages. This *
+* limitation of liability shall not apply to liability for death or *
+* personal injury resulting from such party's negligence to the *
+* extent applicable law prohibits such limitation. Some *
+* jurisdictions do not allow the exclusion or limitation of *
+* incidental or consequential damages, so this exclusion and *
+* limitation may not apply to You. *
+* *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+ This Source Code Form is "Incompatible With Secondary Licenses", as
+ defined by the Mozilla Public License, v. 2.0.
diff --git a/packages/cli/cli.js b/packages/cli/cli.js
new file mode 100644
index 0000000000..2b8767cafa
--- /dev/null
+++ b/packages/cli/cli.js
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require('../src')
diff --git a/packages/cli/package.json b/packages/cli/package.json
new file mode 100644
index 0000000000..dd207bd325
--- /dev/null
+++ b/packages/cli/package.json
@@ -0,0 +1,23 @@
+{
+ "name": "@docmirror/dev-sidecar-cli",
+ "version": "1.8.9",
+ "private": false,
+ "description": "给开发者的加速代理工具",
+ "author": "docmirror.cn",
+ "license": "MPL-2.0",
+ "keywords": [
+ "dev-sidecar",
+ "github加速",
+ "google加速",
+ "代理"
+ ],
+ "bin": "./cli.js",
+ "main": "src/index.js",
+ "scripts": {
+ "start": "node ./src"
+ },
+ "dependencies": {
+ "@docmirror/dev-sidecar": "workspace:*",
+ "@docmirror/mitmproxy": "workspace:*"
+ }
+}
diff --git a/packages/core/start/banner.txt b/packages/cli/src/banner.txt
similarity index 100%
rename from packages/core/start/banner.txt
rename to packages/cli/src/banner.txt
diff --git a/packages/core/start/index.js b/packages/cli/src/index.js
similarity index 67%
rename from packages/core/start/index.js
rename to packages/cli/src/index.js
index b41aaae7da..9385f4816c 100644
--- a/packages/core/start/index.js
+++ b/packages/cli/src/index.js
@@ -1,19 +1,18 @@
const fs = require('fs')
const jsonApi = require('@docmirror/mitmproxy/src/json')
-const DevSidecar = require('../index')
-const log = require('../src/utils/util.log')
+const DevSidecar = require('@docmirror/dev-sidecar')
// 启动服务
-const mitmproxyPath = './start/mitmproxy'
+const mitmproxyPath = './src/mitmproxy'
async function startup () {
- const banner = fs.readFileSync('./start/banner.txt')
+ const banner = fs.readFileSync('./src/banner.txt')
console.log(banner.toString())
- const configPath = './start/user_config.json5'
+ const configPath = './src/user_config.json5'
if (fs.existsSync(configPath)) {
const file = fs.readFileSync(configPath)
const userConfig = jsonApi.parse(file.toString())
- log.info('读取 user_config.json5 成功:', configPath)
+ console.info('读取 user_config.json5 成功:', configPath)
DevSidecar.api.config.set(userConfig)
}
diff --git a/packages/core/start/mitmproxy.js b/packages/cli/src/mitmproxy.js
similarity index 100%
rename from packages/core/start/mitmproxy.js
rename to packages/cli/src/mitmproxy.js
diff --git a/packages/core/start/user_config.json5 b/packages/cli/src/user_config.json5
similarity index 100%
rename from packages/core/start/user_config.json5
rename to packages/cli/src/user_config.json5
diff --git a/packages/core/package.json b/packages/core/package.json
index c38a4ce0d1..add351c7dc 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -13,7 +13,6 @@
],
"main": "src/index.js",
"scripts": {
- "start": "node ./start",
"test": "mocha"
},
"dependencies": {
@@ -26,7 +25,6 @@
"winreg": "^1.2.5"
},
"devDependencies": {
- "@docmirror/mitmproxy": "workspace:*",
"chai": "^4.3.4",
"mocha": "^8.2.1"
}
From feddcc52571c3aa76d926a8894ab5b1c5231c236 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 10:08:39 +0800
Subject: [PATCH 06/20] upgrade deps
---
packages/cli/cli.js | 0
packages/mitmproxy/package.json | 5 +++--
packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js | 4 +---
3 files changed, 4 insertions(+), 5 deletions(-)
mode change 100644 => 100755 packages/cli/cli.js
diff --git a/packages/cli/cli.js b/packages/cli/cli.js
old mode 100644
new mode 100755
diff --git a/packages/mitmproxy/package.json b/packages/mitmproxy/package.json
index 8fa36a85ef..c281102d33 100644
--- a/packages/mitmproxy/package.json
+++ b/packages/mitmproxy/package.json
@@ -15,17 +15,18 @@
"agentkeepalive": "^4.5.0",
"axios": "^1.7.7",
"baidu-aip-sdk": "^4.16.16",
- "crypto-js": "^4.0.0",
"dns-over-http": "^0.2.0",
"dns-over-tls": "^0.0.9",
"is-browser": "^2.1.0",
"json5": "^2.2.3",
"lodash": "^4.17.20",
"lru-cache": "^6.0.0",
- "mkdirp": "^0.5.1",
"node-forge": "^1.3.1",
"stream-throttle": "^0.1.3",
"through2": "^4.0.2",
"tunnel-agent": "^0.6.0"
+ },
+ "devDependencies": {
+ "crypto-js": "^4.2.0"
}
}
diff --git a/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js b/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
index df9535ed19..ee4a97fe92 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
@@ -1,7 +1,6 @@
const fs = require('fs')
const path = require('path')
const _ = require('lodash')
-const mkdirp = require('mkdirp')
const forge = require('node-forge')
const log = require('../../../utils/util.log')
const config = require('../common/config')
@@ -253,8 +252,7 @@ utils.initCA = function ({ caCertPath, caKeyPath }) {
const certPem = pki.certificateToPem(caCert)
const keyPem = pki.privateKeyToPem(cakey)
-
- mkdirp.sync(path.dirname(caCertPath))
+ fs.mkdirSync(path.dirname(caCertPath), { recursive: true })
fs.writeFileSync(caCertPath, certPem)
fs.writeFileSync(caKeyPath, keyPem)
log.info('生成证书文件成功,共2个文件:', caCertPath, caKeyPath)
From 609c9c782dc060669e0cf143ffbd4cd3363d1a08 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 10:43:58 +0800
Subject: [PATCH 07/20] upgrade deps
---
packages/mitmproxy/package.json | 2 +-
packages/mitmproxy/src/lib/choice/index.js | 6 ++++--
packages/mitmproxy/src/lib/dns/base.js | 6 ++++--
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/packages/mitmproxy/package.json b/packages/mitmproxy/package.json
index c281102d33..f5a17cf07e 100644
--- a/packages/mitmproxy/package.json
+++ b/packages/mitmproxy/package.json
@@ -20,7 +20,7 @@
"is-browser": "^2.1.0",
"json5": "^2.2.3",
"lodash": "^4.17.20",
- "lru-cache": "^6.0.0",
+ "lru-cache": "^7.15.0",
"node-forge": "^1.3.1",
"stream-throttle": "^0.1.3",
"through2": "^4.0.2",
diff --git a/packages/mitmproxy/src/lib/choice/index.js b/packages/mitmproxy/src/lib/choice/index.js
index 701dbd897c..d603c839c6 100644
--- a/packages/mitmproxy/src/lib/choice/index.js
+++ b/packages/mitmproxy/src/lib/choice/index.js
@@ -1,11 +1,13 @@
-const LRU = require('lru-cache')
+const LRUCache = require('lru-cache').default
const log = require('../../utils/util.log')
const cacheSize = 1024
class ChoiceCache {
constructor () {
- this.cache = new LRU(cacheSize)
+ this.cache = new LRUCache({
+ maxSize: cacheSize,
+ })
}
get (key) {
diff --git a/packages/mitmproxy/src/lib/dns/base.js b/packages/mitmproxy/src/lib/dns/base.js
index 487fc53dc1..2e8427d7bd 100644
--- a/packages/mitmproxy/src/lib/dns/base.js
+++ b/packages/mitmproxy/src/lib/dns/base.js
@@ -1,4 +1,4 @@
-const LRU = require('lru-cache')
+const LRUCache = require('lru-cache').default
const log = require('../../utils/util.log')
const { DynamicChoice } = require('../choice/index')
@@ -23,7 +23,9 @@ class IpCache extends DynamicChoice {
module.exports = class BaseDNS {
constructor () {
- this.cache = new LRU(cacheSize)
+ this.cache = new LRUCache({
+ maxSize: cacheSize,
+ })
}
count (hostname, ip, isError = true) {
From 7a7b384dd7f9f75dd6857556a994694ce38083e9 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 11:05:43 +0800
Subject: [PATCH 08/20] upgrade `vue-cli-plugin-electron-builder`
---
packages/gui/package.json | 3 +--
packages/gui/vue.config.js | 9 ++++-----
packages/mitmproxy/src/lib/choice/index.js | 2 +-
packages/mitmproxy/src/lib/dns/base.js | 2 +-
4 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/packages/gui/package.json b/packages/gui/package.json
index f84eda47c2..9add504dc7 100644
--- a/packages/gui/package.json
+++ b/packages/gui/package.json
@@ -8,7 +8,6 @@
},
"license": "MPL-2.0",
"homepage": "https://github.com/docmirror/dev-sidecar",
- "main": "background.js",
"scripts": {
"serve": "vue-cli-service serve",
"lint": "vue-cli-service lint",
@@ -49,7 +48,7 @@
"electron-builder": "^25.0.6",
"electron-icon-builder": "^2.0.1",
"json5-loader": "^4.0.1",
- "vue-cli-plugin-electron-builder": "^2.1.1"
+ "vue-cli-plugin-electron-builder": "^3.0.0-alpha.4"
},
"browserslist": [
"> 1%",
diff --git a/packages/gui/vue.config.js b/packages/gui/vue.config.js
index 9a39c7c760..fcb013f95b 100644
--- a/packages/gui/vue.config.js
+++ b/packages/gui/vue.config.js
@@ -1,14 +1,12 @@
const path = require('path')
const webpack = require('webpack')
+const { defineConfig } = require('@vue/cli-service')
const publishUrl = process.env.VUE_APP_PUBLISH_URL
const publishProvider = process.env.VUE_APP_PUBLISH_PROVIDER
console.log('Publish url:', publishUrl)
-/**
- * @type {import('@vue/cli-service').ProjectOptions}
- */
-module.exports = {
+module.exports = defineConfig({
pages: {
index: {
entry: 'src/main.js',
@@ -35,6 +33,7 @@ module.exports = {
},
pluginOptions: {
electronBuilder: {
+ mainProcessFile: "./src/background.js",
// Ref: https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/1891
customFileProtocol: './',
externals: [
@@ -116,4 +115,4 @@ module.exports = {
},
},
},
-}
+})
diff --git a/packages/mitmproxy/src/lib/choice/index.js b/packages/mitmproxy/src/lib/choice/index.js
index d603c839c6..964c2c6ff5 100644
--- a/packages/mitmproxy/src/lib/choice/index.js
+++ b/packages/mitmproxy/src/lib/choice/index.js
@@ -1,4 +1,4 @@
-const LRUCache = require('lru-cache').default
+const LRUCache = require('lru-cache')
const log = require('../../utils/util.log')
const cacheSize = 1024
diff --git a/packages/mitmproxy/src/lib/dns/base.js b/packages/mitmproxy/src/lib/dns/base.js
index 2e8427d7bd..14d2ca2041 100644
--- a/packages/mitmproxy/src/lib/dns/base.js
+++ b/packages/mitmproxy/src/lib/dns/base.js
@@ -1,4 +1,4 @@
-const LRUCache = require('lru-cache').default
+const LRUCache = require('lru-cache')
const log = require('../../utils/util.log')
const { DynamicChoice } = require('../choice/index')
From 352fb918830e219c449b1e19203b523d42265720 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 11:16:54 +0800
Subject: [PATCH 09/20] eslint config
---
eslint.config.js | 15 +++++++++++++++
package.json | 10 +++++++++-
packages/core/.babelrc | 3 ---
packages/core/.eslintignore | 1 -
4 files changed, 24 insertions(+), 5 deletions(-)
create mode 100644 eslint.config.js
delete mode 100644 packages/core/.babelrc
delete mode 100644 packages/core/.eslintignore
diff --git a/eslint.config.js b/eslint.config.js
new file mode 100644
index 0000000000..4850b4c99a
--- /dev/null
+++ b/eslint.config.js
@@ -0,0 +1,15 @@
+import antfu from '@antfu/eslint-config'
+
+export default antfu({
+ vue: {
+ vueVersion: 2,
+ },
+ rules: {
+ "style/space-before-function-paren": ["error", "always"],
+ "no-console": 'off'
+ },
+ isInEditor: true,
+ ignore: [
+ '**/test/**',
+ ]
+})
diff --git a/package.json b/package.json
index dbf8815a40..97cd1b6f99 100644
--- a/package.json
+++ b/package.json
@@ -3,5 +3,13 @@
"packageManager": "pnpm@9.13.2",
"private": false,
"author": "Greper",
- "license": "MPL-2.0"
+ "license": "MPL-2.0",
+ "devDependencies": {
+ "eslint": "^9.15.0",
+ "@antfu/eslint-config": "^3.9.1"
+ },
+ "scripts": {
+ "lint": "eslint .",
+ "lint:fix": "eslint . --fix"
+ }
}
diff --git a/packages/core/.babelrc b/packages/core/.babelrc
deleted file mode 100644
index ae733f4770..0000000000
--- a/packages/core/.babelrc
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "presets": ["es2020","stage-4"]
-}
\ No newline at end of file
diff --git a/packages/core/.eslintignore b/packages/core/.eslintignore
deleted file mode 100644
index 3d9ba84a28..0000000000
--- a/packages/core/.eslintignore
+++ /dev/null
@@ -1 +0,0 @@
-./src/test
From 47608ffef9b4cda1ca4288b6779c0c9d1c8718a3 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 11:22:02 +0800
Subject: [PATCH 10/20] eslint config
---
eslint.config.js | 7 ++++++-
package.json | 4 +++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/eslint.config.js b/eslint.config.js
index 4850b4c99a..9a053aab0d 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -11,5 +11,10 @@ export default antfu({
isInEditor: true,
ignore: [
'**/test/**',
- ]
+ ],
+ formatters: {
+ css: true,
+ html: true,
+ markdown: 'prettier',
+ }
})
diff --git a/package.json b/package.json
index 97cd1b6f99..0f90ace8a1 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,14 @@
{
"name": "dev-sidecar-parent",
+ "type": "module",
"packageManager": "pnpm@9.13.2",
"private": false,
"author": "Greper",
"license": "MPL-2.0",
"devDependencies": {
"eslint": "^9.15.0",
- "@antfu/eslint-config": "^3.9.1"
+ "@antfu/eslint-config": "^3.9.1",
+ "eslint-plugin-format": "^0.1.2"
},
"scripts": {
"lint": "eslint .",
From 64795cc50966f6461c1a406a3f9caedf74d2b52d Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 11:43:07 +0800
Subject: [PATCH 11/20] lint all files
---
.github/ISSUE_TEMPLATE/1_BUG_REPORT.md | 7 +
.github/ISSUE_TEMPLATE/2_STYLE_ISSUE.md | 2 +
.github/ISSUE_TEMPLATE/3_CONFIG_ISSUES.md | 4 +
.github/ISSUE_TEMPLATE/4_FEATURE_REQUEST.md | 3 +
.github/PULL_REQUEST_TEMPLATE.md | 2 +
.github/workflows/build-and-release.yml | 20 +-
.github/workflows/test-and-upload.yml | 16 +-
README.md | 176 +++----
doc/caroot.md | 7 +-
doc/linux.md | 35 +-
doc/other.md | 14 +-
doc/recover.md | 10 +-
eslint.config.js | 14 +-
package.json | 12 +-
packages/cli/package.json | 2 +-
packages/cli/src/index.js | 4 +-
packages/cli/src/mitmproxy.js | 7 +-
packages/core/package.json | 2 +-
packages/core/src/config.js | 46 +-
packages/core/src/config/index.js | 2 +-
packages/core/src/config/remote_config.json5 | 448 +++++++++---------
packages/core/src/expose.js | 24 +-
packages/core/src/modules/plugin/git/index.js | 9 +-
.../core/src/modules/plugin/node/index.js | 12 +-
.../core/src/modules/plugin/overwall/index.js | 3 +-
packages/core/src/modules/plugin/pip/index.js | 3 +-
packages/core/src/modules/proxy/index.js | 3 +-
packages/core/src/modules/server/index.js | 18 +-
.../src/shell/scripts/extra-path/index.js | 2 +-
.../shell/scripts/set-system-proxy/index.js | 59 ++-
packages/core/src/shell/shell.js | 23 +-
packages/core/src/shell/test.js | 2 +-
packages/core/src/utils/util.logger.js | 12 +-
packages/core/test/httpsVerifyTest.js | 2 +-
packages/gui/README.md | 5 +
packages/gui/babel.config.js | 4 +-
packages/gui/pkg/after-all-artifact-build.js | 4 +-
packages/gui/pkg/after-pack.js | 10 +-
packages/gui/public/index.html | 24 +-
packages/gui/src/background.js | 56 ++-
packages/gui/src/background/powerMonitor.js | 12 +-
packages/gui/src/bridge/api/backend.js | 11 +-
packages/gui/src/bridge/auto-start/backend.js | 12 +-
packages/gui/src/bridge/auto-start/front.js | 3 +-
packages/gui/src/bridge/error/front.js | 3 +-
.../gui/src/bridge/file-selector/backend.js | 3 +-
.../gui/src/bridge/file-selector/front.js | 3 +-
packages/gui/src/bridge/mitmproxy.js | 4 +-
packages/gui/src/bridge/update/backend.js | 49 +-
packages/gui/src/bridge/update/front.js | 48 +-
packages/gui/src/utils/util.apppath.js | 4 +-
packages/gui/src/view/App.vue | 46 +-
.../gui/src/view/components/container.vue | 34 +-
packages/gui/src/view/components/setup-ca.vue | 6 +-
packages/gui/src/view/mixins/plugin.js | 9 +-
packages/gui/src/view/pages/index.vue | 20 +-
packages/gui/src/view/pages/plugin/git.vue | 11 +-
packages/gui/src/view/pages/plugin/node.vue | 8 +-
.../gui/src/view/pages/plugin/overwall.vue | 8 +-
packages/gui/src/view/pages/plugin/pip.vue | 8 +-
packages/gui/src/view/pages/proxy.vue | 19 +-
packages/gui/src/view/pages/server.vue | 18 +-
packages/gui/src/view/pages/setting.vue | 28 +-
packages/gui/src/view/style/index.scss | 101 ++--
packages/gui/src/view/style/theme/dark.scss | 98 ++--
packages/gui/vue.config.js | 6 +-
packages/mitmproxy/src/index.js | 12 +-
packages/mitmproxy/src/json.js | 9 +-
packages/mitmproxy/src/lib/choice/index.js | 6 +-
packages/mitmproxy/src/lib/dns/base.js | 6 +-
packages/mitmproxy/src/lib/dns/https.js | 11 +-
packages/mitmproxy/src/lib/dns/index.js | 6 +-
packages/mitmproxy/src/lib/dns/ipaddress.js | 2 +-
packages/mitmproxy/src/lib/dns/preset.js | 3 +-
.../src/lib/interceptor/impl/req/OPTIONS.js | 3 +-
.../src/lib/interceptor/impl/req/baiduOcr.js | 12 +-
.../src/lib/interceptor/impl/req/cacheReq.js | 3 +-
.../src/lib/interceptor/impl/req/proxy.js | 14 +-
.../interceptor/impl/req/requestReplace.js | 3 +-
.../src/lib/interceptor/impl/res/cacheRes.js | 21 +-
.../interceptor/impl/res/responseReplace.js | 3 +-
.../src/lib/interceptor/impl/res/script.js | 21 +-
.../mitmproxy/src/lib/interceptor/index.js | 24 +-
packages/mitmproxy/src/lib/monkey/index.js | 24 +-
.../mitmproxy/src/lib/proxy/common/config.js | 2 +-
.../mitmproxy/src/lib/proxy/common/util.js | 32 +-
.../src/lib/proxy/compatible/compatible.js | 16 +-
.../middleware/InsertScriptMiddleware.js | 8 +-
.../src/lib/proxy/middleware/overwall.js | 38 +-
.../src/lib/proxy/middleware/source/pac.js | 7 +-
.../proxy/mitmproxy/createConnectHandler.js | 13 +-
.../proxy/mitmproxy/createFakeServerCenter.js | 5 +-
.../proxy/mitmproxy/createRequestHandler.js | 40 +-
.../proxy/mitmproxy/createUpgradeHandler.js | 4 +-
.../src/lib/proxy/mitmproxy/dnsLookup.js | 11 +-
.../src/lib/proxy/mitmproxy/index.js | 5 +-
.../src/lib/proxy/tls/CertAndKeyContainer.js | 3 +-
.../src/lib/proxy/tls/FakeServersCenter.js | 21 +-
.../mitmproxy/src/lib/proxy/tls/sniUtil.js | 6 +-
.../mitmproxy/src/lib/proxy/tls/tlsUtils.js | 7 +-
.../mitmproxy/src/lib/speed/SpeedTester.js | 5 +-
packages/mitmproxy/src/lib/speed/index.js | 3 +-
packages/mitmproxy/src/options.js | 16 +-
packages/mitmproxy/src/utils/util.match.js | 9 +-
.../impl/res/responseReplaceTest.js | 17 +-
packages/mitmproxy/test/proxyTest.js | 2 +-
test/test.js | 3 +-
107 files changed, 1275 insertions(+), 861 deletions(-)
diff --git a/.github/ISSUE_TEMPLATE/1_BUG_REPORT.md b/.github/ISSUE_TEMPLATE/1_BUG_REPORT.md
index a6531d319d..c2f7066c88 100644
--- a/.github/ISSUE_TEMPLATE/1_BUG_REPORT.md
+++ b/.github/ISSUE_TEMPLATE/1_BUG_REPORT.md
@@ -5,9 +5,11 @@ labels: Bug
---
+
- [ ] 你是否在现有 [Issue列表](/docmirror/dev-sidecar/issues) 中搜索过相同问题,但未找到?
### Ⅰ. 请说明操作系统及DS的版本号:
+
1. 操作系统:?
2. DS版本号:?
@@ -22,10 +24,15 @@ labels: Bug
3. xxx
### Ⅴ. 请提供相关的错误日志,尽可能的详细:(日志文件在 `${user.home}/.dev-sidecar/logs/` 目录下)
+
```log
+
```
### Ⅵ. 有必要时,请提供 `${user.home}/.dev-sidecar/running.json` 文件内容:
+
+
```json
+
```
diff --git a/.github/ISSUE_TEMPLATE/2_STYLE_ISSUE.md b/.github/ISSUE_TEMPLATE/2_STYLE_ISSUE.md
index 566013ae3a..76fc08abfe 100644
--- a/.github/ISSUE_TEMPLATE/2_STYLE_ISSUE.md
+++ b/.github/ISSUE_TEMPLATE/2_STYLE_ISSUE.md
@@ -5,9 +5,11 @@ labels: Style Issue
---
+
- [ ] 你是否在现有 [Issue列表](/docmirror/dev-sidecar/issues) 中搜索过相同问题,但未找到?
### Ⅰ. 请说明操作系统及DS的版本号:
+
1. 操作系统:?
2. DS版本号:?
diff --git a/.github/ISSUE_TEMPLATE/3_CONFIG_ISSUES.md b/.github/ISSUE_TEMPLATE/3_CONFIG_ISSUES.md
index c38ffc8846..cdfaa26c83 100644
--- a/.github/ISSUE_TEMPLATE/3_CONFIG_ISSUES.md
+++ b/.github/ISSUE_TEMPLATE/3_CONFIG_ISSUES.md
@@ -5,6 +5,7 @@ labels: Config Issue
---
### Ⅰ. 你对哪个功能的配置不了解?
+
- [ ] 拦截设置:
@@ -28,6 +29,9 @@ labels: Config Issue
### Ⅱ. 请详细描述你的问题:
### Ⅲ. 有必要时,请提供 `${user.home}/.dev-sidecar/running.json` 文件内容:
+
+
```json
+
```
diff --git a/.github/ISSUE_TEMPLATE/4_FEATURE_REQUEST.md b/.github/ISSUE_TEMPLATE/4_FEATURE_REQUEST.md
index 02d91fcdc6..31e9254258 100644
--- a/.github/ISSUE_TEMPLATE/4_FEATURE_REQUEST.md
+++ b/.github/ISSUE_TEMPLATE/4_FEATURE_REQUEST.md
@@ -5,10 +5,13 @@ labels: Feature Request
---
### Ⅰ. 请描述你想要的新功能:
+
### Ⅱ. 请描述你心目中新功能的样子:
+
### Ⅲ. 你希望该新功能修复哪个issue?
+
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index 78a409bb74..8a64ff3058 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -1,7 +1,9 @@
### Ⅰ. 描述此PR的作用:
### Ⅱ. 此PR修复了哪个issue吗?
+
### Ⅲ. 界面变化截屏
+
diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml
index d456f4bf02..92405f2cef 100644
--- a/.github/workflows/build-and-release.yml
+++ b/.github/workflows/build-and-release.yml
@@ -1,4 +1,4 @@
-name: 'Build And Release'
+name: Build And Release
on:
push:
@@ -21,7 +21,7 @@ jobs:
node:
- 22
steps:
- - name: 'Checkout'
+ - name: Checkout
uses: actions/checkout@v4.1.7
- name: 'Setup Node.js "${{ matrix.node }}.x" environment'
@@ -30,22 +30,22 @@ jobs:
node-version: ${{ matrix.node }}
registry-url: https://npm.pkg.github.com/
- - name: 'Setup pnpm'
+ - name: Setup pnpm
uses: pnpm/action-setup@v4
- - name: 'Setup Python environment (Mac) Because of electron-builder install-app-deps requires Python setup tools'
+ - name: Setup Python environment (Mac) Because of electron-builder install-app-deps requires Python setup tools
if: matrix.os == 'macos'
uses: actions/setup-python@v5
with:
python-version: '3.10'
- - name: 'Get package info'
+ - name: Get package info
id: package-info
uses: luizfelipelaviola/get-package-info@v1
with:
path: ./packages/mitmproxy
- - name: 'Print'
+ - name: Print
run: |
echo "version = ${{ steps.package-info.outputs.version }}";
echo "github.ref_type = ${{ github.ref_type }}";
@@ -69,7 +69,7 @@ jobs:
echo "--------------------";
python --version;
- - name: 'pnpm install'
+ - name: pnpm install
run: |
echo "======================================================================";
dir || ls -lah;
@@ -139,10 +139,10 @@ jobs:
needs:
- build-and-upload
steps:
- - name: 'Checkout'
+ - name: Checkout
uses: actions/checkout@v4.1.7
- - name: 'Get package info'
+ - name: Get package info
id: package-info
uses: luizfelipelaviola/get-package-info@v1
with:
@@ -177,7 +177,7 @@ jobs:
run: |
ls -lah release;
- - name: 'Create a draft release'
+ - name: Create a draft release
uses: wangliang181230/github-action-ghr@master
env:
GITHUB_TOKEN: ${{ github.token }}
diff --git a/.github/workflows/test-and-upload.yml b/.github/workflows/test-and-upload.yml
index c48449dbe3..cc3cb0e9cb 100644
--- a/.github/workflows/test-and-upload.yml
+++ b/.github/workflows/test-and-upload.yml
@@ -1,10 +1,10 @@
-name: 'Test And Upload'
+name: Test And Upload
on:
push:
branches:
- master
- - '1.x'
+ - 1.x
pull_request:
branches:
- master
@@ -22,7 +22,7 @@ jobs:
node:
- 22
steps:
- - name: 'Checkout'
+ - name: Checkout
uses: actions/checkout@v4.1.7
- name: 'Setup Node.js "${{ matrix.node }}.x" environment'
@@ -31,22 +31,22 @@ jobs:
node-version: ${{ matrix.node }}
registry-url: https://npm.pkg.github.com/
- - name: 'Setup pnpm'
+ - name: Setup pnpm
uses: pnpm/action-setup@v4
- - name: 'Setup Python environment (Mac) Because of electron-builder install-app-deps requires Python setup tools'
+ - name: Setup Python environment (Mac) Because of electron-builder install-app-deps requires Python setup tools
if: matrix.os == 'macos'
uses: actions/setup-python@v5
with:
python-version: '3.10'
- - name: 'Get package info'
+ - name: Get package info
id: package-info
uses: luizfelipelaviola/get-package-info@v1
with:
path: ./packages/mitmproxy
- - name: 'Print'
+ - name: Print
run: |
echo "version = ${{ steps.package-info.outputs.version }}";
echo "github.ref_type = ${{ github.ref_type }}";
@@ -70,7 +70,7 @@ jobs:
echo "--------------------";
python --version;
- - name: 'pnpm install'
+ - name: pnpm install
run: |
echo "======================================================================";
dir || ls -lah;
diff --git a/README.md b/README.md
index 94fd263624..d7c4f9efd6 100644
--- a/README.md
+++ b/README.md
@@ -5,80 +5,77 @@
->
> Gitee上的同步项目已被封禁,此项目将不再更新与维护 【狗头保命】
>
> 我将继续奋战在开源一线,为社区贡献更多更好的开源项目。
-> 感兴趣的可以关注我的主页 [【github】](https://github.com/greper) [【gitee】](https://gitee.com/greper)
->
+> 感兴趣的可以关注我的主页 [【github】](https://github.com/greper) [【gitee】](https://gitee.com/greper)
+
## 打个广告
->
+
>
> 我的开源证书管理工具项目,全自动申请和部署证书,有需求的可以去试试,帮忙点个star
## 重要提醒
->
+
> ------------------------------重要提醒1---------------------------------
>
> 注意:由于electron无法监听windows的关机事件,开着ds情况下直接重启电脑,会导致无法上网,你可以手动启动ds即可恢复网络,你也可以将ds设置为开机自启。
>
> 关于此问题的更多讨论请前往:
>
->
> ------------------------------重要提醒2---------------------------------
>
> 注意:本应用启动会自动修改系统代理,所以会与其他代理软件有冲突,请务必不要一起使用。
> 本应用主要目的在于直连访问github,如果你已经有飞机了,那建议还是不要用这个自行车(ds)了
->
## 一、 特性
-### 1.1、 dns优选(解决***污染问题)
+### 1.1、 dns优选(解决\*\*\*污染问题)
-* 根据网络状况智能解析最佳域名ip地址,获取最佳网络速度
-* 解决一些网站和库无法访问或访问速度慢的问题
-* 建议遇到打开比较慢的国外网站,可以优先尝试将该域名添加到dns设置中(注意:被***封杀的无效)
+- 根据网络状况智能解析最佳域名ip地址,获取最佳网络速度
+- 解决一些网站和库无法访问或访问速度慢的问题
+- 建议遇到打开比较慢的国外网站,可以优先尝试将该域名添加到dns设置中(注意:被\*\*\*封杀的无效)
### 1.2、 请求拦截
-* 拦截打不开的网站,代理到加速镜像站点上去。
-* 可配置多个镜像站作为备份
-* 具备测速机制,当访问失败或超时之后,自动切换到备用站点,使得目标服务高可用
+- 拦截打不开的网站,代理到加速镜像站点上去。
+- 可配置多个镜像站作为备份
+- 具备测速机制,当访问失败或超时之后,自动切换到备用站点,使得目标服务高可用
### 1.3、 github加速
-* github 直连加速 (通过修改sni实现,感谢 [fastGithub](https://github.com/dotnetcore/FastGithub) 提供的思路)
-* release、source、zip下载加速
-* clone 加速
-* 头像加速
-* 解决readme中图片引用无法加载的问题
-* gist.github.com 加速
-* 解决git push 偶尔失败需要输入账号密码的问题(fatal: TaskCanceledException encountered / fatal: HttpRequestException encountered)
-* raw/blame加速
+- github 直连加速 (通过修改sni实现,感谢 [fastGithub](https://github.com/dotnetcore/FastGithub) 提供的思路)
+- release、source、zip下载加速
+- clone 加速
+- 头像加速
+- 解决readme中图片引用无法加载的问题
+- gist.github.com 加速
+- 解决git push 偶尔失败需要输入账号密码的问题(fatal: TaskCanceledException encountered / fatal: HttpRequestException encountered)
+- raw/blame加速
> 以上部分功能通过`X.I.U`的油猴脚本实现, 以下是仓库和脚本下载链接,大家可以去支持一下。
>
-> *
-> *
+> -
+> -
>
> 由于此脚本在ds中是打包在本地的,更新会不及时,你可以直接通过浏览器安装油猴插件使用此脚本,从而获得最新更新(ds本地的可以通过`加速服务->基本设置->启用脚本`进行关闭)。
### 1.4、 Stack Overflow 加速
-* 将ajax.google.com代理到加速CDN上
-* recaptcha 图片验证码加速
+- 将ajax.google.com代理到加速CDN上
+- recaptcha 图片验证码加速
### 1.5、 npm加速
-* 支持开启npm代理
-* 官方与淘宝npm registry一键切换,
-* 某些npm install的时候,并且使用cnpm也无法安装时,可以尝试开启npm代理再试
+- 支持开启npm代理
+- 官方与淘宝npm registry一键切换,
+- 某些npm install的时候,并且使用cnpm也无法安装时,可以尝试开启npm代理再试
-***安全警告***:
+**_安全警告_**:
-* 请勿使用来源不明的服务地址,有隐私和账号泄露风险
-* 本应用及服务端承诺不收集任何信息。介意者请使用安全模式。
+- 请勿使用来源不明的服务地址,有隐私和账号泄露风险
+- 本应用及服务端承诺不收集任何信息。介意者请使用安全模式。
## 二、快速开始
@@ -88,8 +85,8 @@
#### 1)下载安装包
-* release下载
-[Github Release](https://github.com/docmirror/dev-sidecar/releases)
+- release下载
+ [Github Release](https://github.com/docmirror/dev-sidecar/releases)
> Windows: 请选择DevSidecar-x.x.x.exe
> Mac: 请选择DevSidecar-x.x.x.dmg
@@ -123,50 +120,52 @@
### 2.2、开启前 vs 开启后
-| | 开启前 | 开启后 |
-| ---- | ---- | ---- |
-|头像| ![](./doc/avatar2.png) |![](./doc/avatar1.png) |
-|clone |![](./doc/clone-before.png) |![](./doc/clone.png) |
-|zip 下载 |![](./doc/download-before.png) |![](./doc/download.png)秒下的,实在截不到速度的图 |
+| | 开启前 | 开启后 |
+| -------- | ------------------------------ | ------------------------------------------------- |
+| 头像 | ![](./doc/avatar2.png) | ![](./doc/avatar1.png) |
+| clone | ![](./doc/clone-before.png) | ![](./doc/clone.png) |
+| zip 下载 | ![](./doc/download-before.png) | ![](./doc/download.png)秒下的,实在截不到速度的图 |
## 三、模式说明
### 3.1、安全模式
-* 此模式:关闭拦截、关闭增强、开启dns优选、开启测速
-* 最安全,无需安装证书,可以在浏览器地址栏左侧查看域名证书
-* 功能也最弱,只有特性1,相当于查询github的国外ip,手动改hosts一个意思。
-* github的可访问性不稳定,取决于IP测速,如果有绿色ip存在,就 `有可能` 可以直连访问。
+- 此模式:关闭拦截、关闭增强、开启dns优选、开启测速
+- 最安全,无需安装证书,可以在浏览器地址栏左侧查看域名证书
+- 功能也最弱,只有特性1,相当于查询github的国外ip,手动改hosts一个意思。
+- github的可访问性不稳定,取决于IP测速,如果有绿色ip存在,就 `有可能` 可以直连访问。
![](./doc/speed.png)
### 3.2、默认模式
-* 此模式:开启拦截、关闭增强、开启dns优选、开启测速
-* 需要安装证书,通过修改sni直连访问github
-* 功能上包含特性1/2/3/4。
+- 此模式:开启拦截、关闭增强、开启dns优选、开启测速
+- 需要安装证书,通过修改sni直连访问github
+- 功能上包含特性1/2/3/4。
## 四、 最佳实践
-* 把dev-sidecar一直开着就行了(注意windows下开着ds重启电脑,会无法上网,重新打开ds即可。)
-* 建议遇到打开比较慢的国外网站,可以尝试将该域名添加到dns设置中(注意:被***封杀的无效)
+- 把dev-sidecar一直开着就行了(注意windows下开着ds重启电脑,会无法上网,重新打开ds即可。)
+- 建议遇到打开比较慢的国外网站,可以尝试将该域名添加到dns设置中(注意:被\*\*\*封杀的无效)
### 其他加速
#### 1)git clone 加速
- 方式1:快捷复制:
- > 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接
+方式1:快捷复制:
+
+> 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接
+
+方式2:
- 方式2:
- > 使用方式用实际的名称替换{}的内容,即可加速clone
- >
- > clone 出来的 remote "origin" 为fastgit的地址,需要手动改回来
- > 你也可以直接使用他们的clone加速工具 [fgit-go](https://github.com/FastGitORG/fgit-go)
+> 使用方式用实际的名称替换{}的内容,即可加速clone
+>
+> clone 出来的 remote "origin" 为fastgit的地址,需要手动改回来
+> 你也可以直接使用他们的clone加速工具 [fgit-go](https://github.com/FastGitORG/fgit-go)
#### 2)github.com的镜像网站(注意:不能登录)
- >
- > 1. [hub.fastgit.org](https://hub.fastgit.org/)
- > 2. [github.com.cnpmjs.org](https://github.com.cnpmjs.org/) 这个很容易超限
+
+> 1. [hub.fastgit.org](https://hub.fastgit.org/)
+> 2. [github.com.cnpmjs.org](https://github.com.cnpmjs.org/) 这个很容易超限
## 五、api
@@ -252,16 +251,16 @@ networksetup -setwebproxy 'WiFi' 127.0.0.1 31181
如果有上面的错误提示,请尝试如下方法:
->取消访问偏好设置需要管理员密码
->系统偏好设置—>安全性与隐私—> 通用—> 高级—> 访问系统范围的偏好设置需要输入管理员密码(取消勾选)
+> 取消访问偏好设置需要管理员密码
+> 系统偏好设置—>安全性与隐私—> 通用—> 高级—> 访问系统范围的偏好设置需要输入管理员密码(取消勾选)
### 6.2、没有加速效果
->本应用仅支持https加速,请务必确认你访问的网站地址是https开头的
+> 本应用仅支持https加速,请务必确认你访问的网站地址是https开头的
1. 本应用仅支持https加速
-请务必确认你访问的地址是https开头的
-比如:
+ 请务必确认你访问的地址是https开头的
+ 比如:
2. 检查浏览器是否装了什么插件,与ds有冲突
@@ -269,10 +268,10 @@ networksetup -setwebproxy 'WiFi' 127.0.0.1 31181
4. 请确认浏览器的代理设置为使用IE代理/或者使用系统代理状态
-6. 可以尝试换个浏览器试试
+5. 可以尝试换个浏览器试试
-7. 请确认网络代理设置处于勾选状态
-正常情况下ds在“系统代理”开关打开时,会自动设置系统代理。
+6. 请确认网络代理设置处于勾选状态
+ 正常情况下ds在“系统代理”开关打开时,会自动设置系统代理。
### 6.3、浏览器打开提示证书不受信任
@@ -293,8 +292,7 @@ networksetup -setwebproxy 'WiFi' 127.0.0.1 31181
### 6.4、打开github显示连接超时
```html
-DevSidecar Warning:
-Error: www.github.com:443, 代理请求超时
+DevSidecar Warning: Error: www.github.com:443, 代理请求超时
```
1、检查测速界面github.com是否有ip ,如果没有ip,则可能是由于你的网络提供商封锁了dns服务商的ip(试试能否ping通:1.1.1.1 / 9.9.9.9 )
@@ -303,8 +301,8 @@ Error: www.github.com:443, 代理请求超时
### 6.5、查看日志是否有报错
- 如果还是不行,请在下方加作者好友,将服务日志发送给作者进行分析
- 日志打开方式:加速服务->右边日志按钮->打开日志文件夹
+如果还是不行,请在下方加作者好友,将服务日志发送给作者进行分析
+日志打开方式:加速服务->右边日志按钮->打开日志文件夹
![](./doc/log.png)
@@ -318,10 +316,10 @@ Error: www.github.com:443, 代理请求超时
应用开启后会自动修改系统代理设置,正常退出会自动关闭系统代理
当应用意外关闭时,可能会因为没有将系统代理恢复,从而导致完全无法上网。
- 对于此问题有如下几种解决方案可供选择:
- 1、重新打开应用即可(右键应用托盘图标可完全退出,将会正常关闭系统代理设置)
- 2、如果应用被卸载了,此时需要[手动关闭系统代理设置](./doc/recover.md)
- 3、如果你是因为开着ds的情况下重启电脑导致无法上网,你可以设置ds为开机自启
+对于此问题有如下几种解决方案可供选择:
+1、重新打开应用即可(右键应用托盘图标可完全退出,将会正常关闭系统代理设置)
+2、如果应用被卸载了,此时需要[手动关闭系统代理设置](./doc/recover.md)
+3、如果你是因为开着ds的情况下重启电脑导致无法上网,你可以设置ds为开机自启
### 6.8、卸载应用后上不了网,git请求不了
@@ -345,7 +343,7 @@ npm config delete https-proxy
## 七、在其他程序使用
-* [java程序使用](./doc/other.md#Java程序使用)
+- [java程序使用](./doc/other.md#Java程序使用)
## 八、贡献代码
@@ -358,6 +356,7 @@ npm config delete https-proxy
#### 2)安装 `lerna`
运行如下命令即可安装所需依赖:
+
> 注:lerna指定为6.x版本,更高版本会导致打包失败(不兼容导致)
```shell
@@ -407,19 +406,20 @@ npm run electron:build
欢迎bug反馈,需求建议,技术交流等
1、 加群(请备注dev-sidecar,或简称DS)
-* QQ 1群:390691483,人数:500 / 500(满)
-* QQ 2群:[667666069](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=n4nksr4sji93vZtD5e8YEHRT6qbh6VyQ&authKey=XKBZnzmoiJrAFyOT4V%2BCrgX5c13ds59b84g%2FVRhXAIQd%2FlAiilsuwDRGWJct%2B570&noverify=0&group_code=667666069),人数:447 / 500
-* QQ 3群:419807815,人数:500 / 500(满)
-* QQ 4群:[438148299](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=i_NCBB5f_Bkm2JsEV1tLs2TkQ79UlCID&authKey=nMsVJbJ6P%2FGNO7Q6vsVUadXRKnULUURwR8zvUZJnP3IgzhHYPhYdcBCHvoOh8vYr&noverify=0&group_code=438148299),人数:203 / 1000
-* QQ 5群:[767622917](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=nAWi_Rxj7mM4Unp5LMiatmUWhGimtbcB&authKey=aswmlWGjbt3GIWXtvjB2GJqqAKuv7hWjk6UBs3MTb%2Biyvr%2Fsbb1kA9CjF6sK7Hgg&noverify=0&group_code=767622917),人数:016 / 200(new)
+
+- QQ 1群:390691483,人数:500 / 500(满)
+- QQ 2群:[667666069](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=n4nksr4sji93vZtD5e8YEHRT6qbh6VyQ&authKey=XKBZnzmoiJrAFyOT4V%2BCrgX5c13ds59b84g%2FVRhXAIQd%2FlAiilsuwDRGWJct%2B570&noverify=0&group_code=667666069),人数:447 / 500
+- QQ 3群:419807815,人数:500 / 500(满)
+- QQ 4群:[438148299](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=i_NCBB5f_Bkm2JsEV1tLs2TkQ79UlCID&authKey=nMsVJbJ6P%2FGNO7Q6vsVUadXRKnULUURwR8zvUZJnP3IgzhHYPhYdcBCHvoOh8vYr&noverify=0&group_code=438148299),人数:203 / 1000
+- QQ 5群:[767622917](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=nAWi_Rxj7mM4Unp5LMiatmUWhGimtbcB&authKey=aswmlWGjbt3GIWXtvjB2GJqqAKuv7hWjk6UBs3MTb%2Biyvr%2Fsbb1kA9CjF6sK7Hgg&noverify=0&group_code=767622917),人数:016 / 200(new)
## 十、求star
我的其他项目求star
-* [fast-crud](https://github.com/fast-crud/fast-crud) : 开发crud快如闪电
-* [certd](https://github.com/certd/certd) : 让你的证书永不过期
-* [trident-sync](https://github.com/handsfree-work/trident-sync) : 二次开发项目同步升级工具
+- [fast-crud](https://github.com/fast-crud/fast-crud) : 开发crud快如闪电
+- [certd](https://github.com/certd/certd) : 让你的证书永不过期
+- [trident-sync](https://github.com/handsfree-work/trident-sync) : 二次开发项目同步升级工具
## 十一、感谢
@@ -429,14 +429,14 @@ npm run electron:build
本项目参考如下开源项目
-* [node-mitmproxy](https://github.com/wuchangming/node-mitmproxy)
-* [ReplaceGoogleCDN](https://github.com/justjavac/ReplaceGoogleCDN)
+- [node-mitmproxy](https://github.com/wuchangming/node-mitmproxy)
+- [ReplaceGoogleCDN](https://github.com/justjavac/ReplaceGoogleCDN)
特别感谢
-* [github增强油猴脚本](https://greasyfork.org/zh-CN/scripts/412245-github-%E5%A2%9E%E5%BC%BA-%E9%AB%98%E9%80%9F%E4%B8%8B%E8%BD%BD) 本项目部分加速功能完全复制该脚本。
-* [中国域名白名单](https://github.com/pluwen/china-domain-allowlist),本项目的系统代理排除域名功能中,使用了该白名单。
+- [github增强油猴脚本](https://greasyfork.org/zh-CN/scripts/412245-github-%E5%A2%9E%E5%BC%BA-%E9%AB%98%E9%80%9F%E4%B8%8B%E8%BD%BD) 本项目部分加速功能完全复制该脚本。
+- [中国域名白名单](https://github.com/pluwen/china-domain-allowlist),本项目的系统代理排除域名功能中,使用了该白名单。
本项目部分加速资源由如下组织提供
-* [FastGit UK](https://fastgit.org/)
+- [FastGit UK](https://fastgit.org/)
diff --git a/doc/caroot.md b/doc/caroot.md
index 0c7508888c..e996b965c7 100644
--- a/doc/caroot.md
+++ b/doc/caroot.md
@@ -3,7 +3,9 @@
## 一、为什么要信任根证书。
要回答这个问题需要先掌握下面两个知识点
+
### 知识点1:什么是根证书
+
[百度百科-什么是根证书](https://baike.baidu.com/item/%E6%A0%B9%E8%AF%81%E4%B9%A6/9874620?fr=aladdin)
当访问目标网站是https协议时,服务器会发送一个由根证书签发的网站ssl证书给浏览器,让浏览器用这个ssl证书给数据加密。
@@ -14,6 +16,7 @@
windows、mac、linux或者浏览器他们都内置了市面上可信的大型证书颁发机构的根证书。
### 知识点2:中间人攻击
+
本应用的实现原理如下图:
![](./flow.jpg)
@@ -29,7 +32,7 @@ windows、mac、linux或者浏览器他们都内置了市面上可信的大型
例如加速github就需要修改如下几处
-1. 直连访问github需要修改tls握手时的sni域名,规避***的sni阻断问题。
+1. 直连访问github需要修改tls握手时的sni域名,规避\*\*\*的sni阻断问题。
2. asserts.github.com等静态资源拦截替换成fastgit.org的镜像地址
DevSidecar在第一次启动时会在本地随机生成一份根证书,当有用户访问github时,就用这份根证书来签发一份假的叫github.com的证书。
@@ -50,7 +53,7 @@ DevSidecar在第一次启动时会在本地随机生成一份根证书,当有
> 或者从源码自行编译安装
> 对于拦截配置里的替代网站风险:
+>
> 1. 尽量缩小替代配置的范围
> 2. 不使用来源不明的镜像地址,尽量使用知名度较高的镜像地址
> 3. 你甚至可以将其他拦截配置全部删除,只保留github相关配置
->
diff --git a/doc/linux.md b/doc/linux.md
index 5a2aae504a..5609336cde 100644
--- a/doc/linux.md
+++ b/doc/linux.md
@@ -1,4 +1,5 @@
# linux 支持
+
`linux`使用说明,目前仅支持`ubuntu_x64(GNOME)`,其他`linux`未测试
> 注意:需要开启[sudo免密支持](https://www.jianshu.com/p/5d02428f313d)
@@ -6,30 +7,38 @@
## 安装
### 1. ubuntu
- * 下载`DevSidecar-x.x.x.deb`
- * 执行命令安装 `dpkg -i DevSidecar-x.x.x.deb`
- * 去应用列表里面找到dev-sidecar应用,打开即可
+
+- 下载`DevSidecar-x.x.x.deb`
+- 执行命令安装 `dpkg -i DevSidecar-x.x.x.deb`
+- 去应用列表里面找到dev-sidecar应用,打开即可
### 2. 其他linux系统(未测试)
-* 下载 `DevSidecar-x.x.x.AppImage`
-* 设置可执行权限 `sudo chmod +X DevSidecar-x.x.x.AppImage`
-* 双击运行
+
+- 下载 `DevSidecar-x.x.x.AppImage`
+- 设置可执行权限 `sudo chmod +X DevSidecar-x.x.x.AppImage`
+- 双击运行
## 证书安装
+
默认模式和增强模式需要系统信任CA证书。
由于linux上火狐和chrome都不走系统证书,所以除了安装系统证书之外,还需要给浏览器安装证书
+
### 1. 系统证书安装
+
根据弹出的提示:
- * 点击首页右上角“安装根证书”按钮
- * 点击“点此去安装”
- * 提示安装成功即可
+
+- 点击首页右上角“安装根证书”按钮
+- 点击“点此去安装”
+- 提示安装成功即可
### 2. 火狐浏览器安装证书
-* 火狐浏览器->选项->隐私与安全->证书->查看证书
-* 证书颁发机构->导入
-* 选择证书文件在`~/.dev-sidecar`目录下
-* 勾选信任由此证书颁发机构来标识网站,确定即可
+
+- 火狐浏览器->选项->隐私与安全->证书->查看证书
+- 证书颁发机构->导入
+- 选择证书文件在`~/.dev-sidecar`目录下
+- 勾选信任由此证书颁发机构来标识网站,确定即可
### 3. chrome浏览器安装证书
+
证书文件目录为`~/.dev-sidecar`
![](../packages/gui/public/setup-linux.png)
diff --git a/doc/other.md b/doc/other.md
index 1779fc67b2..4581f272ec 100644
--- a/doc/other.md
+++ b/doc/other.md
@@ -1,13 +1,15 @@
# 其他程序使用
## Java程序使用
- > 由[Enaium](https://github.com/Enaium) 提供,未做验证,可供参考
+
+> 由[Enaium](https://github.com/Enaium) 提供,未做验证,可供参考
>
-需要先通过keytool安装证书
-`keytool -import -alias dev-sidecar -keystore "jdk路径\security\cacerts" -file 用户目录\.dev-sidecar\dev-sidecar.ca.crt`默认密码为`changeit`
-启动时还需要设置参数
-`-Dhttp.proxyHost=localhost -Dhttp.proxyPort=31181 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=31181`
-Gradle还需在`用户目录/.gradle/gradle.properties`创建配置文件
+> 需要先通过keytool安装证书
+> `keytool -import -alias dev-sidecar -keystore "jdk路径\security\cacerts" -file 用户目录\.dev-sidecar\dev-sidecar.ca.crt`默认密码为`changeit`
+> 启动时还需要设置参数
+> `-Dhttp.proxyHost=localhost -Dhttp.proxyPort=31181 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=31181`
+> Gradle还需在`用户目录/.gradle/gradle.properties`创建配置文件
+
```properties
systemProp.http.proxyHost=localhost
systemProp.http.proxyPort=31181
diff --git a/doc/recover.md b/doc/recover.md
index b99a5cd049..7baf4ed012 100644
--- a/doc/recover.md
+++ b/doc/recover.md
@@ -1,20 +1,26 @@
# 卸载与恢复网络
+
由于应用启动后会自动设置系统代理,正常退出时会关闭系统代理。
当应用意外关闭,或者未正常退出后被卸载,此时会因为系统代理没有恢复从而导致完全上不了网。
目前electron在windows系统上无法监听系统重启事件。更多相关资料 [electron issues](https://github.com/electron/electron/pull/24261)
## 恢复代理设置
+
### 1、windows 代理关闭
+
如何打开查看windows代理设置:
-* win10: 开始->设置->网络和Internet->最下方代理
-* win7: 开始->控制面板->网络和Internet->网络和共享中心->左下角Internet选项->连接选项卡->局域网设置
+
+- win10: 开始->设置->网络和Internet->最下方代理
+- win7: 开始->控制面板->网络和Internet->网络和共享中心->左下角Internet选项->连接选项卡->局域网设置
![windows](./proxy.png)
### 2、mac 代理关闭
+
网络->网卡->代理->去掉http和https的两个勾
![](./mac-proxy.png)
### 3、Linux(Ubuntu)
+
网络->代理->选择禁用
diff --git a/eslint.config.js b/eslint.config.js
index 9a053aab0d..b3d5942540 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -5,16 +5,20 @@ export default antfu({
vueVersion: 2,
},
rules: {
- "style/space-before-function-paren": ["error", "always"],
- "no-console": 'off'
+ 'style/space-before-function-paren': ['error', 'always'],
+ 'node/prefer-global/buffer': 'off',
+ 'node/prefer-global/process': 'off',
+ 'no-console': 'off',
},
- isInEditor: true,
ignore: [
- '**/test/**',
+ '**/node_modules/*',
+ '**/build/*',
+ '**/test/*',
+ '**/dist_electron/*',
],
formatters: {
css: true,
html: true,
markdown: 'prettier',
- }
+ },
})
diff --git a/package.json b/package.json
index 0f90ace8a1..cd139d1914 100644
--- a/package.json
+++ b/package.json
@@ -1,17 +1,17 @@
{
"name": "dev-sidecar-parent",
"type": "module",
- "packageManager": "pnpm@9.13.2",
"private": false,
+ "packageManager": "pnpm@9.13.2",
"author": "Greper",
"license": "MPL-2.0",
- "devDependencies": {
- "eslint": "^9.15.0",
- "@antfu/eslint-config": "^3.9.1",
- "eslint-plugin-format": "^0.1.2"
- },
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
+ },
+ "devDependencies": {
+ "@antfu/eslint-config": "^3.9.1",
+ "eslint": "^9.15.0",
+ "eslint-plugin-format": "^0.1.2"
}
}
diff --git a/packages/cli/package.json b/packages/cli/package.json
index dd207bd325..24e5bea2ec 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -11,8 +11,8 @@
"google加速",
"代理"
],
- "bin": "./cli.js",
"main": "src/index.js",
+ "bin": "./cli.js",
"scripts": {
"start": "node ./src"
},
diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js
index 9385f4816c..4dce5c8ada 100644
--- a/packages/cli/src/index.js
+++ b/packages/cli/src/index.js
@@ -1,6 +1,6 @@
-const fs = require('fs')
-const jsonApi = require('@docmirror/mitmproxy/src/json')
+const fs = require('node:fs')
const DevSidecar = require('@docmirror/dev-sidecar')
+const jsonApi = require('@docmirror/mitmproxy/src/json')
// 启动服务
const mitmproxyPath = './src/mitmproxy'
diff --git a/packages/cli/src/mitmproxy.js b/packages/cli/src/mitmproxy.js
index 57cbe5d4d1..b17a546606 100644
--- a/packages/cli/src/mitmproxy.js
+++ b/packages/cli/src/mitmproxy.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const server = require('@docmirror/mitmproxy')
const jsonApi = require('@docmirror/mitmproxy/src/json')
const log = require('../src/utils/util.log')
@@ -9,7 +9,8 @@ const home = process.env.USER_HOME || process.env.HOME || 'C:/Users/Administrato
let configPath
if (process.argv && process.argv.length > 3) {
configPath = process.argv[2]
-} else {
+}
+else {
configPath = path.join(home, '.dev-sidecar/running.json')
}
diff --git a/packages/core/package.json b/packages/core/package.json
index add351c7dc..629e825f24 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -16,12 +16,12 @@
"test": "mocha"
},
"dependencies": {
- "spawn-sync": "^2.0.0",
"fix-path": "^3.0.0",
"iconv-lite": "^0.6.3",
"lodash": "^4.17.20",
"log4js": "^6.9.1",
"node-powershell": "^4.0.0",
+ "spawn-sync": "^2.0.0",
"winreg": "^1.2.5"
},
"devDependencies": {
diff --git a/packages/core/src/config.js b/packages/core/src/config.js
index fba00d6be2..e4eac3b3f1 100644
--- a/packages/core/src/config.js
+++ b/packages/core/src/config.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const jsonApi = require('@docmirror/mitmproxy/src/json')
const lodash = require('lodash')
const request = require('request')
@@ -30,7 +30,8 @@ function _getConfigPath () {
const dir = getDefaultConfigBasePath()
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
- } else {
+ }
+ else {
// 兼容1.7.3及以下版本的配置文件处理逻辑
const newFilePath = path.join(dir, '/config.json')
const oldFilePath = path.join(dir, '/config.json5')
@@ -52,7 +53,8 @@ const configApi = {
try {
await configApi.downloadRemoteConfig()
configApi.reload()
- } catch (e) {
+ }
+ catch (e) {
log.error('定时下载远程配置并重载配置失败', e)
}
}
@@ -102,7 +104,8 @@ const configApi = {
log.warn('下载远程配置成功,但内容为空:', remoteConfigUrl)
resolve()
return
- } else {
+ }
+ else {
log.info('下载远程配置成功:', remoteConfigUrl)
}
@@ -110,7 +113,8 @@ const configApi = {
let remoteConfig
try {
remoteConfig = jsonApi.parse(body)
- } catch (e) {
+ }
+ catch (e) {
log.error(`远程配置内容格式不正确, url: ${remoteConfigUrl}, body: ${body}`)
remoteConfig = null
}
@@ -119,18 +123,21 @@ const configApi = {
const remoteSavePath = _getRemoteSavePath(suffix)
fs.writeFileSync(remoteSavePath, body)
log.info('保存远程配置文件成功:', remoteSavePath)
- } else {
+ }
+ else {
log.warn('远程配置对象为空:', remoteConfigUrl)
}
resolve()
- } else {
+ }
+ else {
log.error(`下载远程配置失败: ${remoteConfigUrl}, response:`, response, ', body:', body)
let message
if (response) {
message = `下载远程配置失败: ${remoteConfigUrl}, message: ${response.message}, code: ${response.statusCode}`
- } else {
+ }
+ else {
message = `下载远程配置失败: response: ${response}`
}
reject(new Error(message))
@@ -154,7 +161,8 @@ const configApi = {
if (!get().app.remoteConfig.personalUrl) {
return '{}'
}
- } else if (suffix === '') {
+ }
+ else if (suffix === '') {
if (!get().app.remoteConfig.url) {
return '{}'
}
@@ -167,10 +175,12 @@ const configApi = {
const file = fs.readFileSync(path)
log.info('读取远程配置文件内容成功:', path)
return file.toString()
- } else {
+ }
+ else {
log.warn('远程配置文件不存在:', path)
}
- } catch (e) {
+ }
+ catch (e) {
log.error('读取远程配置文件内容失败:', e)
}
@@ -220,7 +230,8 @@ const configApi = {
if (!fs.existsSync(configPath)) {
userConfig = {}
log.info('config.json 文件不存在:', configPath)
- } else {
+ }
+ else {
const file = fs.readFileSync(configPath)
log.info('读取 config.json 成功:', configPath)
const fileStr = file.toString()
@@ -265,7 +276,8 @@ const configApi = {
if (get().app.remoteConfig.personalUrl) {
mergeApi.doMerge(merged, personalRemoteConfig) // 再合并一次个人远程配置,使配置生效
}
- } else {
+ }
+ else {
mergeApi.doMerge(merged, defConfig) // 合并默认配置
}
if (newConfig != null) {
@@ -306,7 +318,8 @@ const configApi = {
configApi.load(null)
return true // 删除并重新加载配置成功
- } else {
+ }
+ else {
return false // config.json 文件不存在
}
},
@@ -315,7 +328,8 @@ const configApi = {
let value = lodash.get(defConfig, key)
value = lodash.cloneDeep(value)
lodash.set(configTarget, key, value)
- } else {
+ }
+ else {
configTarget = lodash.cloneDeep(defConfig)
}
return configTarget
diff --git a/packages/core/src/config/index.js b/packages/core/src/config/index.js
index 21e6ac826d..e950a17adf 100644
--- a/packages/core/src/config/index.js
+++ b/packages/core/src/config/index.js
@@ -1,4 +1,4 @@
-const path = require('path')
+const path = require('node:path')
function getUserBasePath () {
const userHome = process.env.USERPROFILE || process.env.HOME || '/'
diff --git a/packages/core/src/config/remote_config.json5 b/packages/core/src/config/remote_config.json5
index 88b60905e3..b487923f99 100644
--- a/packages/core/src/config/remote_config.json5
+++ b/packages/core/src/config/remote_config.json5
@@ -1,226 +1,226 @@
{
- "server": {
- "compatible": {
- "connect": {
- "218.18.106.132:443": {
- "ssl": true
- }
- },
- "request": {
- "218.18.106.132:443": {
- "rejectUnauthorized": false
- }
- }
- },
- "intercepts": {
- "github.com": {
- "^(/[\\w-.]+){2,}/?(\\?.*)?$": {
- "tampermonkeyScript": "https://gitee.com/wangliang181230/dev-sidecar/raw/scripts/tampermonkey.js",
- "script": "https://gitee.com/wangliang181230/dev-sidecar/raw/scripts/GithubEnhanced-High-Speed-Download.user.js"
- },
- "^(/[^/]+){2}/releases/download/.*$": {
- "redirect": "ghp.ci/https://github.com",
- "desc": "release文件加速下载重定向地址"
- },
- "^(/[^/]+){2}/archive/.*\\.(zip|tar.gz)$": {
- "redirect": "ghp.ci/https://github.com",
- "desc": "release源代码加速下载重定向地址"
- },
- "^((/[^/]+){2,})/raw((/[^/]+)+\\.(jpg|jpeg|png|gif))(\\?.*)?$": {
- "sni": "baidu.com" // proxy拦截器不会使用 .* 中的sni配置,故补充此配置
- },
- "^((/[^/]+){2,})/raw((/[^/]+)+\\.js)(\\?.*)?$": {
- "sni": "baidu.com" // proxy拦截器不会使用 .* 中的sni配置,故补充此配置
- }
- },
- "api.github.com": {
- ".*": {
- "sni": "baidu.com"
- }
- },
- "github.githubassets.com": {
- ".*": {
- "sni": "baidu.com"
- }
- },
- "avatars.githubusercontent.com": {
- ".*": {
- "sni": "baidu.com"
- }
- },
- "camo.githubusercontent.com": {
- ".*": {
- "sni": "baidu.com"
- }
- },
- "collector.github.com": {
- ".*": {
- "sni": "baidu.com"
- }
- },
- "www.gstatic.com": {
- "/recaptcha/.*": {
- "proxy": "www.recaptcha.net"
- }
- }
- },
- "preSetIpList": {
- "github.com": [
- "4.237.22.38",
- "20.26.156.215",
- "20.27.177.113",
- "20.87.245.0",
- "20.200.245.247",
- "20.201.28.151",
- "20.205.243.166",
- "140.82.113.3",
- "140.82.114.4",
- "140.82.116.3",
- "140.82.116.4",
- "140.82.121.3",
- "140.82.121.4"
- ],
- "hub.docker.com": null // 1.8.2版本中,该域名的预设IP有问题,现在远程配置中删除
- },
- "dns": {
- "mapping": {
- "*.jetbrains.com": "quad9",
- "*.azureedge.net": "quad9",
- "*.stackoverflow.com": "quad9"
- },
- "speedTest": {
- "interval": 300000
- }
- },
- "whiteList": {
- "*.icloud.com": true,
- "*.lenovo.net": true
- }
- },
- "proxy": {
- "remoteDomesticDomainAllowListFileUrl": "https://raw.kkgithub.com/pluwen/china-domain-allowlist/main/allow-list.sorl",
- "excludeIpList": {
- // Github文件上传所使用的域名,被DS代理会导致文件上传经常失败,从系统代理中排除掉
- "objects-origin.githubusercontent.com": true,
- // Github通过Actions上传的文件,下载时所需的域名,从系统代理中排除掉,否则下载会失败
- "*.windows.net": true,
- // Github下载release文件的高速镜像地址
- "*.ghproxy.net": true,
- "*.ghp.ci": true,
- "*.kkgithub.com": true,
-
- // Github建站域名
- "*.github.io": true,
-
- // bilibili相关
- "*.bilicomic.com": true,
-
- // 中国移动云盘登录API
- "[2049:8c54:813:10c::140]": true,
- "[2409:8a0c:a442:ff40:a51f:4b9c:8b41:25ea]": true,
- "[2606:2800:147:120f:30c:1ba0:fc6:265a]": true,
- // 移动云盘相关
- "*.cmicapm.com": true,
-
- // cloudflare:排除以下域名,cloudflare的人机校验会更快,成功率更高。
- "*.cloudflare.com": true,
- "*.cloudflare-cn.com": true,
-
- // VS相关
- "*.microsoftonline.com": true, // 此域名不排除的话,部分功能将出现异常
- "*.msecnd.net": true,
- "*.msedge.net": true,
-
- // 卡巴斯基升级域名
- "*kaspersky*.com": true,
- "*.upd.kaspersky.com": true,
-
- // sandbox沙盒域名
- "*.sandboxie-plus.com": true,
-
- // 无忧论坛
- "*.wuyou.net": true,
-
- // python建图包域名(浏览器)
- "*.pyecharts.org": true,
-
- // 教育网站
- "*.bcloudlink.com": true,
-
- // 奇迹秀(资源)
- "*.qijishow.com": true,
-
- // Z-Library
- "*.z-lib.fo": true,
-
- // Finalshell(Linux学习网)
- "*.finalshell.com": true,
-
- // MineBBS(我的世界中文论坛)
- "*.minebbs.com": true,
-
- // 我的世界插件网
- "*.spigotmc.org": true,
-
- // bd测试
- "*.virustotal.com": true,
-
- // 未知
- "*.youdemai.com": true,
- "*.casualthink.com": true,
- "44.239.165.12": true,
- "3.164.110.117": true
- }
- },
- "plugin": {
- "overwall": {
- "targets": {
- "*.github.com": true,
- "*github*.com": true,
- "*.nodejs.org": true,
- "*.npmjs.com": true,
- "*.wikimedia.org": true,
- "*.v2ex.com": true,
- "*.azureedge.net": true,
- "*.cloudfront.net": true,
- "*.bing.com": true,
- "*.discourse-cdn.com": true,
- "*.gravatar.com": true,
- "*.docker.com": true,
- "*.vueuse.org": true,
- "*.elastic.co": true,
- "*.optimizely.com": true,
- "*.stackpathcdn.com": true,
- "*.fastly.net": true,
- "*.cloudflare.com": true,
- "*.233v2.com": true,
- "*.v2fly.org": true,
- "*.telegram.org": true,
- "*.amazon.com": true,
- "*.googleapis.com": true,
- "*.google-analytics.com": true,
- "*.cloudflareinsights.com": true,
- "*.intlify.dev": true,
- "*.segment.io": true,
- "*.shields.io": true,
- "*.jsdelivr.net": true,
- "*.z-library.sk": true,
- "*.zlibrary*.se": true,
-
- // 维基百科
- "*.wikipedia-on-ipfs.org": true,
-
- // ChatGPT
- "*.oaiusercontent.com": true, // 在ChatGPT中生成文件并下载所需的域名
-
- // Pixiv相关
- "*.pixiv.org": true,
- "*.fanbox.cc": true,
- "*.onesignal.com": true // pixiv站点,会加载该域名下的js脚本
- },
- "pac": {
- "pacFileUpdateUrl": "https://raw.kkgithub.com/gfwlist/gfwlist/master/gfwlist.txt"
- }
- }
- }
+ "server": {
+ "compatible": {
+ "connect": {
+ "218.18.106.132:443": {
+ "ssl": true
+ }
+ },
+ "request": {
+ "218.18.106.132:443": {
+ "rejectUnauthorized": false
+ }
+ }
+ },
+ "intercepts": {
+ "github.com": {
+ "^(/[\\w-.]+){2,}/?(\\?.*)?$": {
+ "tampermonkeyScript": "https://gitee.com/wangliang181230/dev-sidecar/raw/scripts/tampermonkey.js",
+ "script": "https://gitee.com/wangliang181230/dev-sidecar/raw/scripts/GithubEnhanced-High-Speed-Download.user.js"
+ },
+ "^(/[^/]+){2}/releases/download/.*$": {
+ "redirect": "ghp.ci/https://github.com",
+ "desc": "release文件加速下载重定向地址"
+ },
+ "^(/[^/]+){2}/archive/.*\\.(zip|tar.gz)$": {
+ "redirect": "ghp.ci/https://github.com",
+ "desc": "release源代码加速下载重定向地址"
+ },
+ "^((/[^/]+){2,})/raw((/[^/]+)+\\.(jpg|jpeg|png|gif))(\\?.*)?$": {
+ "sni": "baidu.com" // proxy拦截器不会使用 .* 中的sni配置,故补充此配置
+ },
+ "^((/[^/]+){2,})/raw((/[^/]+)+\\.js)(\\?.*)?$": {
+ "sni": "baidu.com" // proxy拦截器不会使用 .* 中的sni配置,故补充此配置
+ }
+ },
+ "api.github.com": {
+ ".*": {
+ "sni": "baidu.com"
+ }
+ },
+ "github.githubassets.com": {
+ ".*": {
+ "sni": "baidu.com"
+ }
+ },
+ "avatars.githubusercontent.com": {
+ ".*": {
+ "sni": "baidu.com"
+ }
+ },
+ "camo.githubusercontent.com": {
+ ".*": {
+ "sni": "baidu.com"
+ }
+ },
+ "collector.github.com": {
+ ".*": {
+ "sni": "baidu.com"
+ }
+ },
+ "www.gstatic.com": {
+ "/recaptcha/.*": {
+ "proxy": "www.recaptcha.net"
+ }
+ }
+ },
+ "preSetIpList": {
+ "github.com": [
+ "4.237.22.38",
+ "20.26.156.215",
+ "20.27.177.113",
+ "20.87.245.0",
+ "20.200.245.247",
+ "20.201.28.151",
+ "20.205.243.166",
+ "140.82.113.3",
+ "140.82.114.4",
+ "140.82.116.3",
+ "140.82.116.4",
+ "140.82.121.3",
+ "140.82.121.4"
+ ],
+ "hub.docker.com": null // 1.8.2版本中,该域名的预设IP有问题,现在远程配置中删除
+ },
+ "dns": {
+ "mapping": {
+ "*.jetbrains.com": "quad9",
+ "*.azureedge.net": "quad9",
+ "*.stackoverflow.com": "quad9"
+ },
+ "speedTest": {
+ "interval": 300000
+ }
+ },
+ "whiteList": {
+ "*.icloud.com": true,
+ "*.lenovo.net": true
+ }
+ },
+ "proxy": {
+ "remoteDomesticDomainAllowListFileUrl": "https://raw.kkgithub.com/pluwen/china-domain-allowlist/main/allow-list.sorl",
+ "excludeIpList": {
+ // Github文件上传所使用的域名,被DS代理会导致文件上传经常失败,从系统代理中排除掉
+ "objects-origin.githubusercontent.com": true,
+ // Github通过Actions上传的文件,下载时所需的域名,从系统代理中排除掉,否则下载会失败
+ "*.windows.net": true,
+ // Github下载release文件的高速镜像地址
+ "*.ghproxy.net": true,
+ "*.ghp.ci": true,
+ "*.kkgithub.com": true,
+
+ // Github建站域名
+ "*.github.io": true,
+
+ // bilibili相关
+ "*.bilicomic.com": true,
+
+ // 中国移动云盘登录API
+ "[2049:8c54:813:10c::140]": true,
+ "[2409:8a0c:a442:ff40:a51f:4b9c:8b41:25ea]": true,
+ "[2606:2800:147:120f:30c:1ba0:fc6:265a]": true,
+ // 移动云盘相关
+ "*.cmicapm.com": true,
+
+ // cloudflare:排除以下域名,cloudflare的人机校验会更快,成功率更高。
+ "*.cloudflare.com": true,
+ "*.cloudflare-cn.com": true,
+
+ // VS相关
+ "*.microsoftonline.com": true, // 此域名不排除的话,部分功能将出现异常
+ "*.msecnd.net": true,
+ "*.msedge.net": true,
+
+ // 卡巴斯基升级域名
+ "*kaspersky*.com": true,
+ "*.upd.kaspersky.com": true,
+
+ // sandbox沙盒域名
+ "*.sandboxie-plus.com": true,
+
+ // 无忧论坛
+ "*.wuyou.net": true,
+
+ // python建图包域名(浏览器)
+ "*.pyecharts.org": true,
+
+ // 教育网站
+ "*.bcloudlink.com": true,
+
+ // 奇迹秀(资源)
+ "*.qijishow.com": true,
+
+ // Z-Library
+ "*.z-lib.fo": true,
+
+ // Finalshell(Linux学习网)
+ "*.finalshell.com": true,
+
+ // MineBBS(我的世界中文论坛)
+ "*.minebbs.com": true,
+
+ // 我的世界插件网
+ "*.spigotmc.org": true,
+
+ // bd测试
+ "*.virustotal.com": true,
+
+ // 未知
+ "*.youdemai.com": true,
+ "*.casualthink.com": true,
+ "44.239.165.12": true,
+ "3.164.110.117": true
+ }
+ },
+ "plugin": {
+ "overwall": {
+ "targets": {
+ "*.github.com": true,
+ "*github*.com": true,
+ "*.nodejs.org": true,
+ "*.npmjs.com": true,
+ "*.wikimedia.org": true,
+ "*.v2ex.com": true,
+ "*.azureedge.net": true,
+ "*.cloudfront.net": true,
+ "*.bing.com": true,
+ "*.discourse-cdn.com": true,
+ "*.gravatar.com": true,
+ "*.docker.com": true,
+ "*.vueuse.org": true,
+ "*.elastic.co": true,
+ "*.optimizely.com": true,
+ "*.stackpathcdn.com": true,
+ "*.fastly.net": true,
+ "*.cloudflare.com": true,
+ "*.233v2.com": true,
+ "*.v2fly.org": true,
+ "*.telegram.org": true,
+ "*.amazon.com": true,
+ "*.googleapis.com": true,
+ "*.google-analytics.com": true,
+ "*.cloudflareinsights.com": true,
+ "*.intlify.dev": true,
+ "*.segment.io": true,
+ "*.shields.io": true,
+ "*.jsdelivr.net": true,
+ "*.z-library.sk": true,
+ "*.zlibrary*.se": true,
+
+ // 维基百科
+ "*.wikipedia-on-ipfs.org": true,
+
+ // ChatGPT
+ "*.oaiusercontent.com": true, // 在ChatGPT中生成文件并下载所需的域名
+
+ // Pixiv相关
+ "*.pixiv.org": true,
+ "*.fanbox.cc": true,
+ "*.onesignal.com": true // pixiv站点,会加载该域名下的js脚本
+ },
+ "pac": {
+ "pacFileUpdateUrl": "https://raw.kkgithub.com/gfwlist/gfwlist/master/gfwlist.txt"
+ }
+ }
+ }
}
diff --git a/packages/core/src/expose.js b/packages/core/src/expose.js
index ee3593b2cf..b4c030fe94 100644
--- a/packages/core/src/expose.js
+++ b/packages/core/src/expose.js
@@ -46,14 +46,16 @@ async function startup ({ mitmproxyPath }) {
if (conf.server.enabled) {
try {
await server.start({ mitmproxyPath })
- } catch (err) {
+ }
+ catch (err) {
log.error('代理服务启动失败:', err)
}
}
if (conf.proxy.enabled) {
try {
await proxy.start()
- } catch (err) {
+ }
+ catch (err) {
log.error('开启系统代理失败:', err)
}
}
@@ -65,7 +67,8 @@ async function startup ({ mitmproxyPath }) {
try {
await plugin[key].start()
log.info(`插件【${key}】已启动`)
- } catch (err) {
+ }
+ catch (err) {
log.error(`插件【${key}】启动失败:`, err)
}
}
@@ -75,7 +78,8 @@ async function startup ({ mitmproxyPath }) {
if (plugins && plugins.length > 0) {
await Promise.all(plugins)
}
- } catch (err) {
+ }
+ catch (err) {
log.error('开启插件失败:', err)
}
}
@@ -89,7 +93,8 @@ async function shutdown () {
try {
await plugin[key].close()
log.info(`插件【${key}】已关闭`)
- } catch (err) {
+ }
+ catch (err) {
log.error(`插件【${key}】关闭失败:`, err)
}
}
@@ -99,7 +104,8 @@ async function shutdown () {
if (plugins.length > 0) {
await Promise.all(plugins)
}
- } catch (error) {
+ }
+ catch (error) {
log.error('插件关闭失败:', error)
}
@@ -107,7 +113,8 @@ async function shutdown () {
try {
await proxy.close()
log.info('系统代理已关闭')
- } catch (err) {
+ }
+ catch (err) {
log.error('系统代理关闭失败:', err)
}
}
@@ -115,7 +122,8 @@ async function shutdown () {
try {
await server.close()
log.info('代理服务已关闭')
- } catch (err) {
+ }
+ catch (err) {
log.error('代理服务关闭失败:', err)
}
}
diff --git a/packages/core/src/modules/plugin/git/index.js b/packages/core/src/modules/plugin/git/index.js
index 43fee407ca..ba3a7c24be 100644
--- a/packages/core/src/modules/plugin/git/index.js
+++ b/packages/core/src/modules/plugin/git/index.js
@@ -56,13 +56,15 @@ const Plugin = function (context) {
try {
await shell.exec(['git config --global --unset https.proxy '], { type: 'cmd' })
- } catch (ignore) {
+ }
+ catch (ignore) {
}
if (config.get().plugin.git.setting.sslVerify === true) {
try {
await shell.exec(['git config --global --unset http.sslVerify '], { type: 'cmd' })
- } catch (ignore) {
+ }
+ catch (ignore) {
}
}
@@ -70,7 +72,8 @@ const Plugin = function (context) {
for (const url in config.get().plugin.git.setting.noProxyUrls) {
try {
await shell.exec([`git config --global --unset http."${url}".proxy `], { type: 'cmd' })
- } catch (ignore) {
+ }
+ catch (ignore) {
}
}
}
diff --git a/packages/core/src/modules/plugin/node/index.js b/packages/core/src/modules/plugin/node/index.js
index e19269555c..ac4fe3950f 100644
--- a/packages/core/src/modules/plugin/node/index.js
+++ b/packages/core/src/modules/plugin/node/index.js
@@ -7,7 +7,8 @@ const NodePlugin = function (context) {
async start () {
try {
await nodeApi.setVariables()
- } catch (err) {
+ }
+ catch (err) {
log.warn('set variables error:', err)
}
@@ -47,7 +48,8 @@ const NodePlugin = function (context) {
for (const item of list) {
if (item.value != null && item.value.length > 0 && item.value !== 'default' && item.value !== 'null') {
cmds.push(`${command} config set ${item.key} ${item.value}`)
- } else {
+ }
+ else {
cmds.push(`${command} config delete ${item.key}`)
}
}
@@ -70,7 +72,8 @@ const NodePlugin = function (context) {
for (const item of list) {
if (item.value != null && item.value.length > 0 && item.value !== 'default' && item.value !== 'null') {
cmds.push(`yarn config set ${item.key} ${item.value}`)
- } else {
+ }
+ else {
cmds.push(`yarn config delete ${item.key}`)
}
}
@@ -115,7 +118,8 @@ const NodePlugin = function (context) {
async setRegistry ({ registry, type }) {
if (type === 'npm') {
await nodeApi.setNpmEnv([{ key: 'registry', value: registry }])
- } else {
+ }
+ else {
await nodeApi.setYarnEnv([{ key: 'registry', value: registry }])
}
return true
diff --git a/packages/core/src/modules/plugin/overwall/index.js b/packages/core/src/modules/plugin/overwall/index.js
index 7842449815..656a309419 100644
--- a/packages/core/src/modules/plugin/overwall/index.js
+++ b/packages/core/src/modules/plugin/overwall/index.js
@@ -28,7 +28,8 @@ const Plugin = function (context) {
for (const key in server) {
if (i === 0) {
main = key
- } else {
+ }
+ else {
backup.push(key)
}
i++
diff --git a/packages/core/src/modules/plugin/pip/index.js b/packages/core/src/modules/plugin/pip/index.js
index 63572ceef9..6108b5edb8 100644
--- a/packages/core/src/modules/plugin/pip/index.js
+++ b/packages/core/src/modules/plugin/pip/index.js
@@ -48,7 +48,8 @@ const PipPlugin = function (context) {
for (const item of list) {
if (item.value != null) {
cmds.push(`${command} config set global.${item.key} ${item.value}`)
- } else {
+ }
+ else {
cmds.push(`${command} config unset global.${item.key}`)
}
}
diff --git a/packages/core/src/modules/proxy/index.js b/packages/core/src/modules/proxy/index.js
index 7a01cef6bc..b618a99cf3 100644
--- a/packages/core/src/modules/proxy/index.js
+++ b/packages/core/src/modules/proxy/index.js
@@ -33,7 +33,8 @@ const ProxyPlugin = function (context) {
event.fire('status', { key: 'proxy.enabled', value: false })
log.info('关闭系统代理成功')
return true
- } catch (err) {
+ }
+ catch (err) {
log.error('关闭系统代理失败:', err)
return false
}
diff --git a/packages/core/src/modules/server/index.js b/packages/core/src/modules/server/index.js
index d625d758f1..2eacd07b28 100644
--- a/packages/core/src/modules/server/index.js
+++ b/packages/core/src/modules/server/index.js
@@ -2,9 +2,9 @@ const lodash = require('lodash')
const config = require('../../config')
const event = require('../../event')
const status = require('../../status')
-const fork = require('child_process').fork
-const fs = require('fs')
-const path = require('path')
+const fork = require('node:child_process').fork
+const fs = require('node:fs')
+const path = require('node:path')
const jsonApi = require('@docmirror/mitmproxy/src/json')
const log = require('../../utils/util.log')
@@ -102,14 +102,16 @@ const serverApi = {
log.info('收到子进程消息:', JSON.stringify(msg))
if (msg.type === 'status') {
fireStatus(msg.event)
- } else if (msg.type === 'error') {
+ }
+ else if (msg.type === 'error') {
let code = ''
if (msg.event.code) {
code = msg.event.code
}
fireStatus(false) // 启动失败
event.fire('error', { key: 'server', value: code, error: msg.event, message: msg.message })
- } else if (msg.type === 'speed') {
+ }
+ else if (msg.type === 'speed') {
event.fire('speed', msg.event)
}
})
@@ -139,12 +141,14 @@ const serverApi = {
}
log.warn('代理服务关闭失败:', err)
reject(err)
- } else {
+ }
+ else {
log.info('代理服务关闭成功')
resolve()
}
})
- } else {
+ }
+ else {
log.info('server is null')
resolve()
}
diff --git a/packages/core/src/shell/scripts/extra-path/index.js b/packages/core/src/shell/scripts/extra-path/index.js
index c1d3a0c468..09d5513ddd 100644
--- a/packages/core/src/shell/scripts/extra-path/index.js
+++ b/packages/core/src/shell/scripts/extra-path/index.js
@@ -1,4 +1,4 @@
-const path = require('path')
+const path = require('node:path')
const log = require('../../../utils/util.log')
function getExtraPath () {
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 5b7e852a16..f525903338 100644
--- a/packages/core/src/shell/scripts/set-system-proxy/index.js
+++ b/packages/core/src/shell/scripts/set-system-proxy/index.js
@@ -1,12 +1,12 @@
+const fs = require('node:fs')
+const path = require('node:path')
+const request = require('request')
/**
* 获取环境变量
*/
const Registry = require('winreg')
-const Shell = require('../../shell')
-const fs = require('fs')
-const path = require('path')
-const request = require('request')
const log = require('../../../utils/util.log')
+const Shell = require('../../shell')
const extraPath = require('../extra-path/index')
const execute = Shell.execute
@@ -44,7 +44,8 @@ async function _winUnsetProxy (exec, setEnv) {
})
}
})
- } catch (e) {
+ }
+ catch (e) {
log.error('删除环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e)
}
}
@@ -67,7 +68,8 @@ async function downloadDomesticDomainAllowListAsync () {
if (body == null || body.length < 100) {
log.warn('下载远程 domestic-domain-allowlist.txt 文件成功,但内容为空或内容太短,判断为无效的 domestic-domain-allowlist.txt 文件:', remoteFileUrl, ', body:', body)
return
- } else {
+ }
+ else {
log.info('下载远程 domestic-domain-allowlist.txt 文件成功:', remoteFileUrl)
}
@@ -77,7 +79,8 @@ async function downloadDomesticDomainAllowListAsync () {
fileTxt = Buffer.from(fileTxt, 'base64').toString('utf8')
// log.debug('解析 base64 后的 domestic-domain-allowlist:', fileTxt)
}
- } catch (e) {
+ }
+ catch (e) {
if (!fileTxt.includes('*.')) {
log.error(`远程 domestic-domain-allowlist.txt 文件内容即不是base64格式,也不是要求的格式,url: ${remoteFileUrl},body: ${body}`)
return
@@ -86,7 +89,8 @@ async function downloadDomesticDomainAllowListAsync () {
// 保存到本地
saveDomesticDomainAllowListFile(fileTxt)
- } else {
+ }
+ else {
log.error(`下载远程 domestic-domain-allowlist.txt 文件失败: ${remoteFileUrl}, response:`, response, ', body:', body)
}
})
@@ -97,7 +101,8 @@ function loadLastModifiedTimeFromTxt (fileTxt) {
if (matched && matched.length > 0) {
try {
return new Date(matched[0])
- } catch (ignore) {
+ }
+ catch (ignore) {
return null
}
}
@@ -122,7 +127,8 @@ function saveDomesticDomainAllowListFile (fileTxt) {
fs.utimes(filePath, lastModifiedTime, lastModifiedTime, (utimesErr) => {
if (utimesErr) {
log.error('修改 domestic-domain-allowlist.txt 文件时间失败:', utimesErr)
- } else {
+ }
+ else {
log.info(`'${filePath}' 文件的修改时间已更新为其最近更新时间 '${formatDate(lastModifiedTime)}'`)
}
})
@@ -163,19 +169,22 @@ function getDomesticDomainAllowList () {
// 如果临时文件已存在,则使用临时文件
fileAbsolutePath = tmpFilePath
log.info('读取已下载的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
- } else {
+ }
+ else {
// 如果临时文件不存在,则使用内置文件
log.info('__dirname:', __dirname)
fileAbsolutePath = path.join(__dirname, '../', config.get().proxy.domesticDomainAllowListFilePath)
log.info('读取内置的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
}
- } else {
+ }
+ else {
log.info('读取自定义路径的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
}
try {
return fs.readFileSync(fileAbsolutePath).toString()
- } catch (e) {
+ }
+ catch (e) {
log.error(`读取 domestic-domain-allowlist.txt 文件失败: ${fileAbsolutePath}, error:`, e)
return null
}
@@ -198,11 +207,13 @@ function getProxyExcludeIpStr (split) {
if (domesticDomainAllowList) {
excludeIpStr += domesticDomainAllowList
log.info('系统代理排除列表拼接国内域名')
- } else {
+ }
+ else {
log.info('国内域名为空,不进行系统代理排除列表拼接国内域名')
}
}
- } catch (e) {
+ }
+ catch (e) {
log.error('系统代理排除列表拼接国内域名失败:', e)
}
}
@@ -246,7 +257,8 @@ async function _winSetProxy (exec, ip, port, setEnv) {
}
// await addClearScriptIni()
- } catch (e) {
+ }
+ catch (e) {
log.error('设置环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e)
}
}
@@ -260,7 +272,8 @@ const executor = {
if (ip != null) { // 设置代理
log.info('设置windows系统代理:', ip, port, setEnv)
return _winSetProxy(exec, ip, port, setEnv)
- } else { // 关闭代理
+ }
+ else { // 关闭代理
log.info('关闭windows系统代理')
return _winUnsetProxy(exec, setEnv)
}
@@ -281,7 +294,8 @@ const executor = {
if (config.get().proxy.proxyHttp) {
setProxyCmd.push(`gsettings set org.gnome.system.proxy.http host ${ip}`)
setProxyCmd.push(`gsettings set org.gnome.system.proxy.http port ${port - 1}`)
- } else {
+ }
+ else {
setProxyCmd.push('gsettings set org.gnome.system.proxy.http host \'\'')
setProxyCmd.push('gsettings set org.gnome.system.proxy.http port 0')
}
@@ -291,7 +305,8 @@ const executor = {
setProxyCmd.push(`gsettings set org.gnome.system.proxy ignore-hosts "['${excludeIpStr}']"`)
await exec(setProxyCmd)
- } else { // 关闭代理
+ }
+ else { // 关闭代理
const setProxyCmd = [
'gsettings set org.gnome.system.proxy mode none',
]
@@ -313,7 +328,8 @@ const executor = {
// http
if (config.get().proxy.proxyHttp) {
await exec(`networksetup -setwebproxy "${wifiAdaptor}" ${ip} ${port - 1}`)
- } else {
+ }
+ else {
await exec(`networksetup -setwebproxystate "${wifiAdaptor}" off`)
}
@@ -328,7 +344,8 @@ const executor = {
// source ~/.zshrc
// `
// await exec(setEnv)
- } else { // 关闭代理
+ }
+ else { // 关闭代理
// https
await exec(`networksetup -setsecurewebproxystate "${wifiAdaptor}" off`)
// http
diff --git a/packages/core/src/shell/shell.js b/packages/core/src/shell/shell.js
index 0c06d6d036..7b16c4eaf5 100644
--- a/packages/core/src/shell/shell.js
+++ b/packages/core/src/shell/shell.js
@@ -1,5 +1,5 @@
-const childProcess = require('child_process')
-const os = require('os')
+const childProcess = require('node:child_process')
+const os = require('node:os')
const fixPath = require('fix-path')
const iconv = require('iconv-lite')
const PowerShell = require('node-powershell')
@@ -60,10 +60,12 @@ class WindowsSystemShell extends SystemShell {
const ret = await ps.invoke()
// log.info('ps complete', cmds)
return ret
- } finally {
+ }
+ finally {
ps.dispose()
}
- } else {
+ }
+ else {
let compose = 'echo "test" ' // 'chcp 65001 '
for (const cmd of cmds) {
compose += ` && ${cmd}`
@@ -78,7 +80,7 @@ class WindowsSystemShell extends SystemShell {
function _childExec (composeCmds, options = {}) {
return new Promise((resolve, reject) => {
- const childProcess = require('child_process')
+ const childProcess = require('node:child_process')
log.info('shell:', composeCmds)
childProcess.exec(composeCmds, options, (error, stdout, stderr) => {
if (error) {
@@ -86,7 +88,8 @@ function _childExec (composeCmds, options = {}) {
log.error('cmd 命令执行错误:\n===>\ncommands:', composeCmds, '\n error:', error, '\n<===')
}
reject(new Error(stderr))
- } else {
+ }
+ else {
// log.info('cmd 命令完成:', stdout)
resolve(stdout)
}
@@ -101,7 +104,7 @@ function childExec (composeCmds, options = {}) {
const encoding = 'cp936'
const binaryEncoding = 'binary'
- const childProcess = require('child_process')
+ const childProcess = require('node:child_process')
log.info('shell:', composeCmds)
childProcess.exec(composeCmds, { encoding: binaryEncoding }, (error, stdout, stderr) => {
if (error) {
@@ -111,7 +114,8 @@ function childExec (composeCmds, options = {}) {
log.error('cmd 命令执行错误:\n------------------------------\ncommands:', composeCmds, '\n message:', message, '\n error:', error, '\n------------------------------')
}
reject(new Error(message))
- } else {
+ }
+ else {
// log.info('cmd 命令完成:', stdout)
const message = iconv.decode(Buffer.from(stdout, binaryEncoding), encoding)
resolve(message)
@@ -167,7 +171,8 @@ async function execFile (file, args, options) {
log.debug('文件执行成功:', file)
resolve(stdout)
})
- } catch (e) {
+ }
+ catch (e) {
log.error('文件执行出错:', file, e)
reject(e)
}
diff --git a/packages/core/src/shell/test.js b/packages/core/src/shell/test.js
index 6748a0206a..af7b20b37e 100644
--- a/packages/core/src/shell/test.js
+++ b/packages/core/src/shell/test.js
@@ -34,7 +34,7 @@
// console.error(e)
// })
-const fs = require('fs')
+const fs = require('node:fs')
const request = require('request')
request({
diff --git a/packages/core/src/utils/util.logger.js b/packages/core/src/utils/util.logger.js
index 749449a187..6d15c06def 100644
--- a/packages/core/src/utils/util.logger.js
+++ b/packages/core/src/utils/util.logger.js
@@ -1,4 +1,4 @@
-const path = require('path')
+const path = require('node:path')
const log4js = require('log4js')
const config = require('../config/index')
@@ -13,17 +13,17 @@ const guiLogFilename = path.join(getDefaultConfigBasePath(), '/logs/gui.log')
const serverLogFilename = path.join(getDefaultConfigBasePath(), '/logs/server.log')
log4js.configure({
- appenders: {
- std: { type: 'stdout' },
+ appenders: {
+ std: { type: 'stdout' },
core: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: coreLogFilename },
- gui: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: guiLogFilename },
- server: { level: 'debug', type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: serverLogFilename }
+ gui: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: guiLogFilename },
+ server: { level: 'debug', type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: serverLogFilename },
},
categories: {
default: { appenders: ['std'], level },
core: { appenders: ['core', 'std'], level },
gui: { appenders: ['gui', 'std'], level },
- server: { appenders: ['server', 'std'], level }
+ server: { appenders: ['server', 'std'], level },
},
})
diff --git a/packages/core/test/httpsVerifyTest.js b/packages/core/test/httpsVerifyTest.js
index 30c03b9a61..f2f4133a4d 100644
--- a/packages/core/test/httpsVerifyTest.js
+++ b/packages/core/test/httpsVerifyTest.js
@@ -1,4 +1,4 @@
-const https = require('https')
+const https = require('node:https')
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'
diff --git a/packages/gui/README.md b/packages/gui/README.md
index 77947a7e5c..09c5c06302 100644
--- a/packages/gui/README.md
+++ b/packages/gui/README.md
@@ -1,24 +1,29 @@
# dev-sidecar-gui
## Project setup
+
```
yarn install
```
### Compiles and hot-reloads for development
+
```
yarn serve
```
### Compiles and minifies for production
+
```
yarn build
```
### Lints and fixes files
+
```
yarn lint
```
### Customize configuration
+
See [Configuration Reference](https://cli.vuejs.org/config/).
diff --git a/packages/gui/babel.config.js b/packages/gui/babel.config.js
index 4c3a7a3e4d..0a932f18f5 100644
--- a/packages/gui/babel.config.js
+++ b/packages/gui/babel.config.js
@@ -1,5 +1,5 @@
module.exports = {
presets: [
- '@vue/babel-preset-jsx'
- ]
+ '@vue/babel-preset-jsx',
+ ],
}
diff --git a/packages/gui/pkg/after-all-artifact-build.js b/packages/gui/pkg/after-all-artifact-build.js
index 9c61f50f58..5ab94876f5 100644
--- a/packages/gui/pkg/after-all-artifact-build.js
+++ b/packages/gui/pkg/after-all-artifact-build.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const pkg = require('../package.json')
function appendIntro (context, systemType, latest) {
diff --git a/packages/gui/pkg/after-pack.js b/packages/gui/pkg/after-pack.js
index 48551178ba..f897f08eac 100644
--- a/packages/gui/pkg/after-pack.js
+++ b/packages/gui/pkg/after-pack.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const AdmZip = require('adm-zip')
const pkg = require('../package.json')
@@ -24,11 +24,13 @@ exports.default = async function (context) {
if (context.packager.platform.nodeName === 'darwin') {
targetPath = path.join(context.appOutDir, `${context.packager.appInfo.productName}.app/Contents/Resources`)
systemType = 'mac'
- } else if (context.packager.platform.nodeName === 'linux') {
+ }
+ else if (context.packager.platform.nodeName === 'linux') {
targetPath = path.join(context.appOutDir, './resources')
systemType = 'linux'
writeAppUpdateYmlForLinux()
- } else {
+ }
+ else {
targetPath = path.join(context.appOutDir, './resources')
systemType = 'win'
}
diff --git a/packages/gui/public/index.html b/packages/gui/public/index.html
index 6dc21839dc..dceebc70b4 100644
--- a/packages/gui/public/index.html
+++ b/packages/gui/public/index.html
@@ -1,16 +1,20 @@
-
-
+
+
-
-
-
-
+
+
+
+
<%= htmlWebpackPlugin.options.title %>
-
+
-
-
-
+
+
+
+
+
diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js
index 71570c29fc..aa4a72797c 100644
--- a/packages/gui/src/background.js
+++ b/packages/gui/src/background.js
@@ -1,6 +1,6 @@
'use strict'
/* global __static */
-import path from 'path'
+import path from 'node:path'
import DevSidecar from '@docmirror/dev-sidecar'
import { app, BrowserWindow, dialog, globalShortcut, ipcMain, Menu, nativeImage, nativeTheme, powerMonitor, protocol, Tray } from 'electron'
import minimist from 'minimist'
@@ -34,7 +34,8 @@ function openDevTools () {
log.debug('尝试打开 `开发者工具`')
win.webContents.openDevTools()
log.debug('打开 `开发者工具` 成功')
- } catch (e) {
+ }
+ catch (e) {
log.error('打开 `开发者工具` 失败:', e)
}
}
@@ -44,7 +45,8 @@ function closeDevTools () {
log.debug('尝试关闭 `开发者工具`')
win.webContents.closeDevTools()
log.debug('关闭 `开发者工具` 成功')
- } catch (e) {
+ }
+ catch (e) {
log.error('关闭 `开发者工具` 失败:', e)
}
}
@@ -55,7 +57,8 @@ function switchDevTools () {
}
if (win.webContents.isDevToolsOpened()) {
closeDevTools()
- } else {
+ }
+ else {
openDevTools()
}
}
@@ -102,7 +105,8 @@ function setTray () {
if (nativeTheme.shouldUseDarkColors) {
console.log('i am dark.')
tray.setImage(iconWhitePath)
- } else {
+ }
+ else {
console.log('i am light.')
tray.setImage(iconBlackPath)
// tray.setPressedImage(iconWhitePath)
@@ -200,7 +204,8 @@ function createWindow (startHideWindow) {
if (!process.env.IS_TEST) {
setTimeout(openDevTools, 2000)
}
- } else {
+ }
+ else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')
@@ -219,7 +224,8 @@ function createWindow (startHideWindow) {
ipcMain.on('close', async (event, message) => {
if (message.value === 1) {
quit()
- } else {
+ }
+ else {
hideWin()
}
})
@@ -239,10 +245,12 @@ function createWindow (startHideWindow) {
if (closeStrategy === 0) {
// 弹窗提示,选择关闭策略
win.webContents.send('close.showTip', closeStrategy)
- } else if (closeStrategy === 1) {
+ }
+ else if (closeStrategy === 1) {
// 直接退出
quit()
- } else if (closeStrategy === 2) {
+ }
+ else if (closeStrategy === 2) {
// 隐藏窗口
hideWin()
}
@@ -320,7 +328,8 @@ function registerShowHideShortcut (showHideShortcut) {
if (winIsHidden) {
showWin()
}
- } else {
+ }
+ else {
// linux,快捷键不关闭窗口
if (!isLinux()) {
hideWin()
@@ -330,10 +339,12 @@ function registerShowHideShortcut (showHideShortcut) {
if (registerSuccess) {
log.info('注册快捷键成功:', DevSidecar.api.config.get().app.showHideShortcut)
- } else {
+ }
+ else {
log.error('注册快捷键失败:', DevSidecar.api.config.get().app.showHideShortcut)
}
- } catch (e) {
+ }
+ catch (e) {
log.error('注册快捷键异常:', DevSidecar.api.config.get().app.showHideShortcut, ', error:', e)
}
}
@@ -359,7 +370,8 @@ app.disableHardwareAcceleration() // 禁用gpu
let startHideWindow = !DevSidecar.api.config.get().app.startShowWindow
if (app.getLoginItemSettings().wasOpenedAsHidden) {
startHideWindow = true
-} else if (process.argv) {
+}
+else if (process.argv) {
const args = minimist(process.argv)
log.info('start args:', args)
@@ -367,7 +379,8 @@ if (app.getLoginItemSettings().wasOpenedAsHidden) {
const hideWindowArg = `${args.hideWindow}`
if (hideWindowArg === 'true' || hideWindowArg === '1') {
startHideWindow = true
- } else if (hideWindowArg === 'false' || hideWindowArg === '0') {
+ }
+ else if (hideWindowArg === 'false' || hideWindowArg === '0') {
startHideWindow = false
}
}
@@ -380,7 +393,8 @@ if (!isFirstInstance) {
setTimeout(() => {
app.quit()
}, 1000)
-} else {
+}
+else {
app.on('before-quit', async () => {
log.info('before-quit')
if (process.platform === 'darwin') {
@@ -414,7 +428,8 @@ if (!isFirstInstance) {
// dock icon is clicked and there are no other windows open.
if (win == null) {
createWindow(false)
- } else {
+ }
+ else {
showWin()
}
})
@@ -437,14 +452,16 @@ if (!isFirstInstance) {
createWindow(startHideWindow)
const context = { win, app, beforeQuit, quit, ipcMain, dialog, log, api: DevSidecar.api, changeAppConfig }
backend.install(context) // 模块安装
- } catch (err) {
+ }
+ catch (err) {
log.info('error:', err)
}
try {
// 最小化到托盘
tray = setTray()
- } catch (err) {
+ }
+ catch (err) {
log.info('error:', err)
}
@@ -472,7 +489,8 @@ if (isDevelopment) {
quit()
}
})
- } else {
+ }
+ else {
process.on('SIGINT', () => {
quit()
})
diff --git a/packages/gui/src/background/powerMonitor.js b/packages/gui/src/background/powerMonitor.js
index 3431fe623d..335f8a67d7 100644
--- a/packages/gui/src/background/powerMonitor.js
+++ b/packages/gui/src/background/powerMonitor.js
@@ -34,7 +34,8 @@ class PowerMonitor {
releaseShutdownBlock()
this._shutdownCallback = null
}
- } else {
+ }
+ else {
return _powerMonitor.removeAllListeners(event)
}
}
@@ -50,7 +51,8 @@ class PowerMonitor {
acquireShutdownBlock('正在停止 DevSidecar 代理')
}
this._listeners.push(listener)
- } else {
+ }
+ else {
return _powerMonitor.on(event, listener)
}
}
@@ -58,7 +60,8 @@ class PowerMonitor {
off (event, listener) {
if (event === 'shutdown' && process.platform === 'win32') {
this._listeners = this._listeners.filter(fn => fn !== listener)
- } else {
+ }
+ else {
return _powerMonitor.off(event, listener)
}
}
@@ -66,7 +69,8 @@ class PowerMonitor {
once (event, listener) {
if (event === 'shutdown' && process.platform === 'win32') {
return this.on(event, listener)
- } else {
+ }
+ else {
return _powerMonitor.once(event, listener)
}
}
diff --git a/packages/gui/src/bridge/api/backend.js b/packages/gui/src/bridge/api/backend.js
index 6697e8bdb9..d839a6f3da 100644
--- a/packages/gui/src/bridge/api/backend.js
+++ b/packages/gui/src/bridge/api/backend.js
@@ -4,8 +4,8 @@ import DevSidecar from '@docmirror/dev-sidecar'
import { ipcMain } from 'electron'
import lodash from 'lodash'
-const pk = require('../../../package.json')
const jsonApi = require('@docmirror/mitmproxy/src/json')
+const pk = require('../../../package.json')
const log = require('../../utils/util.log')
const mitmproxyPath = path.join(__dirname, 'mitmproxy.js')
@@ -66,7 +66,8 @@ const localApi = {
try {
setting = jsonApi.parse(file.toString())
log.info('读取 setting.json 成功:', settingPath)
- } catch (e) {
+ }
+ catch (e) {
log.error('读取 setting.json 失败:', settingPath, ', error:', e)
}
if (setting == null) {
@@ -130,7 +131,8 @@ function _deepFindFunction (list, parent, parentKey) {
const item = parent[key]
if (item instanceof Function) {
list.push(parentKey + key)
- } else if (item instanceof Object) {
+ }
+ else if (item instanceof Object) {
_deepFindFunction(list, item, `${parentKey + key}.`)
}
}
@@ -140,7 +142,8 @@ function _getSettingsPath () {
const dir = getDefaultConfigBasePath()
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
- } else {
+ }
+ else {
// 兼容1.7.3及以下版本的配置文件处理逻辑
const newFilePath = path.join(dir, '/setting.json')
const oldFilePath = path.join(dir, '/setting.json5')
diff --git a/packages/gui/src/bridge/auto-start/backend.js b/packages/gui/src/bridge/auto-start/backend.js
index fed4d26513..9748cb21f0 100644
--- a/packages/gui/src/bridge/auto-start/backend.js
+++ b/packages/gui/src/bridge/auto-start/backend.js
@@ -19,7 +19,8 @@ Comment=
EOF
`
await DevSidecar.api.shell.exec(cmd)
- } else {
+ }
+ else {
const removeStart = 'sudo rm ~/.config/autostart/dev-sidecar.desktop -rf'
await DevSidecar.api.shell.exec(removeStart)
}
@@ -39,7 +40,8 @@ export default {
if (message.value) {
if (isLinux) {
await setAutoStartForLinux(app, true)
- } else {
+ }
+ else {
app.setLoginItemSettings({
openAtLogin: true,
openAsHidden: true,
@@ -51,10 +53,12 @@ export default {
}
event.sender.send('auto-start', { key: 'enabled', value: true })
- } else {
+ }
+ else {
if (isLinux) {
await setAutoStartForLinux(app, false)
- } else {
+ }
+ else {
app.setLoginItemSettings({
openAtLogin: false,
openAsHidden: false,
diff --git a/packages/gui/src/bridge/auto-start/front.js b/packages/gui/src/bridge/auto-start/front.js
index 4d19525b1a..bf445a5d65 100644
--- a/packages/gui/src/bridge/auto-start/front.js
+++ b/packages/gui/src/bridge/auto-start/front.js
@@ -2,7 +2,8 @@ function install (app, api) {
api.ipc.on('auto-start', (event, message) => {
if (message.value === true) {
app.$message.info('已添加开机自启')
- } else {
+ }
+ else {
app.$message.info('已取消开机自启')
}
})
diff --git a/packages/gui/src/bridge/error/front.js b/packages/gui/src/bridge/error/front.js
index abb835f4c7..1935c65f6d 100644
--- a/packages/gui/src/bridge/error/front.js
+++ b/packages/gui/src/bridge/error/front.js
@@ -29,7 +29,8 @@ function handleServerStartError (message, err, app, api) {
console.log('Cancel')
},
})
- } else {
+ }
+ else {
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 6cdec455ed..6bf745c89f 100644
--- a/packages/gui/src/bridge/file-selector/backend.js
+++ b/packages/gui/src/bridge/file-selector/backend.js
@@ -9,7 +9,8 @@ export default {
}).then((result) => {
if (result.canceled) {
event.sender.send('file-selector', { key: 'canceled' })
- } else {
+ }
+ else {
event.sender.send('file-selector', { key: 'selected', value: result.filePaths })
}
}).catch((err) => {
diff --git a/packages/gui/src/bridge/file-selector/front.js b/packages/gui/src/bridge/file-selector/front.js
index 69b0d31b5b..27b4828bb3 100644
--- a/packages/gui/src/bridge/file-selector/front.js
+++ b/packages/gui/src/bridge/file-selector/front.js
@@ -7,7 +7,8 @@ function install (app, api) {
console.log('selector', message)
if (message.key === 'selected') {
resolve(message.value)
- } else {
+ }
+ else {
reject(new Error('没有选择文件'))
}
api.ipc.on('file-selector', () => {})
diff --git a/packages/gui/src/bridge/mitmproxy.js b/packages/gui/src/bridge/mitmproxy.js
index 5590874df4..e5dedc8243 100644
--- a/packages/gui/src/bridge/mitmproxy.js
+++ b/packages/gui/src/bridge/mitmproxy.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const server = require('@docmirror/mitmproxy')
const jsonApi = require('@docmirror/mitmproxy/src/json')
const log = require('../utils/util.log')
diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js
index 32e0f02c28..8d51805b9f 100644
--- a/packages/gui/src/bridge/update/backend.js
+++ b/packages/gui/src/bridge/update/backend.js
@@ -1,5 +1,5 @@
-import fs from 'fs'
-import path from 'path'
+import fs from 'node:fs'
+import path from 'node:path'
import DevSidecar from '@docmirror/dev-sidecar'
import AdmZip from 'adm-zip'
import { ipcMain } from 'electron'
@@ -85,14 +85,16 @@ function isNewVersion (version, curVersion) {
if (versionObj.suffix > curVersionObj.suffix) {
return 41
}
- } else if (!versionObj.suffix && curVersionObj.suffix) {
+ }
+ else if (!versionObj.suffix && curVersionObj.suffix) {
// 线上版本号没有后缀版本号,说明为正式版本,为更新版本
return 42
}
}
}
}
- } catch (e) {
+ }
+ catch (e) {
log.error(`比对版本失败,当前版本号:${curVersion},比对版本号:${version}, error:`, e)
return -99
}
@@ -125,9 +127,11 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
// })
if (isMac) {
autoUpdater.updateConfigPath = path.join(__dirname, 'mac/dev-sidecar.app/Contents/Resources/app-update.yml')
- } else if (isLinux) {
+ }
+ else if (isLinux) {
autoUpdater.updateConfigPath = path.join(__dirname, 'linux-unpacked/resources/app-update.yml')
- } else {
+ }
+ else {
autoUpdater.updateConfigPath = path.join(__dirname, 'win-unpacked/resources/app-update.yml')
}
}
@@ -159,7 +163,8 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
let data
try {
data = JSON.parse(body)
- } catch (e) {
+ }
+ catch (e) {
log.error('检查更新失败,github API返回数据格式不正确:', body)
win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: '检查更新失败,github API返回数据格式不正确' })
return
@@ -206,7 +211,8 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
: '无',
},
})
- } else {
+ }
+ else {
log.info(`检查更新:没有新版本,最近发布的版本号为 '${version}',而当前版本号为 '${curVersion}'`)
win.webContents.send('update', { key: 'notAvailable' })
}
@@ -216,25 +222,29 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
log.info('检查更新-没有正式版本数据')
win.webContents.send('update', { key: 'notAvailable' })
- } else {
+ }
+ else {
log.error('检查更新失败, status:', response.statusCode, ', body:', body)
let bodyObj
try {
bodyObj = JSON.parse(body)
- } catch (e) {
+ }
+ catch (e) {
bodyObj = null
}
let message
if (response) {
message = `检查更新失败: ${bodyObj && bodyObj.message ? bodyObj.message : response.message}, code: ${response.statusCode}`
- } else {
+ }
+ else {
message = `检查更新失败: ${bodyObj && bodyObj.message ? bodyObj.message : body}`
}
win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: message })
}
- } catch (e) {
+ }
+ catch (e) {
log.error('检查更新失败:', e)
win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: `检查更新失败:${e.message}` })
}
@@ -248,7 +258,8 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
log.info('download dir:', fileDir)
try {
fs.accessSync(fileDir, fs.constants.F_OK)
- } catch (e) {
+ }
+ catch (e) {
fs.mkdirSync(fileDir)
}
const filePath = path.join(fileDir, `${value.version}.zip`)
@@ -288,7 +299,8 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
const zip = new AdmZip(partPackagePath)
zip.extractAllTo(target, true)
log.info('安装完成,重启app')
- } finally {
+ }
+ finally {
app.exit(0)
}
}
@@ -339,18 +351,21 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
}, 1000)
}
})
- } else if (arg.key === 'checkForUpdate') {
+ }
+ else if (arg.key === 'checkForUpdate') {
// 执行自动更新检查
log.info('autoUpdater checkForUpdates:', arg.fromUser)
// 调用 github API,获取release数据,来检查更新
// autoUpdater.checkForUpdates()
checkForUpdatesFromGitHub()
- } else if (arg.key === 'downloadUpdate') {
+ }
+ else if (arg.key === 'downloadUpdate') {
// 下载新版本
log.info('autoUpdater downloadUpdate')
autoUpdater.downloadUpdate()
- } else if (arg.key === 'downloadPart') {
+ }
+ else if (arg.key === 'downloadPart') {
// 下载增量更新版本
log.info('autoUpdater downloadPart')
downloadPart(app, arg.value)
diff --git a/packages/gui/src/bridge/update/front.js b/packages/gui/src/bridge/update/front.js
index b19d9d3069..06846462ff 100644
--- a/packages/gui/src/bridge/update/front.js
+++ b/packages/gui/src/bridge/update/front.js
@@ -31,23 +31,28 @@ function install (app, api) {
updateParams.checking = false
updateParams.newVersionData = message.value
foundNewVersion(message.value)
- } else if (type === 'notAvailable') {
+ }
+ else if (type === 'notAvailable') {
updateParams.checking = false
noNewVersion()
- } else if (type === 'downloaded') {
+ }
+ else if (type === 'downloaded') {
// 更新包已下载完成,让用户确认是否更新
updateParams.downloading = false
console.log('updateParams', updateParams)
newUpdateIsReady(message.value)
- } else if (type === 'progress') {
+ }
+ else if (type === 'progress') {
progressUpdate(message.value)
- } else if (type === 'error') {
+ }
+ else if (type === 'error') {
updateParams.checking = false
updateParams.downloading = false
if (message.action === 'checkForUpdate' && updateParams.newVersionData) {
// 如果检查更新报错了,但刚才成功拿到过一次数据,就拿之前的数据
foundNewVersion(updateParams.newVersionData)
- } else {
+ }
+ else {
if (updateParams.fromUser === false && message.action === 'checkForUpdate') {
return // 不是手动检查更新,不提示错误信息,避免打扰
}
@@ -83,7 +88,12 @@ function install (app, api) {
content: (h) => {
return (
)
@@ -154,20 +164,27 @@ function install (app, api) {
const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n')
return (
)
- } else {
+ }
+ else {
for (const note of value.releaseNotes) {
notes.push(
{note})
}
return (
@@ -200,20 +217,27 @@ function install (app, api) {
const releaseNotes = value.releaseNotes.replace(/\r\n/g, '\n')
return (
)
- } else {
+ }
+ else {
for (const note of value.releaseNotes) {
notes.push(
{note})
}
return (
diff --git a/packages/gui/src/utils/util.apppath.js b/packages/gui/src/utils/util.apppath.js
index 18878bb4ff..ea4941c807 100644
--- a/packages/gui/src/utils/util.apppath.js
+++ b/packages/gui/src/utils/util.apppath.js
@@ -1,5 +1,5 @@
-import os from 'os'
-import path from 'path'
+import os from 'node:os'
+import path from 'node:path'
function getSystemPlatform () {
switch (os.platform()) {
diff --git a/packages/gui/src/view/App.vue b/packages/gui/src/view/App.vue
index 059c1c3135..e58fb9365a 100644
--- a/packages/gui/src/view/App.vue
+++ b/packages/gui/src/view/App.vue
@@ -88,17 +88,17 @@ export default {
diff --git a/packages/gui/src/view/components/container.vue b/packages/gui/src/view/components/container.vue
index 35610a0526..8df89dd6ff 100644
--- a/packages/gui/src/view/components/container.vue
+++ b/packages/gui/src/view/components/container.vue
@@ -7,21 +7,27 @@ export default {
diff --git a/packages/gui/src/view/components/setup-ca.vue b/packages/gui/src/view/components/setup-ca.vue
index 8ad8fa9502..07bb2c941b 100644
--- a/packages/gui/src/view/components/setup-ca.vue
+++ b/packages/gui/src/view/components/setup-ca.vue
@@ -22,9 +22,11 @@ export default {
setupImage () {
if (this.systemPlatform === 'mac') {
return '/setup-mac.png'
- } else if (this.systemPlatform === 'linux') {
+ }
+ else if (this.systemPlatform === 'linux') {
return '/setup-linux.png'
- } else {
+ }
+ else {
return '/setup.png'
}
},
diff --git a/packages/gui/src/view/mixins/plugin.js b/packages/gui/src/view/mixins/plugin.js
index aa94c8673f..284e85d1a1 100644
--- a/packages/gui/src/view/mixins/plugin.js
+++ b/packages/gui/src/view/mixins/plugin.js
@@ -48,7 +48,8 @@ export default {
await this.applyBefore()
await this.saveConfig()
await this.applyAfter()
- } finally {
+ }
+ finally {
this.applyLoading = false
}
},
@@ -73,7 +74,8 @@ export default {
await this.ready(this.config)
}
await this.apply()
- } finally {
+ }
+ finally {
this.resetDefaultLoading = false
}
},
@@ -125,7 +127,8 @@ export default {
await this.$api.plugin.git.start()
}
this.$message.success('代理服务和系统代理重启成功')
- } else {
+ }
+ else {
this.$message.info('代理服务和系统代理未启动,无需重启')
}
},
diff --git a/packages/gui/src/view/pages/index.vue b/packages/gui/src/view/pages/index.vue
index d8f2f028e9..748492258e 100644
--- a/packages/gui/src/view/pages/index.vue
+++ b/packages/gui/src/view/pages/index.vue
@@ -21,7 +21,8 @@ export default {
doClick: () => {
if (this.status.server.enabled) {
this.apiCall(this.startup, this.$api.shutdown)
- } else {
+ }
+ else {
this.apiCall(this.startup, this.$api.startup)
}
},
@@ -75,11 +76,13 @@ export default {
this.config.server.intercept.enabled = false
this.config.server.dns.speedTest.enabled = true
this.config.plugin.overwall.enabled = false
- } else if (mode === 'default') {
+ }
+ else if (mode === 'default') {
this.config.server.intercept.enabled = true
this.config.server.dns.speedTest.enabled = true
this.config.plugin.overwall.enabled = false
- } else if (mode === 'ow') {
+ }
+ else if (mode === 'ow') {
console.log('event', event)
if (!this.setting.overwall) {
this.wantOW()
@@ -201,10 +204,12 @@ export default {
const ret = await api(param)
console.log('this status', this.status)
return ret
- } catch (err) {
+ }
+ catch (err) {
btn.loading = false // 有时候记录日志会卡死,先设置为false
console.log('api invoke error:', err)
- } finally {
+ }
+ finally {
btn.loading = false
}
},
@@ -212,7 +217,8 @@ export default {
onSwitchClick (btn, openApi, closeApi, checked) {
if (checked) {
return this.apiCall(btn, openApi)
- } else {
+ }
+ else {
return this.apiCall(btn, closeApi)
}
},
@@ -386,7 +392,7 @@ export default {
flex-direction: row;
align-items: center;
justify-content: space-between;
- padding:10px;
+ padding: 10px;
.donate {
cursor: pointer;
}
diff --git a/packages/gui/src/view/pages/plugin/git.vue b/packages/gui/src/view/pages/plugin/git.vue
index 7060a38c7a..dbbd78d06c 100644
--- a/packages/gui/src/view/pages/plugin/git.vue
+++ b/packages/gui/src/view/pages/plugin/git.vue
@@ -24,7 +24,8 @@ export default {
if (this.status.plugin.git.enabled) {
await this.$api.plugin.git.close()
this.needRestart = true
- } else {
+ }
+ else {
this.needRestart = false
}
this.submitNoProxyUrls()
@@ -115,8 +116,12 @@ export default {
diff --git a/packages/gui/src/view/pages/plugin/node.vue b/packages/gui/src/view/pages/plugin/node.vue
index e7b7aaa191..1956c56fc2 100644
--- a/packages/gui/src/view/pages/plugin/node.vue
+++ b/packages/gui/src/view/pages/plugin/node.vue
@@ -136,8 +136,12 @@ export default {
diff --git a/packages/gui/src/view/pages/plugin/overwall.vue b/packages/gui/src/view/pages/plugin/overwall.vue
index c6f062f2e1..1cf27574eb 100644
--- a/packages/gui/src/view/pages/plugin/overwall.vue
+++ b/packages/gui/src/view/pages/plugin/overwall.vue
@@ -213,8 +213,12 @@ export default {
diff --git a/packages/gui/src/view/pages/plugin/pip.vue b/packages/gui/src/view/pages/plugin/pip.vue
index 1c09d9dada..c9c7be1097 100644
--- a/packages/gui/src/view/pages/plugin/pip.vue
+++ b/packages/gui/src/view/pages/plugin/pip.vue
@@ -120,8 +120,12 @@ export default {
diff --git a/packages/gui/src/view/pages/proxy.vue b/packages/gui/src/view/pages/proxy.vue
index 51c361bdbb..28cffbe327 100644
--- a/packages/gui/src/view/pages/proxy.vue
+++ b/packages/gui/src/view/pages/proxy.vue
@@ -31,7 +31,8 @@ export default {
async openEnableLoopback () {
try {
await this.$api.proxy.setEnableLoopback()
- } catch (e) {
+ }
+ catch (e) {
if (e.message.includes('EACCES')) {
this.$message.error('请将DevSidecar关闭后,以管理员身份重新打开,再尝试此操作')
return
@@ -113,7 +114,9 @@ export default {
- 去设置
+
+ 去设置
+
解决OneNote
、MicrosoftStore
、Outlook
等UWP应用
开启代理后无法访问网络的问题
@@ -162,8 +165,12 @@ export default {
@@ -179,7 +186,9 @@ export default {
>
设置Loopback
- 打开EnableLoopback
+
+ 打开EnableLoopback
+
1、此设置用于解决OneNote、MicrosoftStore、Outlook等UWP应用无法访问网络的问题。
diff --git a/packages/gui/src/view/pages/server.vue b/packages/gui/src/view/pages/server.vue
index 1562f84dab..b353dfdaf3 100644
--- a/packages/gui/src/view/pages/server.vue
+++ b/packages/gui/src/view/pages/server.vue
@@ -407,8 +407,12 @@ export default {
- 立即重新测速
- 刷新
+
+ 立即重新测速
+
+
+ 刷新
+
@@ -434,8 +438,12 @@ export default {
@@ -454,7 +462,7 @@ export default {
}
.jsoneditor-vue {
- height: 100%
+ height: 100%;
}
.ant-tabs {
diff --git a/packages/gui/src/view/pages/setting.vue b/packages/gui/src/view/pages/setting.vue
index 776368bccd..b0df36e19c 100644
--- a/packages/gui/src/view/pages/setting.vue
+++ b/packages/gui/src/view/pages/setting.vue
@@ -218,10 +218,12 @@ export default {
await this.$api.config.downloadRemoteConfig()
this.$message.info('下载远程配置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
- } finally {
+ }
+ finally {
this.reloadLoading = false
}
- } else {
+ }
+ else {
this.$message.info('远程配置已关闭,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
}
@@ -244,11 +246,13 @@ export default {
if (remoteConfig.old1 === remoteConfig.new1 && remoteConfig.old2 === remoteConfig.new2) {
this.$message.info('远程配置没有变化,不做任何处理。')
this.$message.warn('如果您确实修改了远程配置,请稍等片刻再重试!')
- } else {
+ }
+ else {
this.$message.success('获取到了最新的远程配置,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
}
- } finally {
+ }
+ finally {
this.reloadLoading = false
}
},
@@ -256,7 +260,7 @@ export default {
this.$confirm({
title: '确定要恢复出厂设置吗?',
width: 610,
- content: (h) => (
+ content: h => (
@@ -276,7 +280,9 @@ export default {
1. 找到备份文件,路径:
~/.dev-sidecar/config.json.时间戳.bak.json
- 2. 将该备份文件重命名为config.json,再重启软件即可恢复个性化配置。
+ 2. 将该备份文件重命名为
+ config.json
+ ,再重启软件即可恢复个性化配置。
@@ -291,10 +297,12 @@ export default {
this.config = await this.$api.config.get()
this.$message.success('恢复出厂设置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
- } else {
+ }
+ else {
this.$message.info('已是出厂设置,无需恢复')
}
- } finally {
+ }
+ finally {
this.removeUserConfigLoading = false
}
},
@@ -316,7 +324,9 @@ export default {
本应用开机自启
- 日志
+
+ 日志
+
diff --git a/packages/gui/src/view/style/index.scss b/packages/gui/src/view/style/index.scss
index f58178e221..cae283934e 100644
--- a/packages/gui/src/view/style/index.scss
+++ b/packages/gui/src/view/style/index.scss
@@ -1,62 +1,93 @@
-.footer-bar{
- padding:10px;
+.footer-bar {
+ padding: 10px;
text-align: right;
- border-top:#eee 1px solid;
+ border-top: #eee 1px solid;
}
-.flex-l-r{
- align-content: center;
+.flex-l-r {
+ align-content: center;
display: flex;
justify-content: flex-end;
align-items: center;
- &>a{
- align-content: center;
+ & > a {
+ align-content: center;
display: flex;
align-items: center;
}
}
-.md-mr-5{margin-right: 5px;}
-.md-mr-10{margin-right: 10px;}
-.md-mr-15{margin-right: 15px;}
-.md-mr-20{margin-right: 20px;}
-
-.md-mt-5{margin-top: 5px;}
-.md-mt-10{margin-top: 10px;}
-.md-mt-15{margin-top: 15px;}
-.md-mt-20{margin-top: 20px;}
+.md-mr-5 {
+ margin-right: 5px;
+}
+.md-mr-10 {
+ margin-right: 10px;
+}
+.md-mr-15 {
+ margin-right: 15px;
+}
+.md-mr-20 {
+ margin-right: 20px;
+}
+.md-mt-5 {
+ margin-top: 5px;
+}
+.md-mt-10 {
+ margin-top: 10px;
+}
+.md-mt-15 {
+ margin-top: 15px;
+}
+.md-mt-20 {
+ margin-top: 20px;
+}
-.md-ml-5{margin-left: 5px;}
-.md-ml-10{margin-left: 10px;}
-.md-ml-15{margin-left: 15px;}
-.md-ml-20{margin-left: 20px;}
+.md-ml-5 {
+ margin-left: 5px;
+}
+.md-ml-10 {
+ margin-left: 10px;
+}
+.md-ml-15 {
+ margin-left: 15px;
+}
+.md-ml-20 {
+ margin-left: 20px;
+}
-.md-mb-5{margin-bottom: 5px;}
-.md-mb-10{margin-bottom: 10px;}
-.md-mb-15{margin-bottom: 15px;}
-.md-mb-20{margin-bottom: 20px;}
+.md-mb-5 {
+ margin-bottom: 5px;
+}
+.md-mb-10 {
+ margin-bottom: 10px;
+}
+.md-mb-15 {
+ margin-bottom: 15px;
+}
+.md-mb-20 {
+ margin-bottom: 20px;
+}
-ol{
+ol {
margin-block-start: 0em;
margin-block-end: 0em;
padding-inline-start: 20px;
}
-.form-help{
- font-size:12px;
+.form-help {
+ font-size: 12px;
line-height: 15px;
color: #a1a1a1;
- i{
- font-family: "Microsoft YaHei", serif;
+ i {
+ font-family: 'Microsoft YaHei', serif;
font-style: normal;
font-weight: bold;
}
code {
- padding: 0 .4em;
+ padding: 0 0.4em;
}
}
@@ -66,13 +97,13 @@ code {
border-radius: 6px;
color: #888;
background-color: #f1f1f1;
- margin-left: .2em;
- margin-right: .2em;
- padding: .2em .4em;
+ margin-left: 0.2em;
+ margin-right: 0.2em;
+ padding: 0.2em 0.4em;
white-space: break-spaces;
}
-.ace_search_form .ace_searchbtn{
+.ace_search_form .ace_searchbtn {
width: auto;
min-width: 27px;
}
@@ -106,4 +137,4 @@ hr {
padding: 2px 5px;
margin: 0 5px 5px 5px;
}
-}
\ No newline at end of file
+}
diff --git a/packages/gui/src/view/style/theme/dark.scss b/packages/gui/src/view/style/theme/dark.scss
index d11c2a1eea..8e72d35e0b 100644
--- a/packages/gui/src/view/style/theme/dark.scss
+++ b/packages/gui/src/view/style/theme/dark.scss
@@ -1,24 +1,28 @@
/* 暗色主题 */
-$dark-logo: url("../../../../public/logo/logo-lang-light.svg");
+$dark-logo: url('../../../../public/logo/logo-lang-light.svg');
$dark-bg: #1e1f22; //背景
$dark-bg-highlight: #333; //高亮块:背景
$dark-text: #ddd; //字体颜色
$dark-bd: #333; //边框和分隔线
$dark-btn: #444; //按钮:边框和背景颜色
$dark-input: #777; //输入框:背景色
-.theme-dark{
+.theme-dark {
hr {
border-color: $dark-bd;
}
/* 背景色和字体颜色 */
- .ds_layout, .ant-layout,
- .ds-container, .ds-container .container-header,
- .ant-layout-footer{
+ .ds_layout,
+ .ant-layout,
+ .ds-container,
+ .ds-container .container-header,
+ .ant-layout-footer {
background: $dark-bg;
color: $dark-text;
}
- div, span, label {
+ div,
+ span,
+ label {
color: $dark-text;
}
.form-help {
@@ -31,7 +35,7 @@ $dark-input: #777; //输入框:背景色
/* 高亮块:背景色和字体颜色 */
/* 警告类型 */
- .ant-alert-warning{
+ .ant-alert-warning {
background: $dark-bg-highlight;
border-color: $dark-bg-highlight;
color: $dark-text;
@@ -41,7 +45,7 @@ $dark-input: #777; //输入框:背景色
}
}
/* 消息类型 */
- .ant-alert-info{
+ .ant-alert-info {
background: $dark-bg-highlight;
border-color: $dark-bg-highlight;
color: $dark-text;
@@ -55,7 +59,7 @@ $dark-input: #777; //输入框:背景色
.footer-bar,
.ant-layout-footer,
.ant-tabs .ant-tabs-left-bar,
- .ant-tabs .ant-tabs-left-content{
+ .ant-tabs .ant-tabs-left-content {
border-color: $dark-bd;
}
.ant-radio-button-wrapper:not(:first-child)::before {
@@ -67,138 +71,146 @@ $dark-input: #777; //输入框:背景色
/* 左侧 */
/** 背景色 **/
- .ant-layout-sider{
+ .ant-layout-sider {
background: $dark-bg;
}
/** Logo **/
- .logo{
+ .logo {
background-image: $dark-logo; /* logo使用亮色的 */
}
/** 菜单 **/
- .ant-menu{
+ .ant-menu {
background: $dark-bg;
color: $dark-text;
}
/* 菜单选中时,或鼠标移到菜单上时的样式 */
.ant-menu-item:hover,
.ant-menu-submenu .ant-menu-submenu-title:hover,
- .ant-menu:not(.ant-menu-horizontal) .ant-menu-item-selected{
+ .ant-menu:not(.ant-menu-horizontal) .ant-menu-item-selected {
background: $dark-bg-highlight;
color: #1890ff;
- span{ color: #1890ff; }
+ span {
+ color: #1890ff;
+ }
}
/* 输入框、下拉框 */
.ant-input,
- .ant-input-number-input, .ant-input-number,
+ .ant-input-number-input,
+ .ant-input-number,
.ant-select-selection,
- .ant-input-group-addon{
+ .ant-input-group-addon {
background: $dark-input;
border-color: #aaa;
color: $dark-text;
- &:hover, &:focus{
+ &:hover,
+ &:focus {
border-color: #fff;
}
}
/* 卡片消息:IP测速 */
- .ant-card{
+ .ant-card {
background: $dark-input;
border-color: $dark-input;
- .ant-card-head{
+ .ant-card-head {
border-bottom-color: #929292;
}
}
/* 标签:未启用 */
- .ant-tag-red{
+ .ant-tag-red {
background: #4f4749;
border-color: #4f4749;
color: #bf8285;
}
/* 标签:已启用 */
- .ant-tag-green{
+ .ant-tag-green {
background: #505f5f;
border-color: #505f5f;
color: #90cb9f;
}
/* 标签:警告 */
- .ant-tag-orange{
+ .ant-tag-orange {
background: #5a5750;
border-color: #5a5750;
color: #cfa572;
}
/* 按钮 */
- .ant-btn:not(.ant-btn-danger, .ant-btn-primary){
+ .ant-btn:not(.ant-btn-danger, .ant-btn-primary) {
background: $dark-btn;
border-color: $dark-btn;
color: $dark-text;
- &:hover{
+ &:hover {
opacity: 0.8;
}
}
/* 单选框:开关式 */
- .ant-switch:not(.ant-switch-checked){
+ .ant-switch:not(.ant-switch-checked) {
background: $dark-btn;
border-color: $dark-btn;
- &:hover{
+ &:hover {
opacity: 0.8;
}
}
/* 单选框:按钮式 */
- .ant-radio-button-wrapper{
+ .ant-radio-button-wrapper {
background: $dark-btn;
border-color: $dark-btn;
color: $dark-text;
- &:hover{
+ &:hover {
opacity: 0.8;
}
}
/* JSON编辑器:应用于拦截设置 */
- .jsoneditor-vue{
+ .jsoneditor-vue {
/*整个编辑框:背景色和边框*/
- div.jsoneditor{
+ div.jsoneditor {
background: $dark-bg-highlight;
border: none;
}
/* 头部菜单栏:边框 */
- div.jsoneditor-menu{
+ div.jsoneditor-menu {
background: $dark-bg-highlight;
border-color: $dark-bg-highlight;
}
/* 内容区域左边:行号 */
- .ace_gutter{
+ .ace_gutter {
background: #444;
- .ace_gutter-cell { color: #aaa; }
+ .ace_gutter-cell {
+ color: #aaa;
+ }
}
/* 内容区域右边:JSON内容 */
- .ace_scroller{
+ .ace_scroller {
background: #555;
}
/* key的颜色 */
- .ace_variable, .ace_text-layer{
+ .ace_variable,
+ .ace_text-layer {
color: #eee;
}
/* 字符串值的颜色 */
- .ace_string, .ace_cjk{
+ .ace_string,
+ .ace_cjk {
color: #a6eaa6;
}
- .ace_constant{
+ .ace_constant {
/* 数字的颜色 */
- &.ace_numeric{
+ &.ace_numeric {
color: #ec9999;
}
/* 布尔值的颜色 */
- &.ace_language{
+ &.ace_language {
color: #f4c995;
}
}
/* 当前行高亮样式 */
.ace_gutter-active-line,
- .ace_marker-layer .ace_active-line{
+ .ace_marker-layer .ace_active-line {
background: #838774;
}
/* 选中行高亮样式 */
@@ -213,7 +225,9 @@ $dark-input: #777; //输入框:背景色
}
}
/* 搜索框 */
- .ace_button, button, .ace_search_field {
+ .ace_button,
+ button,
+ .ace_search_field {
color: #000;
}
/* 搜索结果 */
@@ -221,4 +235,4 @@ $dark-input: #777; //输入框:背景色
border-color: #8b2929;
}
}
-}
\ No newline at end of file
+}
diff --git a/packages/gui/vue.config.js b/packages/gui/vue.config.js
index fcb013f95b..20a833fab0 100644
--- a/packages/gui/vue.config.js
+++ b/packages/gui/vue.config.js
@@ -1,6 +1,6 @@
-const path = require('path')
-const webpack = require('webpack')
+const path = require('node:path')
const { defineConfig } = require('@vue/cli-service')
+const webpack = require('webpack')
const publishUrl = process.env.VUE_APP_PUBLISH_URL
const publishProvider = process.env.VUE_APP_PUBLISH_PROVIDER
@@ -33,7 +33,7 @@ module.exports = defineConfig({
},
pluginOptions: {
electronBuilder: {
- mainProcessFile: "./src/background.js",
+ mainProcessFile: './src/background.js',
// Ref: https://github.com/nklayman/vue-cli-plugin-electron-builder/issues/1891
customFileProtocol: './',
externals: [
diff --git a/packages/mitmproxy/src/index.js b/packages/mitmproxy/src/index.js
index 4e0dba6314..cf08359470 100644
--- a/packages/mitmproxy/src/index.js
+++ b/packages/mitmproxy/src/index.js
@@ -12,7 +12,8 @@ function registerProcessListener () {
log.info('child get msg:', JSON.stringify(msg))
if (msg.type === 'action') {
api[msg.event.key](msg.event.params)
- } else if (msg.type === 'speed') {
+ }
+ else if (msg.type === 'speed') {
speedTest.action(msg.event)
}
})
@@ -61,7 +62,8 @@ const api = {
if (proxyOptions.setting && proxyOptions.setting.NODE_TLS_REJECT_UNAUTHORIZED === false) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
- } else {
+ }
+ else {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'
}
// log.info('启动代理服务时的配置:', JSON.stringify(proxyOptions, null, '\t'))
@@ -98,7 +100,8 @@ const api = {
if (err.code === 'ERR_SERVER_NOT_RUNNING') {
log.info('代理服务未运行,无需关闭')
resolve()
- } else {
+ }
+ else {
log.error('代理服务关闭失败:', err)
reject(err)
}
@@ -110,7 +113,8 @@ const api = {
})
}
servers = []
- } else {
+ }
+ else {
log.info('server is null, no need to close.')
fireStatus(false)
resolve()
diff --git a/packages/mitmproxy/src/json.js b/packages/mitmproxy/src/json.js
index 3b2d3072ce..cf0e09ab02 100644
--- a/packages/mitmproxy/src/json.js
+++ b/packages/mitmproxy/src/json.js
@@ -1,5 +1,6 @@
-const log = require('./utils/util.log')
let JSON5 = require('json5')
+const log = require('./utils/util.log')
+
if (JSON5.default) {
JSON5 = JSON5.default
}
@@ -16,10 +17,12 @@ module.exports = {
stringify2 (obj) {
try {
return JSON.stringify(obj)
- } catch (e) {
+ }
+ catch (e) {
try {
return JSON5.stringify(obj)
- } catch (e2) {
+ }
+ catch (e2) {
log.debug('转换为JSON字符串失败, error:', e, ', obj:', obj)
return obj
}
diff --git a/packages/mitmproxy/src/lib/choice/index.js b/packages/mitmproxy/src/lib/choice/index.js
index 964c2c6ff5..867876094c 100644
--- a/packages/mitmproxy/src/lib/choice/index.js
+++ b/packages/mitmproxy/src/lib/choice/index.js
@@ -88,7 +88,8 @@ class DynamicChoice {
if (this.backupList.length > 0) {
this.value = this.backupList.shift()
log.info(`切换backup完成: ${this.key}, ip: ${valueBackup} ➜ ${this.value}, this:`, this)
- } else {
+ }
+ else {
this.value = null
log.info(`切换backup完成: ${this.key}, backupList为空了,设置this.value: from '${valueBackup}' to null. this:`, this)
}
@@ -109,7 +110,8 @@ class DynamicChoice {
// 失败次数+1,累计连续失败次数+1
count.error++
count.keepErrorCount++
- } else {
+ }
+ else {
// 总次数+1
count.total++
}
diff --git a/packages/mitmproxy/src/lib/dns/base.js b/packages/mitmproxy/src/lib/dns/base.js
index 14d2ca2041..3b6637f131 100644
--- a/packages/mitmproxy/src/lib/dns/base.js
+++ b/packages/mitmproxy/src/lib/dns/base.js
@@ -43,7 +43,8 @@ module.exports = class BaseDNS {
ipCache.doCount(ipCache.value, false)
return ipCache.value
}
- } else {
+ }
+ else {
ipCache = new IpCache(hostname)
this.cache.set(hostname, ipCache)
}
@@ -60,7 +61,8 @@ module.exports = class BaseDNS {
log.info(`[DNS]: ${hostname} ➜ ${ipCache.value} (${new Date() - t} ms), ipList: ${JSON.stringify(ipList)}, ipCache:`, JSON.stringify(ipCache))
return ipCache.value
- } catch (error) {
+ }
+ catch (error) {
log.error(`[DNS] cannot resolve hostname ${hostname} (${error})`, error)
return hostname
}
diff --git a/packages/mitmproxy/src/lib/dns/https.js b/packages/mitmproxy/src/lib/dns/https.js
index 2cd39c8a2d..eb76a296b0 100644
--- a/packages/mitmproxy/src/lib/dns/https.js
+++ b/packages/mitmproxy/src/lib/dns/https.js
@@ -1,4 +1,4 @@
-const { promisify } = require('util')
+const { promisify } = require('node:util')
const doh = require('dns-over-http')
const log = require('../../utils/util.log')
const matchUtil = require('../../utils/util.match')
@@ -30,7 +30,8 @@ module.exports = class DNSOverHTTPS extends BaseDNS {
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
if (hostnamePreSetIpList.length > 0) {
hostnamePreSetIpList = hostnamePreSetIpList.slice()
- } else {
+ }
+ else {
hostnamePreSetIpList = mapToList(hostnamePreSetIpList)
}
@@ -52,11 +53,13 @@ module.exports = class DNSOverHTTPS extends BaseDNS {
const ret = result.answers.filter(item => item.type === 'A').map(item => item.data)
if (ret.length === 0) {
log.info('该域名没有IPv4地址解析:', hostname, ', cost:', (new Date() - start), 'ms')
- } else {
+ }
+ else {
log.info('获取到域名地址:', hostname, JSON.stringify(ret), ', cost:', (new Date() - start), 'ms')
}
return ret
- } catch (e) {
+ }
+ catch (e) {
log.warn('DNS query error:', hostname, ', dns:', this.dnsServer, ', cost:', (new Date() - start), 'ms, error:', e)
return []
}
diff --git a/packages/mitmproxy/src/lib/dns/index.js b/packages/mitmproxy/src/lib/dns/index.js
index 0e23f7a5b5..297694cc3f 100644
--- a/packages/mitmproxy/src/lib/dns/index.js
+++ b/packages/mitmproxy/src/lib/dns/index.js
@@ -14,9 +14,11 @@ module.exports = {
if (conf.type === 'ipaddress') {
dnsMap[provider] = new DNSOverIpAddress(conf.server)
- } else if (conf.type === 'https') {
+ }
+ else if (conf.type === 'https') {
dnsMap[provider] = new DNSOverHTTPS(conf.server, preSetIpList)
- } else {
+ }
+ else {
dnsMap[provider] = new DNSOverTLS(conf.server)
}
diff --git a/packages/mitmproxy/src/lib/dns/ipaddress.js b/packages/mitmproxy/src/lib/dns/ipaddress.js
index 9ed0bf3b18..900995ed0a 100644
--- a/packages/mitmproxy/src/lib/dns/ipaddress.js
+++ b/packages/mitmproxy/src/lib/dns/ipaddress.js
@@ -14,7 +14,7 @@ module.exports = class DNSOverIpAddress extends BaseDNS {
}
const ret = res.data
- const regexp = /IP Address<\/th> | - ([^<]*)<\/li><\/ul><\/td><\/tr>/gm
+ const regexp = /
IP Address<\/th> | - ([^<]*)<\/li><\/ul><\/td><\/tr>/g
const matched = regexp.exec(ret)
let ip = null
diff --git a/packages/mitmproxy/src/lib/dns/preset.js b/packages/mitmproxy/src/lib/dns/preset.js
index f5e0e1a21b..3ff7dafd6a 100644
--- a/packages/mitmproxy/src/lib/dns/preset.js
+++ b/packages/mitmproxy/src/lib/dns/preset.js
@@ -26,7 +26,8 @@ module.exports = class DNSOverPreSetIpList extends BaseDNS {
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
if (hostnamePreSetIpList.length > 0) {
hostnamePreSetIpList = hostnamePreSetIpList.slice()
- } else {
+ }
+ else {
hostnamePreSetIpList = mapToList(hostnamePreSetIpList)
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/OPTIONS.js b/packages/mitmproxy/src/lib/interceptor/impl/req/OPTIONS.js
index 45b6c863e0..b55e11718c 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/OPTIONS.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/OPTIONS.js
@@ -6,7 +6,8 @@ function readConfig (config, defaultConfig) {
if (Object.isArray(config)) {
config = config.join(',')
}
- } else {
+ }
+ else {
config = defaultConfig
}
return config
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/baiduOcr.js b/packages/mitmproxy/src/lib/interceptor/impl/req/baiduOcr.js
index dcce58773b..926eaf1af8 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/baiduOcr.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/baiduOcr.js
@@ -60,7 +60,8 @@ function getConfig (interceptOpt, tryCount, log) {
if (count >= 100000) {
count = 0
}
- } else {
+ }
+ else {
config = interceptOpt.baiduOcr
tryCount = null // 将tryCount设置为null代表只有一个配置
}
@@ -83,11 +84,13 @@ function getConfig (interceptOpt, tryCount, log) {
if (config.api == null) {
if (tryCount == null) {
return null // 只配置了一个账号,没有更多账号可以选择了,直接返回null
- } else {
+ }
+ else {
if (tryCount < interceptOpt.baiduOcr.length) {
// 递归找到有效的配置
return getConfig(interceptOpt, tryCount + 1, log)
- } else {
+ }
+ else {
return null
}
}
@@ -164,7 +167,8 @@ module.exports = {
limitConfig(config.id, config.api)
log.error(`当前百度云账号的接口 ${config.api},已达到当日调用次数上限,暂时禁用它,明天会自动放开:`, config)
}
- } else {
+ }
+ else {
log.info('baiduOcr success:', result)
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/cacheReq.js b/packages/mitmproxy/src/lib/interceptor/impl/req/cacheReq.js
index 5028002b15..5246be4886 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/cacheReq.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/cacheReq.js
@@ -42,7 +42,8 @@ function getLastModifiedTimeFromIfModifiedSince (rOptions, log) {
try {
// 尝试解析 lastModified,并获取time
return new Date(lastModified).getTime()
- } catch (e) {
+ }
+ catch (e) {
// 为数字时,直接返回
if (/\\d+/.test(lastModified)) {
return lastModified - 0
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js b/packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js
index 6dcf19cc83..327f4be679 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js
@@ -1,4 +1,4 @@
-const url = require('url')
+const url = require('node:url')
const lodash = require('lodash')
// 替换占位符
@@ -27,9 +27,11 @@ function buildTargetUrl (rOptions, urlConf, interceptOpt, matched) {
if (interceptOpt && interceptOpt.replace) {
const regexp = new RegExp(interceptOpt.replace)
targetUrl = rOptions.path.replace(regexp, urlConf)
- } else if (urlConf.indexOf('http:') === 0 || urlConf.indexOf('https:') === 0) {
+ }
+ else if (urlConf.indexOf('http:') === 0 || urlConf.indexOf('https:') === 0) {
targetUrl = urlConf
- } else {
+ }
+ else {
let uri = rOptions.path
if (uri.indexOf('http:') === 0 || uri.indexOf('https:') === 0) {
// eslint-disable-next-line node/no-deprecated-api
@@ -95,7 +97,8 @@ module.exports = {
}
if (count.value == null) {
log.error('`count.value` is null, the count:', count)
- } else {
+ }
+ else {
count.doCount(count.value)
proxyConf = count.value
context.requestCount = {
@@ -124,7 +127,8 @@ module.exports = {
}
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}, sni: ${interceptOpt.sni}${unVerifySsl ? ', unVerifySsl' : ''}`)
log.info('proxy intercept: hostname:', originHostname, ', target:', proxyTarget, ', sni replace servername:', rOptions.servername, (unVerifySsl ? ', unVerifySsl' : ''))
- } else {
+ }
+ else {
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}`)
log.info('proxy intercept: hostname:', originHostname, ', target:', proxyTarget)
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/requestReplace.js b/packages/mitmproxy/src/lib/interceptor/impl/req/requestReplace.js
index 219959d526..7ed12c2ef6 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/requestReplace.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/requestReplace.js
@@ -10,7 +10,8 @@ function replaceRequestHeaders (rOptions, headers, log) {
if (value) {
log.debug(`[DS-RequestReplace-Interceptor] replace '${key}': '${rOptions.headers[key.toLowerCase()]}' -> '${value}'`)
rOptions.headers[key.toLowerCase()] = value
- } else if (rOptions.headers[key.toLowerCase()]) {
+ }
+ else if (rOptions.headers[key.toLowerCase()]) {
log.debug(`[DS-RequestReplace-Interceptor] remove '${key}': '${rOptions.headers[key.toLowerCase()]}'`)
delete rOptions.headers[key.toLowerCase()]
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/res/cacheRes.js b/packages/mitmproxy/src/lib/interceptor/impl/res/cacheRes.js
index 62f37feee0..54fe7a2c31 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/res/cacheRes.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/res/cacheRes.js
@@ -47,11 +47,14 @@ module.exports = {
// 尝试修改rawHeaders中的cache-control、last-modified、expires
if (proxyRes.rawHeaders[i].toLowerCase() === 'cache-control') {
originalHeaders.cacheControl = { value: proxyRes.rawHeaders[i + 1], valueIndex: i + 1 }
- } else if (proxyRes.rawHeaders[i].toLowerCase() === 'last-modified') {
+ }
+ else if (proxyRes.rawHeaders[i].toLowerCase() === 'last-modified') {
originalHeaders.lastModified = { value: proxyRes.rawHeaders[i + 1], valueIndex: i + 1 }
- } else if (proxyRes.rawHeaders[i].toLowerCase() === 'expires') {
+ }
+ else if (proxyRes.rawHeaders[i].toLowerCase() === 'expires') {
originalHeaders.expires = { value: proxyRes.rawHeaders[i + 1], valueIndex: i + 1 }
- } else if (proxyRes.rawHeaders[i].toLowerCase() === 'etag') {
+ }
+ else if (proxyRes.rawHeaders[i].toLowerCase() === 'etag') {
originalHeaders.etag = { value: proxyRes.rawHeaders[i + 1], valueIndex: i + 1 }
}
@@ -67,7 +70,8 @@ module.exports = {
if (maxAgeMatch && maxAgeMatch[1] > maxAge) {
if (interceptOpt.cacheImmutable !== false && !originalHeaders.cacheControl.value.includes('immutable')) {
maxAge = maxAgeMatch[1]
- } else {
+ }
+ else {
const url = `${rOptions.method} ➜ ${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${req.url}`
res.setHeader('DS-Cache-Response-Interceptor', `skip: ${maxAgeMatch[1]} > ${maxAge}`)
log.info(`cache response intercept: skip: ${maxAgeMatch[1]} > ${maxAge}, url: ${url}`)
@@ -87,19 +91,22 @@ module.exports = {
// 替换cache-control
if (originalHeaders.cacheControl) {
proxyRes.rawHeaders[originalHeaders.cacheControl.valueIndex] = replaceHeaders.cacheControl
- } else {
+ }
+ else {
res.setHeader('Cache-Control', replaceHeaders.cacheControl)
}
// 替换last-modified
if (originalHeaders.lastModified) {
proxyRes.rawHeaders[originalHeaders.lastModified.valueIndex] = replaceHeaders.lastModified
- } else {
+ }
+ else {
res.setHeader('Last-Modified', replaceHeaders.lastModified)
}
// 替换expires
if (originalHeaders.expires) {
proxyRes.rawHeaders[originalHeaders.expires.valueIndex] = replaceHeaders.expires
- } else {
+ }
+ else {
res.setHeader('Expires', replaceHeaders.expires)
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js b/packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js
index 7c7719ec24..2086018c52 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js
@@ -31,7 +31,8 @@ function replaceResponseHeaders (newHeaders, res, proxyRes) {
preHeaders[headerKey] = proxyRes.rawHeaders[i + 1] // 先保存原先响应头
if (newHeaderValue === REMOVE) { // 由于拦截配置中不允许配置null,会被删,所以配置一个 "[remove]",当作删除响应头的意思
proxyRes.rawHeaders[i + 1] = ''
- } else {
+ }
+ else {
proxyRes.rawHeaders[i + 1] = newHeaderValue
}
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/res/script.js b/packages/mitmproxy/src/lib/interceptor/impl/res/script.js
index 58e7581765..24c502a511 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/res/script.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/res/script.js
@@ -52,7 +52,8 @@ module.exports = {
if (key.includes('/')) {
scriptTag = getScriptByUrlOrPath(key) // 1.绝对地址或相对地址(注意:当目标站点限制跨域脚本时,可使用相对地址,再结合proxy拦截器进行代理,可规避掉限制跨域脚本问题。)
- } else {
+ }
+ else {
const script = scripts[key]
if (script == null) {
continue
@@ -71,7 +72,8 @@ module.exports = {
// 插入油猴脚本浏览器扩展
if (typeof interceptOpt.tampermonkeyScript === 'string') {
tags = `\r\n\t${getScriptByUrlOrPath(interceptOpt.tampermonkeyScript)}${tags}`
- } else {
+ }
+ else {
tags = `\r\n\t${getScript('tampermonkey', scripts.tampermonkey.script)}${tags}`
}
@@ -80,10 +82,12 @@ module.exports = {
return {
head: `${tags}\r\n`,
}
- } catch (err) {
+ }
+ catch (err) {
try {
res.setHeader('DS-Script-Interceptor', 'error')
- } catch (e) {
+ }
+ catch (e) {
// ignore
}
log.error('load monkey script error', err)
@@ -108,7 +112,8 @@ module.exports = {
if (typeof replaceScriptUrlFun === 'function') {
replaceScriptUrlFun(scriptKey)
}
- } else if (scriptUrl.indexOf('/') === 0) {
+ }
+ else if (scriptUrl.indexOf('/') === 0) {
// 相对地址
scriptProxy[scriptUrl] = scriptUrl
}
@@ -124,7 +129,8 @@ module.exports = {
pathConfig.script[i] = scriptKey
})
}
- } else if (typeof pathConfig.script === 'string') {
+ }
+ else if (typeof pathConfig.script === 'string') {
handleScriptUrl(pathConfig.script, 'script', (scriptKey) => {
pathConfig.script = scriptKey
})
@@ -174,7 +180,8 @@ module.exports = {
const obj = {}
obj[pathPattern] = hostnameConfig[pathPattern]
log.debug(`域名 '${hostnamePattern}' 拦截配置中,新增伪脚本地址的代理配置:`, JSON.stringify(obj, null, '\t'))
- } else {
+ }
+ else {
// 相对地址:新增响应头Content-Type替换配置
if (hostnameConfig[scriptKey]) {
continue // 配置已经存在,按自定义配置优先
diff --git a/packages/mitmproxy/src/lib/interceptor/index.js b/packages/mitmproxy/src/lib/interceptor/index.js
index a37b6f560a..be7cbc9c3c 100644
--- a/packages/mitmproxy/src/lib/interceptor/index.js
+++ b/packages/mitmproxy/src/lib/interceptor/index.js
@@ -1,17 +1,17 @@
+const abort = require('./impl/req/abort')
+
+const baiduOcr = require('./impl/req/baiduOcr')
+const cacheReq = require('./impl/req/cacheReq')
// request interceptor impls
const OPTIONS = require('./impl/req/OPTIONS.js')
+const proxy = require('./impl/req/proxy')
-const success = require('./impl/req/success')
const redirect = require('./impl/req/redirect')
-const abort = require('./impl/req/abort')
-const cacheReq = require('./impl/req/cacheReq')
const requestReplace = require('./impl/req/requestReplace')
-
-const proxy = require('./impl/req/proxy')
const sni = require('./impl/req/sni')
-const baiduOcr = require('./impl/req/baiduOcr')
+const success = require('./impl/req/success')
// response interceptor impls
const OPTIONSHeaders = require('./impl/res/AfterOPTIONSHeaders')
@@ -23,12 +23,18 @@ const script = require('./impl/res/script')
module.exports = [
// request interceptor impls
OPTIONS,
- success, redirect, abort, cacheReq,
+ success,
+ redirect,
+ abort,
+ cacheReq,
requestReplace,
- proxy, sni,
+ proxy,
+ sni,
baiduOcr,
// response interceptor impls
- OPTIONSHeaders, cacheRes, responseReplace,
+ OPTIONSHeaders,
+ cacheRes,
+ responseReplace,
script,
]
diff --git a/packages/mitmproxy/src/lib/monkey/index.js b/packages/mitmproxy/src/lib/monkey/index.js
index fbd1daa356..40715a41d2 100644
--- a/packages/mitmproxy/src/lib/monkey/index.js
+++ b/packages/mitmproxy/src/lib/monkey/index.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const log = require('../../utils/util.log')
let scripts
@@ -12,7 +12,8 @@ function buildScript (sc, content, scriptName) {
let eventStr
if (runAt === 'document-end') {
eventStr = 'document.addEventListener("DOMContentLoaded"'
- } else {
+ }
+ else {
eventStr = 'window.addEventListener("load"'
}
@@ -47,7 +48,8 @@ if (!((window.__ds_global__ || {}).GM_getValue || (() => true))("ds_enabled", tr
if (item.indexOf('.') > 0) {
grantStr += `${item} = (window.__ds_global__ || {})['${item}'];`
- } else {
+ }
+ else {
grantStr += `const ${item} = (window.__ds_global__ || {})['${item}'] || (() => {});`
}
}
@@ -57,10 +59,10 @@ if (!((window.__ds_global__ || {}).GM_getValue || (() => true))("ds_enabled", tr
initStr}\r\n${
checkEnabledStr}\r\n\r\n${
grantStr ? (`${grantStr}\r\n\r\n`) : ''
- }${content
- }\r\nconsole.log("${scriptKey} completed")`
- + `\r\n})`
- + `\r\nconsole.log("${scriptKey} loaded")`
+ }${content
+ }\r\nconsole.log("${scriptKey} completed")`
+ + `\r\n})`
+ + `\r\nconsole.log("${scriptKey} loaded")`
}
function loadScript (content, scriptName) {
@@ -89,9 +91,11 @@ function loadScript (content, scriptName) {
const value = ret[2].trim()
if (key === 'grant') {
sc.grant.push(value)
- } else if (key === 'match') {
+ }
+ else if (key === 'match') {
sc.match.push(value)
- } else {
+ }
+ else {
sc[key] = value
}
}
diff --git a/packages/mitmproxy/src/lib/proxy/common/config.js b/packages/mitmproxy/src/lib/proxy/common/config.js
index 0453c1b6e4..617fbc9cea 100644
--- a/packages/mitmproxy/src/lib/proxy/common/config.js
+++ b/packages/mitmproxy/src/lib/proxy/common/config.js
@@ -1,4 +1,4 @@
-const path = require('path')
+const path = require('node:path')
const config = exports
diff --git a/packages/mitmproxy/src/lib/proxy/common/util.js b/packages/mitmproxy/src/lib/proxy/common/util.js
index 0ab2a04527..35a396397e 100644
--- a/packages/mitmproxy/src/lib/proxy/common/util.js
+++ b/packages/mitmproxy/src/lib/proxy/common/util.js
@@ -1,4 +1,4 @@
-const url = require('url')
+const url = require('node:url')
const tunnelAgent = require('tunnel-agent')
const log = require('../../../utils/util.log')
const matchUtil = require('../../../utils/util.match')
@@ -83,7 +83,8 @@ util.parseHostnameAndPort = (host, defaultPort) => {
if (arr[1]) {
arr[1] = Number.parseInt(arr[1], 10)
}
- } else {
+ }
+ else {
arr = host.split(':')
if (arr.length > 1) {
arr[1] = Number.parseInt(arr[1], 10)
@@ -92,7 +93,8 @@ util.parseHostnameAndPort = (host, defaultPort) => {
if (defaultPort > 0 && (arr.length === 1 || arr[1] === undefined)) {
arr[1] = defaultPort
- } else if (arr.length === 2 && arr[1] === undefined) {
+ }
+ else if (arr.length === 2 && arr[1] === undefined) {
arr.pop()
}
@@ -110,10 +112,12 @@ util.getOptionsFromRequest = (req, ssl, externalProxy = null, serverSetting, com
if (externalProxy) {
if (typeof externalProxy === 'string') {
externalProxyUrl = externalProxy
- } else if (typeof externalProxy === 'function') {
+ }
+ else if (typeof externalProxy === 'function') {
try {
externalProxyUrl = externalProxy(req, ssl)
- } catch (e) {
+ }
+ catch (e) {
log.error('externalProxy error:', e)
}
}
@@ -133,10 +137,12 @@ util.getOptionsFromRequest = (req, ssl, externalProxy = null, serverSetting, com
// log.info(`get timeoutConfig '${hostname}':`, timeoutConfig)
agent = createAgent(protocol, timeoutConfig, serverSetting.verifySsl)
headers.connection = 'keep-alive'
- } else {
+ }
+ else {
agent = false
}
- } else {
+ }
+ else {
agent = util.getTunnelAgent(protocol === 'https:', externalProxyUrl)
}
@@ -166,7 +172,8 @@ util.getOptionsFromRequest = (req, ssl, externalProxy = null, serverSetting, com
// mark a socketId for Agent to bind socket for NTLM
if (req.socket.customSocketId) {
options.customSocketId = req.socket.customSocketId
- } else if (headers.authorization) {
+ }
+ else if (headers.authorization) {
options.customSocketId = req.socket.customSocketId = socketId++
}
@@ -194,7 +201,8 @@ util.getTunnelAgent = (requestIsSSL, externalProxyUrl) => {
})
}
return httpsOverHttpAgent
- } else {
+ }
+ else {
if (!httpsOverHttpsAgent) {
httpsOverHttpsAgent = tunnelAgent.httpsOverHttps({
proxy: {
@@ -205,7 +213,8 @@ util.getTunnelAgent = (requestIsSSL, externalProxyUrl) => {
}
return httpsOverHttpsAgent
}
- } else {
+ }
+ else {
if (protocol === 'http:') {
// if (!httpOverHttpAgent) {
// httpOverHttpAgent = tunnelAgent.httpOverHttp({
@@ -216,7 +225,8 @@ util.getTunnelAgent = (requestIsSSL, externalProxyUrl) => {
// })
// }
return false
- } else {
+ }
+ else {
if (!httpOverHttpsAgent) {
httpOverHttpsAgent = tunnelAgent.httpOverHttps({
proxy: {
diff --git a/packages/mitmproxy/src/lib/proxy/compatible/compatible.js b/packages/mitmproxy/src/lib/proxy/compatible/compatible.js
index dd4eb2b0d0..a8dc4fa58b 100644
--- a/packages/mitmproxy/src/lib/proxy/compatible/compatible.js
+++ b/packages/mitmproxy/src/lib/proxy/compatible/compatible.js
@@ -5,8 +5,8 @@
*
* @author WangLiang
*/
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const jsonApi = require('../../../json')
const log = require('../../../utils/util.log')
const matchUtil = require('../../../utils/util.match')
@@ -58,7 +58,8 @@ function _loadFromFile (defaultConfig) {
if (!fs.existsSync(configPath)) {
config = defaultConfig
log.info(`本地未保存过 ${configPath} 文件,使用默认配置`)
- } else {
+ }
+ else {
const file = fs.readFileSync(configPath)
log.info('读取 automaticCompatibleConfig.json 成功:', configPath)
const fileStr = file.toString()
@@ -79,7 +80,8 @@ function _saveConfigToFile () {
try {
fs.writeFileSync(filePath, jsonApi.stringify(config))
log.info('保存 automaticCompatibleConfig.json 成功:', filePath)
- } catch (e) {
+ }
+ catch (e) {
log.error('保存 automaticCompatibleConfig.json 失败:', filePath, e)
}
}
@@ -107,7 +109,8 @@ module.exports = {
const connectCompatibleConfig = this.getConnectCompatibleConfig(hostname, port)
if (connectCompatibleConfig) {
connectCompatibleConfig.ssl = ssl
- } else {
+ }
+ else {
config.connect[`${hostname}:${port}`] = { ssl }
}
@@ -139,7 +142,8 @@ module.exports = {
const requestCompatibleConfig = this.getRequestCompatibleConfig(rOptions.hostname, rOptions.port)
if (requestCompatibleConfig) {
requestCompatibleConfig.rejectUnauthorized = rejectUnauthorized
- } else {
+ }
+ else {
config.request[`${rOptions.hostname}:${rOptions.port}`] = { rejectUnauthorized }
}
diff --git a/packages/mitmproxy/src/lib/proxy/middleware/InsertScriptMiddleware.js b/packages/mitmproxy/src/lib/proxy/middleware/InsertScriptMiddleware.js
index ce3b107a05..c7c7325d8a 100644
--- a/packages/mitmproxy/src/lib/proxy/middleware/InsertScriptMiddleware.js
+++ b/packages/mitmproxy/src/lib/proxy/middleware/InsertScriptMiddleware.js
@@ -1,4 +1,4 @@
-const zlib = require('zlib')
+const zlib = require('node:zlib')
const through = require('through2')
const log = require('../../../utils/util.log')
@@ -181,10 +181,12 @@ module.exports = {
}))
.pipe(codec.createCompressor()) // 编码
.pipe(res)
- } else {
+ }
+ else {
log.error(`InsertScriptMiddleware.responseInterceptor(): 暂不支持编码方式 ${encoding}, 目前支持:`, httpUtil.supportedEncodingsStr())
}
- } else {
+ }
+ else {
proxyRes
.pipe(through(function (chunk, enc, callback) {
chunkByteReplace(this, chunk, enc, callback, append)
diff --git a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js
index d6b2a16c92..3b1e236abd 100644
--- a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js
+++ b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js
@@ -1,7 +1,7 @@
-const { Buffer } = require('buffer')
-const fs = require('fs')
-const path = require('path')
-const url = require('url')
+const { Buffer } = require('node:buffer')
+const fs = require('node:fs')
+const path = require('node:path')
+const url = require('node:url')
const lodash = require('lodash')
const request = require('request')
const log = require('../../../utils/util.log')
@@ -15,7 +15,8 @@ function matched (hostname, overWallTargetMap) {
const ret1 = matchUtil.matchHostname(overWallTargetMap, hostname, 'matched overwall')
if (ret1) {
return 'in config'
- } else if (ret1 === false || ret1 === 'false') {
+ }
+ else if (ret1 === false || ret1 === 'false') {
log.debug(`域名 ${hostname} 的overwall配置为 false,跳过增强功能,即使它在 pac.txt 里`)
return null
}
@@ -28,7 +29,8 @@ function matched (hostname, overWallTargetMap) {
if (ret && ret.indexOf('PROXY ') === 0) {
log.info(`matchHostname: matched overwall: '${hostname}' -> '${ret}' in pac.txt`)
return 'in pac.txt'
- } else {
+ }
+ else {
log.debug(`matchHostname: matched overwall: Not-Matched '${hostname}' -> '${ret}' in pac.txt`)
return null
}
@@ -49,7 +51,8 @@ function loadPacLastModifiedTime (pacTxt) {
if (matched && matched.length > 0) {
try {
return new Date(matched[0])
- } catch (ignore) {
+ }
+ catch {
return null
}
}
@@ -74,7 +77,7 @@ function savePacFile (pacTxt) {
// 尝试解析和修改 pac.txt 文件时间
const lastModifiedTime = loadPacLastModifiedTime(pacTxt)
if (lastModifiedTime) {
- fs.stat(pacFilePath, (err, stats) => {
+ fs.stat(pacFilePath, (err, _stats) => {
if (err) {
log.error('修改 pac.txt 文件时间失败:', err)
return
@@ -84,7 +87,8 @@ function savePacFile (pacTxt) {
fs.utimes(pacFilePath, lastModifiedTime, lastModifiedTime, (utimesErr) => {
if (utimesErr) {
log.error('修改 pac.txt 文件时间失败:', utimesErr)
- } else {
+ }
+ else {
log.info(`'${pacFilePath}' 文件的修改时间已更新为其最近更新时间 '${formatDate(lastModifiedTime)}'`)
}
})
@@ -107,7 +111,8 @@ async function downloadPacAsync (pacConfig) {
if (body == null || body.length < 100) {
log.warn('下载远程 pac.txt 文件成功,但内容为空或内容太短,判断为无效的 pax.txt 文件:', remotePacFileUrl, ', body:', body)
return
- } else {
+ }
+ else {
log.info('下载远程 pac.txt 文件成功:', remotePacFileUrl)
}
@@ -118,7 +123,8 @@ async function downloadPacAsync (pacConfig) {
pacTxt = Buffer.from(pacTxt, 'base64').toString('utf8')
// log.debug('解析 base64 后的 pax:', pacTxt)
}
- } catch (e) {
+ }
+ catch {
if (!pacTxt.includes('!---------------------EOF')) {
log.error(`远程 pac.txt 文件内容即不是base64格式,也不是要求的格式,url: ${remotePacFileUrl},body: ${body}`)
return
@@ -127,7 +133,8 @@ async function downloadPacAsync (pacConfig) {
// 保存到本地
savePacFile(pacTxt)
- } else {
+ }
+ else {
log.error(`下载远程 pac.txt 文件失败: ${remotePacFileUrl}, response:`, response, ', body:', body)
}
})
@@ -153,11 +160,11 @@ function createOverwallMiddleware (overWallConfig) {
}
const overWallTargetMap = matchUtil.domainMapRegexply(overWallConfig.targets)
return {
- sslConnectInterceptor: (req, cltSocket, head) => {
+ sslConnectInterceptor: (req, _cltSocket, _head) => {
const hostname = req.url.split(':')[0]
return matched(hostname, overWallTargetMap)
},
- requestIntercept (context, req, res, ssl, next) {
+ requestIntercept (context, req, res, _ssl, _next) {
const { rOptions, log, RequestCounter } = context
if (rOptions.protocol === 'http:') {
return
@@ -176,7 +183,8 @@ function createOverwallMiddleware (overWallConfig) {
}
if (count.value == null) {
log.error('`count.value` is null, the count:', count)
- } else {
+ }
+ else {
count.doCount(count.value)
proxyServer = count.value
context.requestCount = {
diff --git a/packages/mitmproxy/src/lib/proxy/middleware/source/pac.js b/packages/mitmproxy/src/lib/proxy/middleware/source/pac.js
index 6a0bd29b37..be6c752264 100644
--- a/packages/mitmproxy/src/lib/proxy/middleware/source/pac.js
+++ b/packages/mitmproxy/src/lib/proxy/middleware/source/pac.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const log = require('../../../../utils/util.log')
function createPacClient (pacFilePath) {
@@ -12,7 +12,8 @@ function createPacClient (pacFilePath) {
const filePath = path.resolve(location)
log.info('read pac path:', filePath)
return fs.readFileSync(location).toString()
- } catch (e) {
+ }
+ catch (e) {
log.error('读取pac失败:', e)
return ''
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js
index 401ea23024..ac040e5fe3 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js
@@ -1,5 +1,5 @@
-const net = require('net')
-const url = require('url')
+const net = require('node:net')
+const url = require('node:url')
const jsonApi = require('../../../json')
const log = require('../../../utils/util.log')
const DnsUtil = require('../../dns/index')
@@ -45,7 +45,8 @@ module.exports = function createConnectHandler (sslConnectInterceptor, middlewar
}).catch((e) => {
log.error(`----- fakeServer getServerPromise error: ${hostname}:${port}, error:`, e)
})
- } else {
+ }
+ else {
log.info(`不拦截请求,直连目标服务器: ${hostname}:${port}, headers:`, jsonApi.stringify2(req.headers))
connect(req, cltSocket, head, hostname, port, dnsConfig, true)
}
@@ -117,7 +118,8 @@ function connect (req, cltSocket, head, hostname, port, dnsConfig = null, isDire
const proxySocket = net.connect(options, () => {
if (!isDirect) {
log.info('Proxy connect start:', hostport)
- } else {
+ }
+ else {
log.debug('Direct connect start:', hostport)
}
@@ -190,7 +192,8 @@ function connect (req, cltSocket, head, hostname, port, dnsConfig = null, isDire
}
return proxySocket
- } catch (e) {
+ }
+ catch (e) {
log.error(`${isDirect ? '直连' : '代理连接'}错误: ${hostport}, error:`, e)
}
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createFakeServerCenter.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createFakeServerCenter.js
index bbd4db548e..7bdf41cc53 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createFakeServerCenter.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createFakeServerCenter.js
@@ -1,4 +1,4 @@
-const fs = require('fs')
+const fs = require('node:fs')
const forge = require('node-forge')
const log = require('../../../utils/util.log')
const FakeServersCenter = require('../tls/FakeServersCenter')
@@ -20,7 +20,8 @@ module.exports = function createFakeServerCenter ({
const caKeyPem = fs.readFileSync(caKeyPath)
caCert = forge.pki.certificateFromPem(caCertPem)
caKey = forge.pki.privateKeyFromPem(caKeyPem)
- } catch (e) {
+ }
+ catch (e) {
log.error('Can not find `CA certificate` or `CA key`:', e)
process.exit(1)
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js
index 00f68b2fb8..511956e2f6 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js
@@ -1,5 +1,5 @@
-const http = require('http')
-const https = require('https')
+const http = require('node:http')
+const https = require('node:https')
const jsonApi = require('../../../json')
const log = require('../../../utils/util.log')
const RequestCounter = require('../../choice/RequestCounter')
@@ -23,9 +23,11 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
if (rOptions.headers.connection === 'close') {
req.socket.setKeepAlive(false)
- } else if (rOptions.customSocketId != null) { // for NTLM
+ }
+ else if (rOptions.customSocketId != null) { // for NTLM
req.socket.setKeepAlive(true, 60 * 60 * 1000)
- } else {
+ }
+ else {
req.socket.setKeepAlive(true, 30000)
}
const context = {
@@ -71,10 +73,12 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
}
}
next()
- } else {
+ }
+ else {
next()
}
- } catch (e) {
+ }
+ catch (e) {
reject(e)
}
})
@@ -125,10 +129,12 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
rOptions.lookup = dnsLookup.createLookupFunc(res, dns, 'request url', url, isDnsIntercept)
log.debug(`域名 ${rOptions.hostname} DNS: ${dns.name}`)
res.setHeader('DS-DNS', dns.name)
- } else {
+ }
+ else {
log.info(`域名 ${rOptions.hostname} 在DNS中未配置`)
}
- } else {
+ }
+ else {
log.info(`域名 ${rOptions.hostname} DNS配置不存在`)
}
@@ -157,7 +163,8 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
const cost = new Date() - start
if (rOptions.protocol === 'https:') {
log.info(`代理请求返回: 【${proxyRes.statusCode}】${url}, cost: ${cost} ms`)
- } else {
+ }
+ else {
log.info(`请求返回: 【${proxyRes.statusCode}】${url}, cost: ${cost} ms`)
}
// console.log('request:', proxyReq, proxyReq.socket)
@@ -284,7 +291,8 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
if (append.body) {
body += append.body
}
- } else if (append === false) {
+ }
+ else if (append === false) {
break // 返回false表示终止拦截器,跳出循环
}
}
@@ -292,10 +300,12 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
head,
body,
})
- } else {
+ }
+ else {
next()
}
- } catch (e) {
+ }
+ catch (e) {
reject(e)
}
})
@@ -331,13 +341,15 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
目标网站请求错误:【${e.code}】 ${e.message}
目标地址:${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}`,
)
- } catch (e) {
+ }
+ catch (e) {
// do nothing
}
try {
res.end()
- } catch (e) {
+ }
+ catch (e) {
// do nothing
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createUpgradeHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createUpgradeHandler.js
index 69de41a184..df3859866e 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createUpgradeHandler.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createUpgradeHandler.js
@@ -1,5 +1,5 @@
-const http = require('http')
-const https = require('https')
+const http = require('node:http')
+const https = require('node:https')
const log = require('../../../utils/util.log')
const util = require('../common/util')
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js
index dbea7035d0..006b18991a 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js
@@ -1,4 +1,4 @@
-const defaultDns = require('dns')
+const defaultDns = require('node:dns')
const log = require('../../../utils/util.log')
const speedTest = require('../../speed')
@@ -17,7 +17,8 @@ module.exports = {
}
callback(null, aliveIpObj.host, 4)
return
- } else {
+ }
+ else {
log.info(`----- ${action}: ${hostname}, no alive ip${target}, tester: { "ready": ${tester.ready}, "backupList": ${JSON.stringify(tester.backupList)} }`)
}
}
@@ -49,11 +50,13 @@ module.exports = {
}
callback(null, ip, 4)
return
- } else {
+ }
+ else {
// 使用默认dns
log.info(`----- ${action}: ${hostname}, use hostname by default DNS: ${hostname}, skip test failed ip from dns '${dns.name}: ${ip}'${target}, options:`, options)
}
- } else {
+ }
+ else {
// 使用默认dns
log.info(`----- ${action}: ${hostname}, use hostname by default DNS: ${hostname}${target}, options:`, options, ', dns:', dns)
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/index.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/index.js
index daaf6610e7..acf3a7e988 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/index.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/index.js
@@ -1,4 +1,4 @@
-const http = require('http')
+const http = require('node:http')
const log = require('../../../utils/util.log')
const speedTest = require('../../speed/index.js')
const config = require('../common/config')
@@ -104,7 +104,8 @@ module.exports = {
server.on('upgrade', (req, cltSocket, head) => {
if (printDebugLog) {
log.debug(`【server upgrade, ssl: ${ssl}】\r\n----- req -----\r\n`, req)
- } else {
+ }
+ else {
log.info(`【server upgrade, ssl: ${ssl}】`, req.url)
}
upgradeHandler(req, cltSocket, head, ssl)
diff --git a/packages/mitmproxy/src/lib/proxy/tls/CertAndKeyContainer.js b/packages/mitmproxy/src/lib/proxy/tls/CertAndKeyContainer.js
index 0b2542a470..2a1131add7 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/CertAndKeyContainer.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/CertAndKeyContainer.js
@@ -73,7 +73,8 @@ module.exports = class CertAndKeyContainer {
if (fast) {
certObj = tlsUtils.createFakeCertificateByDomain(this.caKey, this.caCert, hostname)
_resolve(certObj)
- } else {
+ }
+ else {
// 这个太慢了
// const preReq = https.request({
// port: port,
diff --git a/packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js b/packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js
index 598cbb3333..2b781cc5eb 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js
@@ -1,12 +1,12 @@
-const http = require('http')
-const https = require('https')
+const http = require('node:http')
+const https = require('node:https')
const forge = require('node-forge')
const CertAndKeyContainer = require('./CertAndKeyContainer')
const tlsUtils = require('./tlsUtils')
const pki = forge.pki
// const colors = require('colors')
-const tls = require('tls')
+const tls = require('node:tls')
const log = require('../../../utils/util.log')
const compatible = require('../compatible/compatible')
@@ -38,7 +38,8 @@ module.exports = class FakeServersCenter {
try {
log.info('超过最大服务数量,删除旧服务。delServerObj:', delServerObj)
delServerObj.serverObj.server.close()
- } catch (e) {
+ }
+ catch (e) {
log.error('`delServerObj.serverObj.server.close()` error:', e)
}
}
@@ -49,7 +50,8 @@ module.exports = class FakeServersCenter {
getServerPromise (hostname, port, ssl, manualCompatibleConfig) {
if (port === 443 || port === 80) {
ssl = port === 443
- } else if (ssl) {
+ }
+ else if (ssl) {
// 自动兼容程序:1
const compatibleConfig = compatible.getConnectCompatibleConfig(hostname, port, manualCompatibleConfig)
if (compatibleConfig && compatibleConfig.ssl != null) {
@@ -105,7 +107,8 @@ module.exports = class FakeServersCenter {
})()
},
})
- } else {
+ }
+ else {
fakeServer = new http.Server()
}
const serverObj = {
@@ -146,7 +149,8 @@ module.exports = class FakeServersCenter {
fakeServer.on('upgrade', (req, socket, head) => {
if (printDebugLog) {
log.debug(`【fakeServer upgrade - ${hostname}:${port}】\r\n----- req -----\r\n`, req, '\r\n----- socket -----\r\n', socket, '\r\n----- head -----\r\n', head)
- } else {
+ }
+ else {
log.info(`【fakeServer upgrade - ${hostname}:${port}】`, req.url)
}
this.upgradeHandler(req, socket, head, ssl)
@@ -165,7 +169,8 @@ module.exports = class FakeServersCenter {
if (ssl === true && err.code.indexOf('ERR_SSL_') === 0) {
compatible.setConnectSsl(hostname, port, false)
log.error(`自动兼容程序:SSL异常,现设置为禁用ssl: ${hostname}:${port}, ssl = false`)
- } else if (ssl === false && err.code === 'HPE_INVALID_METHOD') {
+ }
+ else if (ssl === false && err.code === 'HPE_INVALID_METHOD') {
compatible.setConnectSsl(hostname, port, true)
log.error(`自动兼容程序:${err.code},现设置为启用ssl: ${hostname}:${port}, ssl = true`)
}
diff --git a/packages/mitmproxy/src/lib/proxy/tls/sniUtil.js b/packages/mitmproxy/src/lib/proxy/tls/sniUtil.js
index c44657e83b..9669f5fa0c 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/sniUtil.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/sniUtil.js
@@ -172,11 +172,13 @@ module.exports = function extractSNI (data) {
end: n + nameLength,
length: nameLength,
}
- } else {
+ }
+ else {
n += nameLength
}
}
- } else { // ExtensionType was something we are not interested in
+ }
+ else { // ExtensionType was something we are not interested in
pos += extensionSize
}
}
diff --git a/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js b/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
index ee4a97fe92..b545cad276 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const _ = require('lodash')
const forge = require('node-forge')
const log = require('../../../utils/util.log')
@@ -244,7 +244,8 @@ utils.initCA = function ({ caCertPath, caKeyPath }) {
caKeyPath,
create: false,
}
- } catch (e) {
+ }
+ catch (e) {
const caObj = utils.createCA(config.caName)
const caCert = caObj.cert
diff --git a/packages/mitmproxy/src/lib/speed/SpeedTester.js b/packages/mitmproxy/src/lib/speed/SpeedTester.js
index f6b2f34f06..dba881cf1e 100644
--- a/packages/mitmproxy/src/lib/speed/SpeedTester.js
+++ b/packages/mitmproxy/src/lib/speed/SpeedTester.js
@@ -1,5 +1,5 @@
// 1个小时不访问,取消获取
-const net = require('net')
+const net = require('node:net')
const _ = require('lodash')
const log = require('../../utils/util.log.js')
const config = require('./config.js')
@@ -124,7 +124,8 @@ class SpeedTester {
}
return a.time - b.time
})
- } catch (e) {
+ }
+ catch (e) {
if (e.message !== 'timeout') {
log.warn('[speed] test error: ', this.hostname, `➜ ${item.host}:${item.port} from DNS '${item.dns}'`, ', errorMsg:', e.message)
}
diff --git a/packages/mitmproxy/src/lib/speed/index.js b/packages/mitmproxy/src/lib/speed/index.js
index 86b7ba0cca..55b92db239 100644
--- a/packages/mitmproxy/src/lib/speed/index.js
+++ b/packages/mitmproxy/src/lib/speed/index.js
@@ -60,7 +60,8 @@ function reSpeedTest () {
function action (event) {
if (event.key === 'reTest') {
reSpeedTest()
- } else if (event.key === 'getList') {
+ }
+ else if (event.key === 'getList') {
process.send({ type: 'speed', event: { key: 'getList', value: getAllSpeedTester() } })
}
}
diff --git a/packages/mitmproxy/src/options.js b/packages/mitmproxy/src/options.js
index 7cf3598a3f..a880530d3f 100644
--- a/packages/mitmproxy/src/options.js
+++ b/packages/mitmproxy/src/options.js
@@ -1,5 +1,5 @@
-const fs = require('fs')
-const path = require('path')
+const fs = require('node:fs')
+const path = require('node:path')
const lodash = require('lodash')
const jsonApi = require('./json')
const dnsUtil = require('./lib/dns')
@@ -24,7 +24,8 @@ function getExclusionArray (exclusions) {
if (exclusions.length > 0) {
ret = exclusions
}
- } else if (lodash.isObject(exclusions)) {
+ }
+ else if (lodash.isObject(exclusions)) {
ret = []
for (const exclusion in exclusions) {
ret.push(exclusion)
@@ -157,7 +158,8 @@ module.exports = (serverConfig) => {
}
}
}
- } catch (e) {
+ }
+ catch (e) {
log.error(`判断拦截器是否排除当前path时出现异常, path: ${rOptions.path}, interceptOpt:`, interceptOpt, ', error:', e)
}
if (isExcluded) {
@@ -189,7 +191,8 @@ module.exports = (serverConfig) => {
interceptor.requestIntercept = (context, req, res, ssl, next) => {
return impl.requestIntercept(context, interceptOpt, req, res, ssl, next, matched)
}
- } else if (impl.responseIntercept) {
+ }
+ else if (impl.responseIntercept) {
// res拦截器
interceptor.responseIntercept = (context, req, res, proxyReq, proxyRes, ssl, next) => {
return impl.responseIntercept(context, interceptOpt, req, res, proxyReq, proxyRes, ssl, next, matched)
@@ -199,7 +202,8 @@ module.exports = (serverConfig) => {
// log.info(`${action} interceptor: ${impl.name}, hostname: ${rOptions.hostname}, regexp: ${regexp}`)
if (action === 'add') {
matchIntercepts.push(interceptor)
- } else {
+ }
+ else {
matchIntercepts[matchedInterceptOpt.index] = interceptor
}
matchInterceptsOpts[impl.name] = {
diff --git a/packages/mitmproxy/src/utils/util.match.js b/packages/mitmproxy/src/utils/util.match.js
index 4404ba0b6d..8668e6b1d0 100644
--- a/packages/mitmproxy/src/utils/util.match.js
+++ b/packages/mitmproxy/src/utils/util.match.js
@@ -12,7 +12,8 @@ function isMatched (url, regexp) {
urlRegexp = `.${regexp}`
}
return url.match(urlRegexp)
- } catch (e) {
+ }
+ catch (e) {
log.error('匹配串有问题:', regexp)
return null
}
@@ -39,7 +40,8 @@ function domainMapRegexply (hostMap) {
if (domain.indexOf('*') === 0 && domain.lastIndexOf('*') === 0) {
origin[domain] = value
}
- } else {
+ }
+ else {
origin[domain] = value
}
})
@@ -168,7 +170,8 @@ function matchHostnameAll (hostMap, hostname, action) {
deleteNullItems(values)
log.info(`matchHostname-all: ${action}: '${hostname}':`, JSON.stringify(values))
return values
- } else {
+ }
+ else {
log.debug(`matchHostname-all: ${action}: '${hostname}' Not-Matched`)
}
}
diff --git a/packages/mitmproxy/test/lib/interceptor/impl/res/responseReplaceTest.js b/packages/mitmproxy/test/lib/interceptor/impl/res/responseReplaceTest.js
index 00ff519773..050fc37db9 100644
--- a/packages/mitmproxy/test/lib/interceptor/impl/res/responseReplaceTest.js
+++ b/packages/mitmproxy/test/lib/interceptor/impl/res/responseReplaceTest.js
@@ -9,12 +9,17 @@ const res = {
const proxyRes = {
rawHeaders: [
- 'Content-Type', 'application/json; charset=utf-8',
- 'Content-Length', '2',
- 'ETag', 'W/"2"',
- 'Date', 'Thu, 01 Jan 1970 00:00:00 GMT',
- 'Connection', 'keep-alive'
- ]
+ 'Content-Type',
+ 'application/json; charset=utf-8',
+ 'Content-Length',
+ '2',
+ 'ETag',
+ 'W/"2"',
+ 'Date',
+ 'Thu, 01 Jan 1970 00:00:00 GMT',
+ 'Connection',
+ 'keep-alive',
+ ],
}
const newHeaders = {
diff --git a/packages/mitmproxy/test/proxyTest.js b/packages/mitmproxy/test/proxyTest.js
index 84a402a147..55d3babdd5 100644
--- a/packages/mitmproxy/test/proxyTest.js
+++ b/packages/mitmproxy/test/proxyTest.js
@@ -1,4 +1,4 @@
-const http = require('http')
+const http = require('node:http')
const options = {
headers: {
diff --git a/test/test.js b/test/test.js
index 9b47d719a2..5ea6546bf1 100644
--- a/test/test.js
+++ b/test/test.js
@@ -59,7 +59,8 @@ function testRequest () {
request('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', (error, response, body) => {
if (error) {
console.error(error)
- } else {
+ }
+ else {
console.log(body)
}
})
From a8b6da02d908d80601e6d0e80f1568ea724afe97 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 12:21:57 +0800
Subject: [PATCH 12/20] upgrade `electron-updater`
---
packages/gui/package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/gui/package.json b/packages/gui/package.json
index 9add504dc7..6e963d0f35 100644
--- a/packages/gui/package.json
+++ b/packages/gui/package.json
@@ -28,7 +28,7 @@
"ant-design-vue": "^1.7.8",
"electron-baidu-tongji": "^1.0.5",
"electron-sudo": "^4.0.12",
- "electron-updater": "^4.3.5",
+ "electron-updater": "^6.3.9",
"json5": "^2.2.3",
"lodash": "^4.17.20",
"request-progress": "^3.0.0",
From 293bbc96aa256d8ab27f9acc75b10f44bc881929 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 14:40:43 +0800
Subject: [PATCH 13/20] fix: lint style
---
eslint.config.js | 46 ++++++++--------
packages/cli/src/mitmproxy.js | 3 +-
packages/core/src/config.js | 42 +++++----------
packages/core/src/event.js | 4 +-
packages/core/src/expose.js | 24 +++------
packages/core/src/modules/plugin/git/index.js | 9 ++--
.../core/src/modules/plugin/node/index.js | 12 ++---
.../core/src/modules/plugin/overwall/index.js | 3 +-
packages/core/src/modules/plugin/pip/index.js | 3 +-
packages/core/src/modules/proxy/index.js | 3 +-
packages/core/src/modules/server/index.js | 12 ++---
.../shell/scripts/set-system-proxy/index.js | 51 ++++++------------
packages/core/src/shell/shell.js | 15 ++----
packages/gui/pkg/after-pack.js | 6 +--
packages/gui/src/background.js | 54 +++++++------------
packages/gui/src/background/powerMonitor.js | 12 ++---
packages/gui/src/bridge/api/backend.js | 13 ++---
packages/gui/src/bridge/auto-start/backend.js | 12 ++---
packages/gui/src/bridge/auto-start/front.js | 3 +-
packages/gui/src/bridge/error/front.js | 3 +-
.../gui/src/bridge/file-selector/backend.js | 3 +-
.../gui/src/bridge/file-selector/front.js | 3 +-
packages/gui/src/bridge/tongji/front.js | 4 +-
packages/gui/src/bridge/update/backend.js | 45 ++++++----------
packages/gui/src/bridge/update/front.js | 21 +++-----
packages/gui/src/view/components/setup-ca.vue | 6 +--
packages/gui/src/view/mixins/plugin.js | 9 ++--
packages/gui/src/view/pages/index.vue | 18 +++----
packages/gui/src/view/pages/plugin/git.vue | 3 +-
packages/gui/src/view/pages/proxy.vue | 3 +-
packages/gui/src/view/pages/setting.vue | 34 ++++++------
packages/mitmproxy/src/index.js | 12 ++---
packages/mitmproxy/src/json.js | 6 +--
packages/mitmproxy/src/lib/choice/index.js | 6 +--
packages/mitmproxy/src/lib/dns/base.js | 6 +--
packages/mitmproxy/src/lib/dns/https.js | 9 ++--
packages/mitmproxy/src/lib/dns/index.js | 6 +--
packages/mitmproxy/src/lib/dns/preset.js | 3 +-
.../src/lib/interceptor/impl/req/OPTIONS.js | 3 +-
.../src/lib/interceptor/impl/req/baiduOcr.js | 12 ++---
.../src/lib/interceptor/impl/req/cacheReq.js | 3 +-
.../src/lib/interceptor/impl/req/proxy.js | 12 ++---
.../interceptor/impl/req/requestReplace.js | 3 +-
.../src/lib/interceptor/impl/res/cacheRes.js | 21 +++-----
.../interceptor/impl/res/responseReplace.js | 3 +-
.../src/lib/interceptor/impl/res/script.js | 21 +++-----
packages/mitmproxy/src/lib/monkey/index.js | 12 ++---
.../mitmproxy/src/lib/proxy/common/util.js | 30 ++++-------
.../src/lib/proxy/compatible/compatible.js | 12 ++---
.../middleware/InsertScriptMiddleware.js | 6 +--
.../src/lib/proxy/middleware/overwall.js | 24 +++------
.../src/lib/proxy/middleware/source/pac.js | 3 +-
.../proxy/mitmproxy/createConnectHandler.js | 9 ++--
.../proxy/mitmproxy/createFakeServerCenter.js | 3 +-
.../proxy/mitmproxy/createRequestHandler.js | 36 +++++--------
.../src/lib/proxy/mitmproxy/dnsLookup.js | 9 ++--
.../src/lib/proxy/mitmproxy/index.js | 3 +-
.../src/lib/proxy/tls/CertAndKeyContainer.js | 3 +-
.../src/lib/proxy/tls/FakeServersCenter.js | 15 ++----
.../mitmproxy/src/lib/proxy/tls/sniUtil.js | 6 +--
.../mitmproxy/src/lib/proxy/tls/tlsUtils.js | 3 +-
.../mitmproxy/src/lib/speed/SpeedTester.js | 3 +-
packages/mitmproxy/src/lib/speed/index.js | 3 +-
packages/mitmproxy/src/options.js | 16 +++---
packages/mitmproxy/src/utils/util.match.js | 9 ++--
test/test.js | 3 +-
66 files changed, 293 insertions(+), 520 deletions(-)
diff --git a/eslint.config.js b/eslint.config.js
index b3d5942540..46f5abf62b 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -1,24 +1,28 @@
import antfu from '@antfu/eslint-config'
-export default antfu({
- vue: {
- vueVersion: 2,
+export default antfu(
+ {
+ vue: {
+ vueVersion: 2,
+ },
+ rules: {
+ 'style/brace-style': ['error', '1tbs'],
+ 'style/space-before-function-paren': ['error', 'always'],
+ 'import/newline-after-import': 'off',
+ 'import/first': 'off',
+ 'perfectionist/sort-imports': 'off',
+ 'node/prefer-global/buffer': 'off',
+ 'node/prefer-global/process': 'off',
+ 'no-console': 'off',
+ },
+ ignores: [
+ '**/build/*',
+ '**/dist_electron',
+ ],
+ formatters: {
+ css: true,
+ html: true,
+ markdown: 'prettier',
+ },
},
- rules: {
- 'style/space-before-function-paren': ['error', 'always'],
- 'node/prefer-global/buffer': 'off',
- 'node/prefer-global/process': 'off',
- 'no-console': 'off',
- },
- ignore: [
- '**/node_modules/*',
- '**/build/*',
- '**/test/*',
- '**/dist_electron/*',
- ],
- formatters: {
- css: true,
- html: true,
- markdown: 'prettier',
- },
-})
+)
diff --git a/packages/cli/src/mitmproxy.js b/packages/cli/src/mitmproxy.js
index b17a546606..a86035d063 100644
--- a/packages/cli/src/mitmproxy.js
+++ b/packages/cli/src/mitmproxy.js
@@ -9,8 +9,7 @@ const home = process.env.USER_HOME || process.env.HOME || 'C:/Users/Administrato
let configPath
if (process.argv && process.argv.length > 3) {
configPath = process.argv[2]
-}
-else {
+} else {
configPath = path.join(home, '.dev-sidecar/running.json')
}
diff --git a/packages/core/src/config.js b/packages/core/src/config.js
index e4eac3b3f1..a591d09086 100644
--- a/packages/core/src/config.js
+++ b/packages/core/src/config.js
@@ -30,8 +30,7 @@ function _getConfigPath () {
const dir = getDefaultConfigBasePath()
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
- }
- else {
+ } else {
// 兼容1.7.3及以下版本的配置文件处理逻辑
const newFilePath = path.join(dir, '/config.json')
const oldFilePath = path.join(dir, '/config.json5')
@@ -53,8 +52,7 @@ const configApi = {
try {
await configApi.downloadRemoteConfig()
configApi.reload()
- }
- catch (e) {
+ } catch (e) {
log.error('定时下载远程配置并重载配置失败', e)
}
}
@@ -104,8 +102,7 @@ const configApi = {
log.warn('下载远程配置成功,但内容为空:', remoteConfigUrl)
resolve()
return
- }
- else {
+ } else {
log.info('下载远程配置成功:', remoteConfigUrl)
}
@@ -113,8 +110,7 @@ const configApi = {
let remoteConfig
try {
remoteConfig = jsonApi.parse(body)
- }
- catch (e) {
+ } catch (e) {
log.error(`远程配置内容格式不正确, url: ${remoteConfigUrl}, body: ${body}`)
remoteConfig = null
}
@@ -123,21 +119,18 @@ const configApi = {
const remoteSavePath = _getRemoteSavePath(suffix)
fs.writeFileSync(remoteSavePath, body)
log.info('保存远程配置文件成功:', remoteSavePath)
- }
- else {
+ } else {
log.warn('远程配置对象为空:', remoteConfigUrl)
}
resolve()
- }
- else {
+ } else {
log.error(`下载远程配置失败: ${remoteConfigUrl}, response:`, response, ', body:', body)
let message
if (response) {
message = `下载远程配置失败: ${remoteConfigUrl}, message: ${response.message}, code: ${response.statusCode}`
- }
- else {
+ } else {
message = `下载远程配置失败: response: ${response}`
}
reject(new Error(message))
@@ -161,8 +154,7 @@ const configApi = {
if (!get().app.remoteConfig.personalUrl) {
return '{}'
}
- }
- else if (suffix === '') {
+ } else if (suffix === '') {
if (!get().app.remoteConfig.url) {
return '{}'
}
@@ -175,12 +167,10 @@ const configApi = {
const file = fs.readFileSync(path)
log.info('读取远程配置文件内容成功:', path)
return file.toString()
- }
- else {
+ } else {
log.warn('远程配置文件不存在:', path)
}
- }
- catch (e) {
+ } catch (e) {
log.error('读取远程配置文件内容失败:', e)
}
@@ -230,8 +220,7 @@ const configApi = {
if (!fs.existsSync(configPath)) {
userConfig = {}
log.info('config.json 文件不存在:', configPath)
- }
- else {
+ } else {
const file = fs.readFileSync(configPath)
log.info('读取 config.json 成功:', configPath)
const fileStr = file.toString()
@@ -276,8 +265,7 @@ const configApi = {
if (get().app.remoteConfig.personalUrl) {
mergeApi.doMerge(merged, personalRemoteConfig) // 再合并一次个人远程配置,使配置生效
}
- }
- else {
+ } else {
mergeApi.doMerge(merged, defConfig) // 合并默认配置
}
if (newConfig != null) {
@@ -318,8 +306,7 @@ const configApi = {
configApi.load(null)
return true // 删除并重新加载配置成功
- }
- else {
+ } else {
return false // config.json 文件不存在
}
},
@@ -328,8 +315,7 @@ const configApi = {
let value = lodash.get(defConfig, key)
value = lodash.cloneDeep(value)
lodash.set(configTarget, key, value)
- }
- else {
+ } else {
configTarget = lodash.cloneDeep(defConfig)
}
return configTarget
diff --git a/packages/core/src/event.js b/packages/core/src/event.js
index 94df10002f..ea136cfadd 100644
--- a/packages/core/src/event.js
+++ b/packages/core/src/event.js
@@ -6,7 +6,9 @@ function register (channel, handle, order = 10) {
handles = listener[channel] = []
}
handles.push({ id: index, handle, order })
- handles.sort((a, b) => { return a.order - b.order })
+ handles.sort((a, b) => {
+ return a.order - b.order
+ })
return index++
}
function fire (channel, event) {
diff --git a/packages/core/src/expose.js b/packages/core/src/expose.js
index b4c030fe94..ee3593b2cf 100644
--- a/packages/core/src/expose.js
+++ b/packages/core/src/expose.js
@@ -46,16 +46,14 @@ async function startup ({ mitmproxyPath }) {
if (conf.server.enabled) {
try {
await server.start({ mitmproxyPath })
- }
- catch (err) {
+ } catch (err) {
log.error('代理服务启动失败:', err)
}
}
if (conf.proxy.enabled) {
try {
await proxy.start()
- }
- catch (err) {
+ } catch (err) {
log.error('开启系统代理失败:', err)
}
}
@@ -67,8 +65,7 @@ async function startup ({ mitmproxyPath }) {
try {
await plugin[key].start()
log.info(`插件【${key}】已启动`)
- }
- catch (err) {
+ } catch (err) {
log.error(`插件【${key}】启动失败:`, err)
}
}
@@ -78,8 +75,7 @@ async function startup ({ mitmproxyPath }) {
if (plugins && plugins.length > 0) {
await Promise.all(plugins)
}
- }
- catch (err) {
+ } catch (err) {
log.error('开启插件失败:', err)
}
}
@@ -93,8 +89,7 @@ async function shutdown () {
try {
await plugin[key].close()
log.info(`插件【${key}】已关闭`)
- }
- catch (err) {
+ } catch (err) {
log.error(`插件【${key}】关闭失败:`, err)
}
}
@@ -104,8 +99,7 @@ async function shutdown () {
if (plugins.length > 0) {
await Promise.all(plugins)
}
- }
- catch (error) {
+ } catch (error) {
log.error('插件关闭失败:', error)
}
@@ -113,8 +107,7 @@ async function shutdown () {
try {
await proxy.close()
log.info('系统代理已关闭')
- }
- catch (err) {
+ } catch (err) {
log.error('系统代理关闭失败:', err)
}
}
@@ -122,8 +115,7 @@ async function shutdown () {
try {
await server.close()
log.info('代理服务已关闭')
- }
- catch (err) {
+ } catch (err) {
log.error('代理服务关闭失败:', err)
}
}
diff --git a/packages/core/src/modules/plugin/git/index.js b/packages/core/src/modules/plugin/git/index.js
index ba3a7c24be..43fee407ca 100644
--- a/packages/core/src/modules/plugin/git/index.js
+++ b/packages/core/src/modules/plugin/git/index.js
@@ -56,15 +56,13 @@ const Plugin = function (context) {
try {
await shell.exec(['git config --global --unset https.proxy '], { type: 'cmd' })
- }
- catch (ignore) {
+ } catch (ignore) {
}
if (config.get().plugin.git.setting.sslVerify === true) {
try {
await shell.exec(['git config --global --unset http.sslVerify '], { type: 'cmd' })
- }
- catch (ignore) {
+ } catch (ignore) {
}
}
@@ -72,8 +70,7 @@ const Plugin = function (context) {
for (const url in config.get().plugin.git.setting.noProxyUrls) {
try {
await shell.exec([`git config --global --unset http."${url}".proxy `], { type: 'cmd' })
- }
- catch (ignore) {
+ } catch (ignore) {
}
}
}
diff --git a/packages/core/src/modules/plugin/node/index.js b/packages/core/src/modules/plugin/node/index.js
index ac4fe3950f..e19269555c 100644
--- a/packages/core/src/modules/plugin/node/index.js
+++ b/packages/core/src/modules/plugin/node/index.js
@@ -7,8 +7,7 @@ const NodePlugin = function (context) {
async start () {
try {
await nodeApi.setVariables()
- }
- catch (err) {
+ } catch (err) {
log.warn('set variables error:', err)
}
@@ -48,8 +47,7 @@ const NodePlugin = function (context) {
for (const item of list) {
if (item.value != null && item.value.length > 0 && item.value !== 'default' && item.value !== 'null') {
cmds.push(`${command} config set ${item.key} ${item.value}`)
- }
- else {
+ } else {
cmds.push(`${command} config delete ${item.key}`)
}
}
@@ -72,8 +70,7 @@ const NodePlugin = function (context) {
for (const item of list) {
if (item.value != null && item.value.length > 0 && item.value !== 'default' && item.value !== 'null') {
cmds.push(`yarn config set ${item.key} ${item.value}`)
- }
- else {
+ } else {
cmds.push(`yarn config delete ${item.key}`)
}
}
@@ -118,8 +115,7 @@ const NodePlugin = function (context) {
async setRegistry ({ registry, type }) {
if (type === 'npm') {
await nodeApi.setNpmEnv([{ key: 'registry', value: registry }])
- }
- else {
+ } else {
await nodeApi.setYarnEnv([{ key: 'registry', value: registry }])
}
return true
diff --git a/packages/core/src/modules/plugin/overwall/index.js b/packages/core/src/modules/plugin/overwall/index.js
index 656a309419..7842449815 100644
--- a/packages/core/src/modules/plugin/overwall/index.js
+++ b/packages/core/src/modules/plugin/overwall/index.js
@@ -28,8 +28,7 @@ const Plugin = function (context) {
for (const key in server) {
if (i === 0) {
main = key
- }
- else {
+ } else {
backup.push(key)
}
i++
diff --git a/packages/core/src/modules/plugin/pip/index.js b/packages/core/src/modules/plugin/pip/index.js
index 6108b5edb8..63572ceef9 100644
--- a/packages/core/src/modules/plugin/pip/index.js
+++ b/packages/core/src/modules/plugin/pip/index.js
@@ -48,8 +48,7 @@ const PipPlugin = function (context) {
for (const item of list) {
if (item.value != null) {
cmds.push(`${command} config set global.${item.key} ${item.value}`)
- }
- else {
+ } else {
cmds.push(`${command} config unset global.${item.key}`)
}
}
diff --git a/packages/core/src/modules/proxy/index.js b/packages/core/src/modules/proxy/index.js
index b618a99cf3..7a01cef6bc 100644
--- a/packages/core/src/modules/proxy/index.js
+++ b/packages/core/src/modules/proxy/index.js
@@ -33,8 +33,7 @@ const ProxyPlugin = function (context) {
event.fire('status', { key: 'proxy.enabled', value: false })
log.info('关闭系统代理成功')
return true
- }
- catch (err) {
+ } catch (err) {
log.error('关闭系统代理失败:', err)
return false
}
diff --git a/packages/core/src/modules/server/index.js b/packages/core/src/modules/server/index.js
index 2eacd07b28..c0d2f85fa5 100644
--- a/packages/core/src/modules/server/index.js
+++ b/packages/core/src/modules/server/index.js
@@ -102,16 +102,14 @@ const serverApi = {
log.info('收到子进程消息:', JSON.stringify(msg))
if (msg.type === 'status') {
fireStatus(msg.event)
- }
- else if (msg.type === 'error') {
+ } else if (msg.type === 'error') {
let code = ''
if (msg.event.code) {
code = msg.event.code
}
fireStatus(false) // 启动失败
event.fire('error', { key: 'server', value: code, error: msg.event, message: msg.message })
- }
- else if (msg.type === 'speed') {
+ } else if (msg.type === 'speed') {
event.fire('speed', msg.event)
}
})
@@ -141,14 +139,12 @@ const serverApi = {
}
log.warn('代理服务关闭失败:', err)
reject(err)
- }
- else {
+ } else {
log.info('代理服务关闭成功')
resolve()
}
})
- }
- else {
+ } else {
log.info('server is null')
resolve()
}
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 f525903338..05d6c9cfe0 100644
--- a/packages/core/src/shell/scripts/set-system-proxy/index.js
+++ b/packages/core/src/shell/scripts/set-system-proxy/index.js
@@ -44,8 +44,7 @@ async function _winUnsetProxy (exec, setEnv) {
})
}
})
- }
- catch (e) {
+ } catch (e) {
log.error('删除环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e)
}
}
@@ -68,8 +67,7 @@ async function downloadDomesticDomainAllowListAsync () {
if (body == null || body.length < 100) {
log.warn('下载远程 domestic-domain-allowlist.txt 文件成功,但内容为空或内容太短,判断为无效的 domestic-domain-allowlist.txt 文件:', remoteFileUrl, ', body:', body)
return
- }
- else {
+ } else {
log.info('下载远程 domestic-domain-allowlist.txt 文件成功:', remoteFileUrl)
}
@@ -79,8 +77,7 @@ async function downloadDomesticDomainAllowListAsync () {
fileTxt = Buffer.from(fileTxt, 'base64').toString('utf8')
// log.debug('解析 base64 后的 domestic-domain-allowlist:', fileTxt)
}
- }
- catch (e) {
+ } catch (e) {
if (!fileTxt.includes('*.')) {
log.error(`远程 domestic-domain-allowlist.txt 文件内容即不是base64格式,也不是要求的格式,url: ${remoteFileUrl},body: ${body}`)
return
@@ -89,8 +86,7 @@ async function downloadDomesticDomainAllowListAsync () {
// 保存到本地
saveDomesticDomainAllowListFile(fileTxt)
- }
- else {
+ } else {
log.error(`下载远程 domestic-domain-allowlist.txt 文件失败: ${remoteFileUrl}, response:`, response, ', body:', body)
}
})
@@ -101,8 +97,7 @@ function loadLastModifiedTimeFromTxt (fileTxt) {
if (matched && matched.length > 0) {
try {
return new Date(matched[0])
- }
- catch (ignore) {
+ } catch (ignore) {
return null
}
}
@@ -127,8 +122,7 @@ function saveDomesticDomainAllowListFile (fileTxt) {
fs.utimes(filePath, lastModifiedTime, lastModifiedTime, (utimesErr) => {
if (utimesErr) {
log.error('修改 domestic-domain-allowlist.txt 文件时间失败:', utimesErr)
- }
- else {
+ } else {
log.info(`'${filePath}' 文件的修改时间已更新为其最近更新时间 '${formatDate(lastModifiedTime)}'`)
}
})
@@ -169,22 +163,19 @@ function getDomesticDomainAllowList () {
// 如果临时文件已存在,则使用临时文件
fileAbsolutePath = tmpFilePath
log.info('读取已下载的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
- }
- else {
+ } else {
// 如果临时文件不存在,则使用内置文件
log.info('__dirname:', __dirname)
fileAbsolutePath = path.join(__dirname, '../', config.get().proxy.domesticDomainAllowListFilePath)
log.info('读取内置的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
}
- }
- else {
+ } else {
log.info('读取自定义路径的 domestic-domain-allowlist.txt 文件:', fileAbsolutePath)
}
try {
return fs.readFileSync(fileAbsolutePath).toString()
- }
- catch (e) {
+ } catch (e) {
log.error(`读取 domestic-domain-allowlist.txt 文件失败: ${fileAbsolutePath}, error:`, e)
return null
}
@@ -207,13 +198,11 @@ function getProxyExcludeIpStr (split) {
if (domesticDomainAllowList) {
excludeIpStr += domesticDomainAllowList
log.info('系统代理排除列表拼接国内域名')
- }
- else {
+ } else {
log.info('国内域名为空,不进行系统代理排除列表拼接国内域名')
}
}
- }
- catch (e) {
+ } catch (e) {
log.error('系统代理排除列表拼接国内域名失败:', e)
}
}
@@ -257,8 +246,7 @@ async function _winSetProxy (exec, ip, port, setEnv) {
}
// await addClearScriptIni()
- }
- catch (e) {
+ } catch (e) {
log.error('设置环境变量 HTTPS_PROXY、HTTP_PROXY 失败:', e)
}
}
@@ -272,8 +260,7 @@ const executor = {
if (ip != null) { // 设置代理
log.info('设置windows系统代理:', ip, port, setEnv)
return _winSetProxy(exec, ip, port, setEnv)
- }
- else { // 关闭代理
+ } else { // 关闭代理
log.info('关闭windows系统代理')
return _winUnsetProxy(exec, setEnv)
}
@@ -294,8 +281,7 @@ const executor = {
if (config.get().proxy.proxyHttp) {
setProxyCmd.push(`gsettings set org.gnome.system.proxy.http host ${ip}`)
setProxyCmd.push(`gsettings set org.gnome.system.proxy.http port ${port - 1}`)
- }
- else {
+ } else {
setProxyCmd.push('gsettings set org.gnome.system.proxy.http host \'\'')
setProxyCmd.push('gsettings set org.gnome.system.proxy.http port 0')
}
@@ -305,8 +291,7 @@ const executor = {
setProxyCmd.push(`gsettings set org.gnome.system.proxy ignore-hosts "['${excludeIpStr}']"`)
await exec(setProxyCmd)
- }
- else { // 关闭代理
+ } else { // 关闭代理
const setProxyCmd = [
'gsettings set org.gnome.system.proxy mode none',
]
@@ -328,8 +313,7 @@ const executor = {
// http
if (config.get().proxy.proxyHttp) {
await exec(`networksetup -setwebproxy "${wifiAdaptor}" ${ip} ${port - 1}`)
- }
- else {
+ } else {
await exec(`networksetup -setwebproxystate "${wifiAdaptor}" off`)
}
@@ -344,8 +328,7 @@ const executor = {
// source ~/.zshrc
// `
// await exec(setEnv)
- }
- else { // 关闭代理
+ } else { // 关闭代理
// https
await exec(`networksetup -setsecurewebproxystate "${wifiAdaptor}" off`)
// http
diff --git a/packages/core/src/shell/shell.js b/packages/core/src/shell/shell.js
index 7b16c4eaf5..9ab1facb3b 100644
--- a/packages/core/src/shell/shell.js
+++ b/packages/core/src/shell/shell.js
@@ -60,12 +60,10 @@ class WindowsSystemShell extends SystemShell {
const ret = await ps.invoke()
// log.info('ps complete', cmds)
return ret
- }
- finally {
+ } finally {
ps.dispose()
}
- }
- else {
+ } else {
let compose = 'echo "test" ' // 'chcp 65001 '
for (const cmd of cmds) {
compose += ` && ${cmd}`
@@ -88,8 +86,7 @@ function _childExec (composeCmds, options = {}) {
log.error('cmd 命令执行错误:\n===>\ncommands:', composeCmds, '\n error:', error, '\n<===')
}
reject(new Error(stderr))
- }
- else {
+ } else {
// log.info('cmd 命令完成:', stdout)
resolve(stdout)
}
@@ -114,8 +111,7 @@ function childExec (composeCmds, options = {}) {
log.error('cmd 命令执行错误:\n------------------------------\ncommands:', composeCmds, '\n message:', message, '\n error:', error, '\n------------------------------')
}
reject(new Error(message))
- }
- else {
+ } else {
// log.info('cmd 命令完成:', stdout)
const message = iconv.decode(Buffer.from(stdout, binaryEncoding), encoding)
resolve(message)
@@ -171,8 +167,7 @@ async function execFile (file, args, options) {
log.debug('文件执行成功:', file)
resolve(stdout)
})
- }
- catch (e) {
+ } catch (e) {
log.error('文件执行出错:', file, e)
reject(e)
}
diff --git a/packages/gui/pkg/after-pack.js b/packages/gui/pkg/after-pack.js
index f897f08eac..699593be51 100644
--- a/packages/gui/pkg/after-pack.js
+++ b/packages/gui/pkg/after-pack.js
@@ -24,13 +24,11 @@ exports.default = async function (context) {
if (context.packager.platform.nodeName === 'darwin') {
targetPath = path.join(context.appOutDir, `${context.packager.appInfo.productName}.app/Contents/Resources`)
systemType = 'mac'
- }
- else if (context.packager.platform.nodeName === 'linux') {
+ } else if (context.packager.platform.nodeName === 'linux') {
targetPath = path.join(context.appOutDir, './resources')
systemType = 'linux'
writeAppUpdateYmlForLinux()
- }
- else {
+ } else {
targetPath = path.join(context.appOutDir, './resources')
systemType = 'win'
}
diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js
index aa4a72797c..f755123c07 100644
--- a/packages/gui/src/background.js
+++ b/packages/gui/src/background.js
@@ -34,8 +34,7 @@ function openDevTools () {
log.debug('尝试打开 `开发者工具`')
win.webContents.openDevTools()
log.debug('打开 `开发者工具` 成功')
- }
- catch (e) {
+ } catch (e) {
log.error('打开 `开发者工具` 失败:', e)
}
}
@@ -45,8 +44,7 @@ function closeDevTools () {
log.debug('尝试关闭 `开发者工具`')
win.webContents.closeDevTools()
log.debug('关闭 `开发者工具` 成功')
- }
- catch (e) {
+ } catch (e) {
log.error('关闭 `开发者工具` 失败:', e)
}
}
@@ -57,8 +55,7 @@ function switchDevTools () {
}
if (win.webContents.isDevToolsOpened()) {
closeDevTools()
- }
- else {
+ } else {
openDevTools()
}
}
@@ -105,8 +102,7 @@ function setTray () {
if (nativeTheme.shouldUseDarkColors) {
console.log('i am dark.')
tray.setImage(iconWhitePath)
- }
- else {
+ } else {
console.log('i am light.')
tray.setImage(iconBlackPath)
// tray.setPressedImage(iconWhitePath)
@@ -204,8 +200,7 @@ function createWindow (startHideWindow) {
if (!process.env.IS_TEST) {
setTimeout(openDevTools, 2000)
}
- }
- else {
+ } else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')
@@ -224,8 +219,7 @@ function createWindow (startHideWindow) {
ipcMain.on('close', async (event, message) => {
if (message.value === 1) {
quit()
- }
- else {
+ } else {
hideWin()
}
})
@@ -245,12 +239,10 @@ function createWindow (startHideWindow) {
if (closeStrategy === 0) {
// 弹窗提示,选择关闭策略
win.webContents.send('close.showTip', closeStrategy)
- }
- else if (closeStrategy === 1) {
+ } else if (closeStrategy === 1) {
// 直接退出
quit()
- }
- else if (closeStrategy === 2) {
+ } else if (closeStrategy === 2) {
// 隐藏窗口
hideWin()
}
@@ -328,8 +320,7 @@ function registerShowHideShortcut (showHideShortcut) {
if (winIsHidden) {
showWin()
}
- }
- else {
+ } else {
// linux,快捷键不关闭窗口
if (!isLinux()) {
hideWin()
@@ -339,12 +330,10 @@ function registerShowHideShortcut (showHideShortcut) {
if (registerSuccess) {
log.info('注册快捷键成功:', DevSidecar.api.config.get().app.showHideShortcut)
- }
- else {
+ } else {
log.error('注册快捷键失败:', DevSidecar.api.config.get().app.showHideShortcut)
}
- }
- catch (e) {
+ } catch (e) {
log.error('注册快捷键异常:', DevSidecar.api.config.get().app.showHideShortcut, ', error:', e)
}
}
@@ -370,8 +359,7 @@ app.disableHardwareAcceleration() // 禁用gpu
let startHideWindow = !DevSidecar.api.config.get().app.startShowWindow
if (app.getLoginItemSettings().wasOpenedAsHidden) {
startHideWindow = true
-}
-else if (process.argv) {
+} else if (process.argv) {
const args = minimist(process.argv)
log.info('start args:', args)
@@ -379,8 +367,7 @@ else if (process.argv) {
const hideWindowArg = `${args.hideWindow}`
if (hideWindowArg === 'true' || hideWindowArg === '1') {
startHideWindow = true
- }
- else if (hideWindowArg === 'false' || hideWindowArg === '0') {
+ } else if (hideWindowArg === 'false' || hideWindowArg === '0') {
startHideWindow = false
}
}
@@ -393,8 +380,7 @@ if (!isFirstInstance) {
setTimeout(() => {
app.quit()
}, 1000)
-}
-else {
+} else {
app.on('before-quit', async () => {
log.info('before-quit')
if (process.platform === 'darwin') {
@@ -428,8 +414,7 @@ else {
// dock icon is clicked and there are no other windows open.
if (win == null) {
createWindow(false)
- }
- else {
+ } else {
showWin()
}
})
@@ -452,16 +437,14 @@ else {
createWindow(startHideWindow)
const context = { win, app, beforeQuit, quit, ipcMain, dialog, log, api: DevSidecar.api, changeAppConfig }
backend.install(context) // 模块安装
- }
- catch (err) {
+ } catch (err) {
log.info('error:', err)
}
try {
// 最小化到托盘
tray = setTray()
- }
- catch (err) {
+ } catch (err) {
log.info('error:', err)
}
@@ -489,8 +472,7 @@ if (isDevelopment) {
quit()
}
})
- }
- else {
+ } else {
process.on('SIGINT', () => {
quit()
})
diff --git a/packages/gui/src/background/powerMonitor.js b/packages/gui/src/background/powerMonitor.js
index 335f8a67d7..3431fe623d 100644
--- a/packages/gui/src/background/powerMonitor.js
+++ b/packages/gui/src/background/powerMonitor.js
@@ -34,8 +34,7 @@ class PowerMonitor {
releaseShutdownBlock()
this._shutdownCallback = null
}
- }
- else {
+ } else {
return _powerMonitor.removeAllListeners(event)
}
}
@@ -51,8 +50,7 @@ class PowerMonitor {
acquireShutdownBlock('正在停止 DevSidecar 代理')
}
this._listeners.push(listener)
- }
- else {
+ } else {
return _powerMonitor.on(event, listener)
}
}
@@ -60,8 +58,7 @@ class PowerMonitor {
off (event, listener) {
if (event === 'shutdown' && process.platform === 'win32') {
this._listeners = this._listeners.filter(fn => fn !== listener)
- }
- else {
+ } else {
return _powerMonitor.off(event, listener)
}
}
@@ -69,8 +66,7 @@ class PowerMonitor {
once (event, listener) {
if (event === 'shutdown' && process.platform === 'win32') {
return this.on(event, listener)
- }
- else {
+ } else {
return _powerMonitor.once(event, listener)
}
}
diff --git a/packages/gui/src/bridge/api/backend.js b/packages/gui/src/bridge/api/backend.js
index d839a6f3da..7fbd3414c1 100644
--- a/packages/gui/src/bridge/api/backend.js
+++ b/packages/gui/src/bridge/api/backend.js
@@ -1,5 +1,5 @@
-import fs from 'fs'
-import path from 'path'
+import fs from 'node:fs'
+import path from 'node:path'
import DevSidecar from '@docmirror/dev-sidecar'
import { ipcMain } from 'electron'
import lodash from 'lodash'
@@ -66,8 +66,7 @@ const localApi = {
try {
setting = jsonApi.parse(file.toString())
log.info('读取 setting.json 成功:', settingPath)
- }
- catch (e) {
+ } catch (e) {
log.error('读取 setting.json 失败:', settingPath, ', error:', e)
}
if (setting == null) {
@@ -131,8 +130,7 @@ function _deepFindFunction (list, parent, parentKey) {
const item = parent[key]
if (item instanceof Function) {
list.push(parentKey + key)
- }
- else if (item instanceof Object) {
+ } else if (item instanceof Object) {
_deepFindFunction(list, item, `${parentKey + key}.`)
}
}
@@ -142,8 +140,7 @@ function _getSettingsPath () {
const dir = getDefaultConfigBasePath()
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
- }
- else {
+ } else {
// 兼容1.7.3及以下版本的配置文件处理逻辑
const newFilePath = path.join(dir, '/setting.json')
const oldFilePath = path.join(dir, '/setting.json5')
diff --git a/packages/gui/src/bridge/auto-start/backend.js b/packages/gui/src/bridge/auto-start/backend.js
index 9748cb21f0..fed4d26513 100644
--- a/packages/gui/src/bridge/auto-start/backend.js
+++ b/packages/gui/src/bridge/auto-start/backend.js
@@ -19,8 +19,7 @@ Comment=
EOF
`
await DevSidecar.api.shell.exec(cmd)
- }
- else {
+ } else {
const removeStart = 'sudo rm ~/.config/autostart/dev-sidecar.desktop -rf'
await DevSidecar.api.shell.exec(removeStart)
}
@@ -40,8 +39,7 @@ export default {
if (message.value) {
if (isLinux) {
await setAutoStartForLinux(app, true)
- }
- else {
+ } else {
app.setLoginItemSettings({
openAtLogin: true,
openAsHidden: true,
@@ -53,12 +51,10 @@ export default {
}
event.sender.send('auto-start', { key: 'enabled', value: true })
- }
- else {
+ } else {
if (isLinux) {
await setAutoStartForLinux(app, false)
- }
- else {
+ } else {
app.setLoginItemSettings({
openAtLogin: false,
openAsHidden: false,
diff --git a/packages/gui/src/bridge/auto-start/front.js b/packages/gui/src/bridge/auto-start/front.js
index bf445a5d65..4d19525b1a 100644
--- a/packages/gui/src/bridge/auto-start/front.js
+++ b/packages/gui/src/bridge/auto-start/front.js
@@ -2,8 +2,7 @@ function install (app, api) {
api.ipc.on('auto-start', (event, message) => {
if (message.value === true) {
app.$message.info('已添加开机自启')
- }
- else {
+ } else {
app.$message.info('已取消开机自启')
}
})
diff --git a/packages/gui/src/bridge/error/front.js b/packages/gui/src/bridge/error/front.js
index 1935c65f6d..abb835f4c7 100644
--- a/packages/gui/src/bridge/error/front.js
+++ b/packages/gui/src/bridge/error/front.js
@@ -29,8 +29,7 @@ function handleServerStartError (message, err, app, api) {
console.log('Cancel')
},
})
- }
- else {
+ } else {
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 6bf745c89f..6cdec455ed 100644
--- a/packages/gui/src/bridge/file-selector/backend.js
+++ b/packages/gui/src/bridge/file-selector/backend.js
@@ -9,8 +9,7 @@ export default {
}).then((result) => {
if (result.canceled) {
event.sender.send('file-selector', { key: 'canceled' })
- }
- else {
+ } else {
event.sender.send('file-selector', { key: 'selected', value: result.filePaths })
}
}).catch((err) => {
diff --git a/packages/gui/src/bridge/file-selector/front.js b/packages/gui/src/bridge/file-selector/front.js
index 27b4828bb3..69b0d31b5b 100644
--- a/packages/gui/src/bridge/file-selector/front.js
+++ b/packages/gui/src/bridge/file-selector/front.js
@@ -7,8 +7,7 @@ function install (app, api) {
console.log('selector', message)
if (message.key === 'selected') {
resolve(message.value)
- }
- else {
+ } else {
reject(new Error('没有选择文件'))
}
api.ipc.on('file-selector', () => {})
diff --git a/packages/gui/src/bridge/tongji/front.js b/packages/gui/src/bridge/tongji/front.js
index 53cdf37f55..4d54f3bc8b 100644
--- a/packages/gui/src/bridge/tongji/front.js
+++ b/packages/gui/src/bridge/tongji/front.js
@@ -19,7 +19,9 @@ function ebtRenderer (ipcRenderer, siteId, router) {
ipcRenderer.on('electron-baidu-tongji-reply', (_, { text, isDevelopment }) => {
console.log('electron-baidu-tongji-reply')
/* istanbul ignore else */
- if (isDevelopment) { document.body.classList.add('electron-baidu-tongji_dev') }
+ if (isDevelopment) {
+ document.body.classList.add('electron-baidu-tongji_dev')
+ }
window._hmt = window._hmt || []
diff --git a/packages/gui/src/bridge/update/backend.js b/packages/gui/src/bridge/update/backend.js
index 8d51805b9f..3b8eda1bb0 100644
--- a/packages/gui/src/bridge/update/backend.js
+++ b/packages/gui/src/bridge/update/backend.js
@@ -85,16 +85,14 @@ function isNewVersion (version, curVersion) {
if (versionObj.suffix > curVersionObj.suffix) {
return 41
}
- }
- else if (!versionObj.suffix && curVersionObj.suffix) {
+ } else if (!versionObj.suffix && curVersionObj.suffix) {
// 线上版本号没有后缀版本号,说明为正式版本,为更新版本
return 42
}
}
}
}
- }
- catch (e) {
+ } catch (e) {
log.error(`比对版本失败,当前版本号:${curVersion},比对版本号:${version}, error:`, e)
return -99
}
@@ -127,11 +125,9 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
// })
if (isMac) {
autoUpdater.updateConfigPath = path.join(__dirname, 'mac/dev-sidecar.app/Contents/Resources/app-update.yml')
- }
- else if (isLinux) {
+ } else if (isLinux) {
autoUpdater.updateConfigPath = path.join(__dirname, 'linux-unpacked/resources/app-update.yml')
- }
- else {
+ } else {
autoUpdater.updateConfigPath = path.join(__dirname, 'win-unpacked/resources/app-update.yml')
}
}
@@ -163,8 +159,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
let data
try {
data = JSON.parse(body)
- }
- catch (e) {
+ } catch (e) {
log.error('检查更新失败,github API返回数据格式不正确:', body)
win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: '检查更新失败,github API返回数据格式不正确' })
return
@@ -211,8 +206,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
: '无',
},
})
- }
- else {
+ } else {
log.info(`检查更新:没有新版本,最近发布的版本号为 '${version}',而当前版本号为 '${curVersion}'`)
win.webContents.send('update', { key: 'notAvailable' })
}
@@ -222,29 +216,25 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
log.info('检查更新-没有正式版本数据')
win.webContents.send('update', { key: 'notAvailable' })
- }
- else {
+ } else {
log.error('检查更新失败, status:', response.statusCode, ', body:', body)
let bodyObj
try {
bodyObj = JSON.parse(body)
- }
- catch (e) {
+ } catch (e) {
bodyObj = null
}
let message
if (response) {
message = `检查更新失败: ${bodyObj && bodyObj.message ? bodyObj.message : response.message}, code: ${response.statusCode}`
- }
- else {
+ } else {
message = `检查更新失败: ${bodyObj && bodyObj.message ? bodyObj.message : body}`
}
win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: message })
}
- }
- catch (e) {
+ } catch (e) {
log.error('检查更新失败:', e)
win.webContents.send('update', { key: 'error', action: 'checkForUpdate', error: `检查更新失败:${e.message}` })
}
@@ -258,8 +248,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
log.info('download dir:', fileDir)
try {
fs.accessSync(fileDir, fs.constants.F_OK)
- }
- catch (e) {
+ } catch (e) {
fs.mkdirSync(fileDir)
}
const filePath = path.join(fileDir, `${value.version}.zip`)
@@ -299,8 +288,7 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
const zip = new AdmZip(partPackagePath)
zip.extractAllTo(target, true)
log.info('安装完成,重启app')
- }
- finally {
+ } finally {
app.exit(0)
}
}
@@ -351,21 +339,18 @@ function updateHandle (app, api, win, beforeQuit, quit, log) {
}, 1000)
}
})
- }
- else if (arg.key === 'checkForUpdate') {
+ } else if (arg.key === 'checkForUpdate') {
// 执行自动更新检查
log.info('autoUpdater checkForUpdates:', arg.fromUser)
// 调用 github API,获取release数据,来检查更新
// autoUpdater.checkForUpdates()
checkForUpdatesFromGitHub()
- }
- else if (arg.key === 'downloadUpdate') {
+ } else if (arg.key === 'downloadUpdate') {
// 下载新版本
log.info('autoUpdater downloadUpdate')
autoUpdater.downloadUpdate()
- }
- else if (arg.key === 'downloadPart') {
+ } else if (arg.key === 'downloadPart') {
// 下载增量更新版本
log.info('autoUpdater downloadPart')
downloadPart(app, arg.value)
diff --git a/packages/gui/src/bridge/update/front.js b/packages/gui/src/bridge/update/front.js
index 06846462ff..254e9f6f08 100644
--- a/packages/gui/src/bridge/update/front.js
+++ b/packages/gui/src/bridge/update/front.js
@@ -31,28 +31,23 @@ function install (app, api) {
updateParams.checking = false
updateParams.newVersionData = message.value
foundNewVersion(message.value)
- }
- else if (type === 'notAvailable') {
+ } else if (type === 'notAvailable') {
updateParams.checking = false
noNewVersion()
- }
- else if (type === 'downloaded') {
+ } else if (type === 'downloaded') {
// 更新包已下载完成,让用户确认是否更新
updateParams.downloading = false
console.log('updateParams', updateParams)
newUpdateIsReady(message.value)
- }
- else if (type === 'progress') {
+ } else if (type === 'progress') {
progressUpdate(message.value)
- }
- else if (type === 'error') {
+ } else if (type === 'error') {
updateParams.checking = false
updateParams.downloading = false
if (message.action === 'checkForUpdate' && updateParams.newVersionData) {
// 如果检查更新报错了,但刚才成功拿到过一次数据,就拿之前的数据
foundNewVersion(updateParams.newVersionData)
- }
- else {
+ } else {
if (updateParams.fromUser === false && message.action === 'checkForUpdate') {
return // 不是手动检查更新,不提示错误信息,避免打扰
}
@@ -174,8 +169,7 @@ function install (app, api) {
)
- }
- else {
+ } else {
for (const note of value.releaseNotes) {
notes.push( - {note}
)
}
@@ -227,8 +221,7 @@ function install (app, api) {
)
- }
- else {
+ } else {
for (const note of value.releaseNotes) {
notes.push(- {note}
)
}
diff --git a/packages/gui/src/view/components/setup-ca.vue b/packages/gui/src/view/components/setup-ca.vue
index 07bb2c941b..8ad8fa9502 100644
--- a/packages/gui/src/view/components/setup-ca.vue
+++ b/packages/gui/src/view/components/setup-ca.vue
@@ -22,11 +22,9 @@ export default {
setupImage () {
if (this.systemPlatform === 'mac') {
return '/setup-mac.png'
- }
- else if (this.systemPlatform === 'linux') {
+ } else if (this.systemPlatform === 'linux') {
return '/setup-linux.png'
- }
- else {
+ } else {
return '/setup.png'
}
},
diff --git a/packages/gui/src/view/mixins/plugin.js b/packages/gui/src/view/mixins/plugin.js
index 284e85d1a1..aa94c8673f 100644
--- a/packages/gui/src/view/mixins/plugin.js
+++ b/packages/gui/src/view/mixins/plugin.js
@@ -48,8 +48,7 @@ export default {
await this.applyBefore()
await this.saveConfig()
await this.applyAfter()
- }
- finally {
+ } finally {
this.applyLoading = false
}
},
@@ -74,8 +73,7 @@ export default {
await this.ready(this.config)
}
await this.apply()
- }
- finally {
+ } finally {
this.resetDefaultLoading = false
}
},
@@ -127,8 +125,7 @@ export default {
await this.$api.plugin.git.start()
}
this.$message.success('代理服务和系统代理重启成功')
- }
- else {
+ } else {
this.$message.info('代理服务和系统代理未启动,无需重启')
}
},
diff --git a/packages/gui/src/view/pages/index.vue b/packages/gui/src/view/pages/index.vue
index 748492258e..5115d8d273 100644
--- a/packages/gui/src/view/pages/index.vue
+++ b/packages/gui/src/view/pages/index.vue
@@ -21,8 +21,7 @@ export default {
doClick: () => {
if (this.status.server.enabled) {
this.apiCall(this.startup, this.$api.shutdown)
- }
- else {
+ } else {
this.apiCall(this.startup, this.$api.startup)
}
},
@@ -76,13 +75,11 @@ export default {
this.config.server.intercept.enabled = false
this.config.server.dns.speedTest.enabled = true
this.config.plugin.overwall.enabled = false
- }
- else if (mode === 'default') {
+ } else if (mode === 'default') {
this.config.server.intercept.enabled = true
this.config.server.dns.speedTest.enabled = true
this.config.plugin.overwall.enabled = false
- }
- else if (mode === 'ow') {
+ } else if (mode === 'ow') {
console.log('event', event)
if (!this.setting.overwall) {
this.wantOW()
@@ -204,12 +201,10 @@ export default {
const ret = await api(param)
console.log('this status', this.status)
return ret
- }
- catch (err) {
+ } catch (err) {
btn.loading = false // 有时候记录日志会卡死,先设置为false
console.log('api invoke error:', err)
- }
- finally {
+ } finally {
btn.loading = false
}
},
@@ -217,8 +212,7 @@ export default {
onSwitchClick (btn, openApi, closeApi, checked) {
if (checked) {
return this.apiCall(btn, openApi)
- }
- else {
+ } else {
return this.apiCall(btn, closeApi)
}
},
diff --git a/packages/gui/src/view/pages/plugin/git.vue b/packages/gui/src/view/pages/plugin/git.vue
index dbbd78d06c..998e413a6e 100644
--- a/packages/gui/src/view/pages/plugin/git.vue
+++ b/packages/gui/src/view/pages/plugin/git.vue
@@ -24,8 +24,7 @@ export default {
if (this.status.plugin.git.enabled) {
await this.$api.plugin.git.close()
this.needRestart = true
- }
- else {
+ } else {
this.needRestart = false
}
this.submitNoProxyUrls()
diff --git a/packages/gui/src/view/pages/proxy.vue b/packages/gui/src/view/pages/proxy.vue
index 28cffbe327..93360bf2ac 100644
--- a/packages/gui/src/view/pages/proxy.vue
+++ b/packages/gui/src/view/pages/proxy.vue
@@ -31,8 +31,7 @@ export default {
async openEnableLoopback () {
try {
await this.$api.proxy.setEnableLoopback()
- }
- catch (e) {
+ } catch (e) {
if (e.message.includes('EACCES')) {
this.$message.error('请将DevSidecar关闭后,以管理员身份重新打开,再尝试此操作')
return
diff --git a/packages/gui/src/view/pages/setting.vue b/packages/gui/src/view/pages/setting.vue
index b0df36e19c..940e539c74 100644
--- a/packages/gui/src/view/pages/setting.vue
+++ b/packages/gui/src/view/pages/setting.vue
@@ -218,12 +218,10 @@ export default {
await this.$api.config.downloadRemoteConfig()
this.$message.info('下载远程配置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
- }
- finally {
+ } finally {
this.reloadLoading = false
}
- }
- else {
+ } else {
this.$message.info('远程配置已关闭,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
}
@@ -237,22 +235,28 @@ export default {
try {
const remoteConfig = {}
- await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.old1 = ret })
- await this.$api.config.readRemoteConfigStr('_personal').then((ret) => { remoteConfig.old2 = ret })
+ await this.$api.config.readRemoteConfigStr().then((ret) => {
+ remoteConfig.old1 = ret
+ })
+ await this.$api.config.readRemoteConfigStr('_personal').then((ret) => {
+ remoteConfig.old2 = ret
+ })
await this.$api.config.downloadRemoteConfig()
- await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.new1 = ret })
- await this.$api.config.readRemoteConfigStr('_personal').then((ret) => { remoteConfig.new2 = ret })
+ await this.$api.config.readRemoteConfigStr().then((ret) => {
+ remoteConfig.new1 = ret
+ })
+ await this.$api.config.readRemoteConfigStr('_personal').then((ret) => {
+ remoteConfig.new2 = ret
+ })
if (remoteConfig.old1 === remoteConfig.new1 && remoteConfig.old2 === remoteConfig.new2) {
this.$message.info('远程配置没有变化,不做任何处理。')
this.$message.warn('如果您确实修改了远程配置,请稍等片刻再重试!')
- }
- else {
+ } else {
this.$message.success('获取到了最新的远程配置,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
}
- }
- finally {
+ } finally {
this.reloadLoading = false
}
},
@@ -297,12 +301,10 @@ export default {
this.config = await this.$api.config.get()
this.$message.success('恢复出厂设置成功,开始重启代理服务和系统代理')
await this.reloadConfigAndRestart()
- }
- else {
+ } else {
this.$message.info('已是出厂设置,无需恢复')
}
- }
- finally {
+ } finally {
this.removeUserConfigLoading = false
}
},
diff --git a/packages/mitmproxy/src/index.js b/packages/mitmproxy/src/index.js
index cf08359470..4e0dba6314 100644
--- a/packages/mitmproxy/src/index.js
+++ b/packages/mitmproxy/src/index.js
@@ -12,8 +12,7 @@ function registerProcessListener () {
log.info('child get msg:', JSON.stringify(msg))
if (msg.type === 'action') {
api[msg.event.key](msg.event.params)
- }
- else if (msg.type === 'speed') {
+ } else if (msg.type === 'speed') {
speedTest.action(msg.event)
}
})
@@ -62,8 +61,7 @@ const api = {
if (proxyOptions.setting && proxyOptions.setting.NODE_TLS_REJECT_UNAUTHORIZED === false) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
- }
- else {
+ } else {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '1'
}
// log.info('启动代理服务时的配置:', JSON.stringify(proxyOptions, null, '\t'))
@@ -100,8 +98,7 @@ const api = {
if (err.code === 'ERR_SERVER_NOT_RUNNING') {
log.info('代理服务未运行,无需关闭')
resolve()
- }
- else {
+ } else {
log.error('代理服务关闭失败:', err)
reject(err)
}
@@ -113,8 +110,7 @@ const api = {
})
}
servers = []
- }
- else {
+ } else {
log.info('server is null, no need to close.')
fireStatus(false)
resolve()
diff --git a/packages/mitmproxy/src/json.js b/packages/mitmproxy/src/json.js
index cf0e09ab02..1e90c94888 100644
--- a/packages/mitmproxy/src/json.js
+++ b/packages/mitmproxy/src/json.js
@@ -17,12 +17,10 @@ module.exports = {
stringify2 (obj) {
try {
return JSON.stringify(obj)
- }
- catch (e) {
+ } catch (e) {
try {
return JSON5.stringify(obj)
- }
- catch (e2) {
+ } catch (e2) {
log.debug('转换为JSON字符串失败, error:', e, ', obj:', obj)
return obj
}
diff --git a/packages/mitmproxy/src/lib/choice/index.js b/packages/mitmproxy/src/lib/choice/index.js
index 867876094c..964c2c6ff5 100644
--- a/packages/mitmproxy/src/lib/choice/index.js
+++ b/packages/mitmproxy/src/lib/choice/index.js
@@ -88,8 +88,7 @@ class DynamicChoice {
if (this.backupList.length > 0) {
this.value = this.backupList.shift()
log.info(`切换backup完成: ${this.key}, ip: ${valueBackup} ➜ ${this.value}, this:`, this)
- }
- else {
+ } else {
this.value = null
log.info(`切换backup完成: ${this.key}, backupList为空了,设置this.value: from '${valueBackup}' to null. this:`, this)
}
@@ -110,8 +109,7 @@ class DynamicChoice {
// 失败次数+1,累计连续失败次数+1
count.error++
count.keepErrorCount++
- }
- else {
+ } else {
// 总次数+1
count.total++
}
diff --git a/packages/mitmproxy/src/lib/dns/base.js b/packages/mitmproxy/src/lib/dns/base.js
index 3b6637f131..14d2ca2041 100644
--- a/packages/mitmproxy/src/lib/dns/base.js
+++ b/packages/mitmproxy/src/lib/dns/base.js
@@ -43,8 +43,7 @@ module.exports = class BaseDNS {
ipCache.doCount(ipCache.value, false)
return ipCache.value
}
- }
- else {
+ } else {
ipCache = new IpCache(hostname)
this.cache.set(hostname, ipCache)
}
@@ -61,8 +60,7 @@ module.exports = class BaseDNS {
log.info(`[DNS]: ${hostname} ➜ ${ipCache.value} (${new Date() - t} ms), ipList: ${JSON.stringify(ipList)}, ipCache:`, JSON.stringify(ipCache))
return ipCache.value
- }
- catch (error) {
+ } catch (error) {
log.error(`[DNS] cannot resolve hostname ${hostname} (${error})`, error)
return hostname
}
diff --git a/packages/mitmproxy/src/lib/dns/https.js b/packages/mitmproxy/src/lib/dns/https.js
index eb76a296b0..3175da0f28 100644
--- a/packages/mitmproxy/src/lib/dns/https.js
+++ b/packages/mitmproxy/src/lib/dns/https.js
@@ -30,8 +30,7 @@ module.exports = class DNSOverHTTPS extends BaseDNS {
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
if (hostnamePreSetIpList.length > 0) {
hostnamePreSetIpList = hostnamePreSetIpList.slice()
- }
- else {
+ } else {
hostnamePreSetIpList = mapToList(hostnamePreSetIpList)
}
@@ -53,13 +52,11 @@ module.exports = class DNSOverHTTPS extends BaseDNS {
const ret = result.answers.filter(item => item.type === 'A').map(item => item.data)
if (ret.length === 0) {
log.info('该域名没有IPv4地址解析:', hostname, ', cost:', (new Date() - start), 'ms')
- }
- else {
+ } else {
log.info('获取到域名地址:', hostname, JSON.stringify(ret), ', cost:', (new Date() - start), 'ms')
}
return ret
- }
- catch (e) {
+ } catch (e) {
log.warn('DNS query error:', hostname, ', dns:', this.dnsServer, ', cost:', (new Date() - start), 'ms, error:', e)
return []
}
diff --git a/packages/mitmproxy/src/lib/dns/index.js b/packages/mitmproxy/src/lib/dns/index.js
index 297694cc3f..0e23f7a5b5 100644
--- a/packages/mitmproxy/src/lib/dns/index.js
+++ b/packages/mitmproxy/src/lib/dns/index.js
@@ -14,11 +14,9 @@ module.exports = {
if (conf.type === 'ipaddress') {
dnsMap[provider] = new DNSOverIpAddress(conf.server)
- }
- else if (conf.type === 'https') {
+ } else if (conf.type === 'https') {
dnsMap[provider] = new DNSOverHTTPS(conf.server, preSetIpList)
- }
- else {
+ } else {
dnsMap[provider] = new DNSOverTLS(conf.server)
}
diff --git a/packages/mitmproxy/src/lib/dns/preset.js b/packages/mitmproxy/src/lib/dns/preset.js
index 3ff7dafd6a..f5e0e1a21b 100644
--- a/packages/mitmproxy/src/lib/dns/preset.js
+++ b/packages/mitmproxy/src/lib/dns/preset.js
@@ -26,8 +26,7 @@ module.exports = class DNSOverPreSetIpList extends BaseDNS {
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
if (hostnamePreSetIpList.length > 0) {
hostnamePreSetIpList = hostnamePreSetIpList.slice()
- }
- else {
+ } else {
hostnamePreSetIpList = mapToList(hostnamePreSetIpList)
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/OPTIONS.js b/packages/mitmproxy/src/lib/interceptor/impl/req/OPTIONS.js
index b55e11718c..45b6c863e0 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/OPTIONS.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/OPTIONS.js
@@ -6,8 +6,7 @@ function readConfig (config, defaultConfig) {
if (Object.isArray(config)) {
config = config.join(',')
}
- }
- else {
+ } else {
config = defaultConfig
}
return config
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/baiduOcr.js b/packages/mitmproxy/src/lib/interceptor/impl/req/baiduOcr.js
index 926eaf1af8..dcce58773b 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/baiduOcr.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/baiduOcr.js
@@ -60,8 +60,7 @@ function getConfig (interceptOpt, tryCount, log) {
if (count >= 100000) {
count = 0
}
- }
- else {
+ } else {
config = interceptOpt.baiduOcr
tryCount = null // 将tryCount设置为null代表只有一个配置
}
@@ -84,13 +83,11 @@ function getConfig (interceptOpt, tryCount, log) {
if (config.api == null) {
if (tryCount == null) {
return null // 只配置了一个账号,没有更多账号可以选择了,直接返回null
- }
- else {
+ } else {
if (tryCount < interceptOpt.baiduOcr.length) {
// 递归找到有效的配置
return getConfig(interceptOpt, tryCount + 1, log)
- }
- else {
+ } else {
return null
}
}
@@ -167,8 +164,7 @@ module.exports = {
limitConfig(config.id, config.api)
log.error(`当前百度云账号的接口 ${config.api},已达到当日调用次数上限,暂时禁用它,明天会自动放开:`, config)
}
- }
- else {
+ } else {
log.info('baiduOcr success:', result)
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/cacheReq.js b/packages/mitmproxy/src/lib/interceptor/impl/req/cacheReq.js
index 5246be4886..5028002b15 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/cacheReq.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/cacheReq.js
@@ -42,8 +42,7 @@ function getLastModifiedTimeFromIfModifiedSince (rOptions, log) {
try {
// 尝试解析 lastModified,并获取time
return new Date(lastModified).getTime()
- }
- catch (e) {
+ } catch (e) {
// 为数字时,直接返回
if (/\\d+/.test(lastModified)) {
return lastModified - 0
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js b/packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js
index 327f4be679..90efd335b9 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js
@@ -27,11 +27,9 @@ function buildTargetUrl (rOptions, urlConf, interceptOpt, matched) {
if (interceptOpt && interceptOpt.replace) {
const regexp = new RegExp(interceptOpt.replace)
targetUrl = rOptions.path.replace(regexp, urlConf)
- }
- else if (urlConf.indexOf('http:') === 0 || urlConf.indexOf('https:') === 0) {
+ } else if (urlConf.indexOf('http:') === 0 || urlConf.indexOf('https:') === 0) {
targetUrl = urlConf
- }
- else {
+ } else {
let uri = rOptions.path
if (uri.indexOf('http:') === 0 || uri.indexOf('https:') === 0) {
// eslint-disable-next-line node/no-deprecated-api
@@ -97,8 +95,7 @@ module.exports = {
}
if (count.value == null) {
log.error('`count.value` is null, the count:', count)
- }
- else {
+ } else {
count.doCount(count.value)
proxyConf = count.value
context.requestCount = {
@@ -127,8 +124,7 @@ module.exports = {
}
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}, sni: ${interceptOpt.sni}${unVerifySsl ? ', unVerifySsl' : ''}`)
log.info('proxy intercept: hostname:', originHostname, ', target:', proxyTarget, ', sni replace servername:', rOptions.servername, (unVerifySsl ? ', unVerifySsl' : ''))
- }
- else {
+ } else {
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}`)
log.info('proxy intercept: hostname:', originHostname, ', target:', proxyTarget)
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/req/requestReplace.js b/packages/mitmproxy/src/lib/interceptor/impl/req/requestReplace.js
index 7ed12c2ef6..219959d526 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/req/requestReplace.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/req/requestReplace.js
@@ -10,8 +10,7 @@ function replaceRequestHeaders (rOptions, headers, log) {
if (value) {
log.debug(`[DS-RequestReplace-Interceptor] replace '${key}': '${rOptions.headers[key.toLowerCase()]}' -> '${value}'`)
rOptions.headers[key.toLowerCase()] = value
- }
- else if (rOptions.headers[key.toLowerCase()]) {
+ } else if (rOptions.headers[key.toLowerCase()]) {
log.debug(`[DS-RequestReplace-Interceptor] remove '${key}': '${rOptions.headers[key.toLowerCase()]}'`)
delete rOptions.headers[key.toLowerCase()]
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/res/cacheRes.js b/packages/mitmproxy/src/lib/interceptor/impl/res/cacheRes.js
index 54fe7a2c31..62f37feee0 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/res/cacheRes.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/res/cacheRes.js
@@ -47,14 +47,11 @@ module.exports = {
// 尝试修改rawHeaders中的cache-control、last-modified、expires
if (proxyRes.rawHeaders[i].toLowerCase() === 'cache-control') {
originalHeaders.cacheControl = { value: proxyRes.rawHeaders[i + 1], valueIndex: i + 1 }
- }
- else if (proxyRes.rawHeaders[i].toLowerCase() === 'last-modified') {
+ } else if (proxyRes.rawHeaders[i].toLowerCase() === 'last-modified') {
originalHeaders.lastModified = { value: proxyRes.rawHeaders[i + 1], valueIndex: i + 1 }
- }
- else if (proxyRes.rawHeaders[i].toLowerCase() === 'expires') {
+ } else if (proxyRes.rawHeaders[i].toLowerCase() === 'expires') {
originalHeaders.expires = { value: proxyRes.rawHeaders[i + 1], valueIndex: i + 1 }
- }
- else if (proxyRes.rawHeaders[i].toLowerCase() === 'etag') {
+ } else if (proxyRes.rawHeaders[i].toLowerCase() === 'etag') {
originalHeaders.etag = { value: proxyRes.rawHeaders[i + 1], valueIndex: i + 1 }
}
@@ -70,8 +67,7 @@ module.exports = {
if (maxAgeMatch && maxAgeMatch[1] > maxAge) {
if (interceptOpt.cacheImmutable !== false && !originalHeaders.cacheControl.value.includes('immutable')) {
maxAge = maxAgeMatch[1]
- }
- else {
+ } else {
const url = `${rOptions.method} ➜ ${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${req.url}`
res.setHeader('DS-Cache-Response-Interceptor', `skip: ${maxAgeMatch[1]} > ${maxAge}`)
log.info(`cache response intercept: skip: ${maxAgeMatch[1]} > ${maxAge}, url: ${url}`)
@@ -91,22 +87,19 @@ module.exports = {
// 替换cache-control
if (originalHeaders.cacheControl) {
proxyRes.rawHeaders[originalHeaders.cacheControl.valueIndex] = replaceHeaders.cacheControl
- }
- else {
+ } else {
res.setHeader('Cache-Control', replaceHeaders.cacheControl)
}
// 替换last-modified
if (originalHeaders.lastModified) {
proxyRes.rawHeaders[originalHeaders.lastModified.valueIndex] = replaceHeaders.lastModified
- }
- else {
+ } else {
res.setHeader('Last-Modified', replaceHeaders.lastModified)
}
// 替换expires
if (originalHeaders.expires) {
proxyRes.rawHeaders[originalHeaders.expires.valueIndex] = replaceHeaders.expires
- }
- else {
+ } else {
res.setHeader('Expires', replaceHeaders.expires)
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js b/packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js
index 2086018c52..7c7719ec24 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js
@@ -31,8 +31,7 @@ function replaceResponseHeaders (newHeaders, res, proxyRes) {
preHeaders[headerKey] = proxyRes.rawHeaders[i + 1] // 先保存原先响应头
if (newHeaderValue === REMOVE) { // 由于拦截配置中不允许配置null,会被删,所以配置一个 "[remove]",当作删除响应头的意思
proxyRes.rawHeaders[i + 1] = ''
- }
- else {
+ } else {
proxyRes.rawHeaders[i + 1] = newHeaderValue
}
}
diff --git a/packages/mitmproxy/src/lib/interceptor/impl/res/script.js b/packages/mitmproxy/src/lib/interceptor/impl/res/script.js
index 24c502a511..58e7581765 100644
--- a/packages/mitmproxy/src/lib/interceptor/impl/res/script.js
+++ b/packages/mitmproxy/src/lib/interceptor/impl/res/script.js
@@ -52,8 +52,7 @@ module.exports = {
if (key.includes('/')) {
scriptTag = getScriptByUrlOrPath(key) // 1.绝对地址或相对地址(注意:当目标站点限制跨域脚本时,可使用相对地址,再结合proxy拦截器进行代理,可规避掉限制跨域脚本问题。)
- }
- else {
+ } else {
const script = scripts[key]
if (script == null) {
continue
@@ -72,8 +71,7 @@ module.exports = {
// 插入油猴脚本浏览器扩展
if (typeof interceptOpt.tampermonkeyScript === 'string') {
tags = `\r\n\t${getScriptByUrlOrPath(interceptOpt.tampermonkeyScript)}${tags}`
- }
- else {
+ } else {
tags = `\r\n\t${getScript('tampermonkey', scripts.tampermonkey.script)}${tags}`
}
@@ -82,12 +80,10 @@ module.exports = {
return {
head: `${tags}\r\n`,
}
- }
- catch (err) {
+ } catch (err) {
try {
res.setHeader('DS-Script-Interceptor', 'error')
- }
- catch (e) {
+ } catch (e) {
// ignore
}
log.error('load monkey script error', err)
@@ -112,8 +108,7 @@ module.exports = {
if (typeof replaceScriptUrlFun === 'function') {
replaceScriptUrlFun(scriptKey)
}
- }
- else if (scriptUrl.indexOf('/') === 0) {
+ } else if (scriptUrl.indexOf('/') === 0) {
// 相对地址
scriptProxy[scriptUrl] = scriptUrl
}
@@ -129,8 +124,7 @@ module.exports = {
pathConfig.script[i] = scriptKey
})
}
- }
- else if (typeof pathConfig.script === 'string') {
+ } else if (typeof pathConfig.script === 'string') {
handleScriptUrl(pathConfig.script, 'script', (scriptKey) => {
pathConfig.script = scriptKey
})
@@ -180,8 +174,7 @@ module.exports = {
const obj = {}
obj[pathPattern] = hostnameConfig[pathPattern]
log.debug(`域名 '${hostnamePattern}' 拦截配置中,新增伪脚本地址的代理配置:`, JSON.stringify(obj, null, '\t'))
- }
- else {
+ } else {
// 相对地址:新增响应头Content-Type替换配置
if (hostnameConfig[scriptKey]) {
continue // 配置已经存在,按自定义配置优先
diff --git a/packages/mitmproxy/src/lib/monkey/index.js b/packages/mitmproxy/src/lib/monkey/index.js
index 40715a41d2..df00bd7056 100644
--- a/packages/mitmproxy/src/lib/monkey/index.js
+++ b/packages/mitmproxy/src/lib/monkey/index.js
@@ -12,8 +12,7 @@ function buildScript (sc, content, scriptName) {
let eventStr
if (runAt === 'document-end') {
eventStr = 'document.addEventListener("DOMContentLoaded"'
- }
- else {
+ } else {
eventStr = 'window.addEventListener("load"'
}
@@ -48,8 +47,7 @@ if (!((window.__ds_global__ || {}).GM_getValue || (() => true))("ds_enabled", tr
if (item.indexOf('.') > 0) {
grantStr += `${item} = (window.__ds_global__ || {})['${item}'];`
- }
- else {
+ } else {
grantStr += `const ${item} = (window.__ds_global__ || {})['${item}'] || (() => {});`
}
}
@@ -91,11 +89,9 @@ function loadScript (content, scriptName) {
const value = ret[2].trim()
if (key === 'grant') {
sc.grant.push(value)
- }
- else if (key === 'match') {
+ } else if (key === 'match') {
sc.match.push(value)
- }
- else {
+ } else {
sc[key] = value
}
}
diff --git a/packages/mitmproxy/src/lib/proxy/common/util.js b/packages/mitmproxy/src/lib/proxy/common/util.js
index 35a396397e..31e1cd14a5 100644
--- a/packages/mitmproxy/src/lib/proxy/common/util.js
+++ b/packages/mitmproxy/src/lib/proxy/common/util.js
@@ -83,8 +83,7 @@ util.parseHostnameAndPort = (host, defaultPort) => {
if (arr[1]) {
arr[1] = Number.parseInt(arr[1], 10)
}
- }
- else {
+ } else {
arr = host.split(':')
if (arr.length > 1) {
arr[1] = Number.parseInt(arr[1], 10)
@@ -93,8 +92,7 @@ util.parseHostnameAndPort = (host, defaultPort) => {
if (defaultPort > 0 && (arr.length === 1 || arr[1] === undefined)) {
arr[1] = defaultPort
- }
- else if (arr.length === 2 && arr[1] === undefined) {
+ } else if (arr.length === 2 && arr[1] === undefined) {
arr.pop()
}
@@ -112,12 +110,10 @@ util.getOptionsFromRequest = (req, ssl, externalProxy = null, serverSetting, com
if (externalProxy) {
if (typeof externalProxy === 'string') {
externalProxyUrl = externalProxy
- }
- else if (typeof externalProxy === 'function') {
+ } else if (typeof externalProxy === 'function') {
try {
externalProxyUrl = externalProxy(req, ssl)
- }
- catch (e) {
+ } catch (e) {
log.error('externalProxy error:', e)
}
}
@@ -137,12 +133,10 @@ util.getOptionsFromRequest = (req, ssl, externalProxy = null, serverSetting, com
// log.info(`get timeoutConfig '${hostname}':`, timeoutConfig)
agent = createAgent(protocol, timeoutConfig, serverSetting.verifySsl)
headers.connection = 'keep-alive'
- }
- else {
+ } else {
agent = false
}
- }
- else {
+ } else {
agent = util.getTunnelAgent(protocol === 'https:', externalProxyUrl)
}
@@ -172,8 +166,7 @@ util.getOptionsFromRequest = (req, ssl, externalProxy = null, serverSetting, com
// mark a socketId for Agent to bind socket for NTLM
if (req.socket.customSocketId) {
options.customSocketId = req.socket.customSocketId
- }
- else if (headers.authorization) {
+ } else if (headers.authorization) {
options.customSocketId = req.socket.customSocketId = socketId++
}
@@ -201,8 +194,7 @@ util.getTunnelAgent = (requestIsSSL, externalProxyUrl) => {
})
}
return httpsOverHttpAgent
- }
- else {
+ } else {
if (!httpsOverHttpsAgent) {
httpsOverHttpsAgent = tunnelAgent.httpsOverHttps({
proxy: {
@@ -213,8 +205,7 @@ util.getTunnelAgent = (requestIsSSL, externalProxyUrl) => {
}
return httpsOverHttpsAgent
}
- }
- else {
+ } else {
if (protocol === 'http:') {
// if (!httpOverHttpAgent) {
// httpOverHttpAgent = tunnelAgent.httpOverHttp({
@@ -225,8 +216,7 @@ util.getTunnelAgent = (requestIsSSL, externalProxyUrl) => {
// })
// }
return false
- }
- else {
+ } else {
if (!httpOverHttpsAgent) {
httpOverHttpsAgent = tunnelAgent.httpOverHttps({
proxy: {
diff --git a/packages/mitmproxy/src/lib/proxy/compatible/compatible.js b/packages/mitmproxy/src/lib/proxy/compatible/compatible.js
index a8dc4fa58b..e9ffba3bc8 100644
--- a/packages/mitmproxy/src/lib/proxy/compatible/compatible.js
+++ b/packages/mitmproxy/src/lib/proxy/compatible/compatible.js
@@ -58,8 +58,7 @@ function _loadFromFile (defaultConfig) {
if (!fs.existsSync(configPath)) {
config = defaultConfig
log.info(`本地未保存过 ${configPath} 文件,使用默认配置`)
- }
- else {
+ } else {
const file = fs.readFileSync(configPath)
log.info('读取 automaticCompatibleConfig.json 成功:', configPath)
const fileStr = file.toString()
@@ -80,8 +79,7 @@ function _saveConfigToFile () {
try {
fs.writeFileSync(filePath, jsonApi.stringify(config))
log.info('保存 automaticCompatibleConfig.json 成功:', filePath)
- }
- catch (e) {
+ } catch (e) {
log.error('保存 automaticCompatibleConfig.json 失败:', filePath, e)
}
}
@@ -109,8 +107,7 @@ module.exports = {
const connectCompatibleConfig = this.getConnectCompatibleConfig(hostname, port)
if (connectCompatibleConfig) {
connectCompatibleConfig.ssl = ssl
- }
- else {
+ } else {
config.connect[`${hostname}:${port}`] = { ssl }
}
@@ -142,8 +139,7 @@ module.exports = {
const requestCompatibleConfig = this.getRequestCompatibleConfig(rOptions.hostname, rOptions.port)
if (requestCompatibleConfig) {
requestCompatibleConfig.rejectUnauthorized = rejectUnauthorized
- }
- else {
+ } else {
config.request[`${rOptions.hostname}:${rOptions.port}`] = { rejectUnauthorized }
}
diff --git a/packages/mitmproxy/src/lib/proxy/middleware/InsertScriptMiddleware.js b/packages/mitmproxy/src/lib/proxy/middleware/InsertScriptMiddleware.js
index c7c7325d8a..d1791495f7 100644
--- a/packages/mitmproxy/src/lib/proxy/middleware/InsertScriptMiddleware.js
+++ b/packages/mitmproxy/src/lib/proxy/middleware/InsertScriptMiddleware.js
@@ -181,12 +181,10 @@ module.exports = {
}))
.pipe(codec.createCompressor()) // 编码
.pipe(res)
- }
- else {
+ } else {
log.error(`InsertScriptMiddleware.responseInterceptor(): 暂不支持编码方式 ${encoding}, 目前支持:`, httpUtil.supportedEncodingsStr())
}
- }
- else {
+ } else {
proxyRes
.pipe(through(function (chunk, enc, callback) {
chunkByteReplace(this, chunk, enc, callback, append)
diff --git a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js
index 3b1e236abd..5237ca359f 100644
--- a/packages/mitmproxy/src/lib/proxy/middleware/overwall.js
+++ b/packages/mitmproxy/src/lib/proxy/middleware/overwall.js
@@ -15,8 +15,7 @@ function matched (hostname, overWallTargetMap) {
const ret1 = matchUtil.matchHostname(overWallTargetMap, hostname, 'matched overwall')
if (ret1) {
return 'in config'
- }
- else if (ret1 === false || ret1 === 'false') {
+ } else if (ret1 === false || ret1 === 'false') {
log.debug(`域名 ${hostname} 的overwall配置为 false,跳过增强功能,即使它在 pac.txt 里`)
return null
}
@@ -29,8 +28,7 @@ function matched (hostname, overWallTargetMap) {
if (ret && ret.indexOf('PROXY ') === 0) {
log.info(`matchHostname: matched overwall: '${hostname}' -> '${ret}' in pac.txt`)
return 'in pac.txt'
- }
- else {
+ } else {
log.debug(`matchHostname: matched overwall: Not-Matched '${hostname}' -> '${ret}' in pac.txt`)
return null
}
@@ -51,8 +49,7 @@ function loadPacLastModifiedTime (pacTxt) {
if (matched && matched.length > 0) {
try {
return new Date(matched[0])
- }
- catch {
+ } catch {
return null
}
}
@@ -87,8 +84,7 @@ function savePacFile (pacTxt) {
fs.utimes(pacFilePath, lastModifiedTime, lastModifiedTime, (utimesErr) => {
if (utimesErr) {
log.error('修改 pac.txt 文件时间失败:', utimesErr)
- }
- else {
+ } else {
log.info(`'${pacFilePath}' 文件的修改时间已更新为其最近更新时间 '${formatDate(lastModifiedTime)}'`)
}
})
@@ -111,8 +107,7 @@ async function downloadPacAsync (pacConfig) {
if (body == null || body.length < 100) {
log.warn('下载远程 pac.txt 文件成功,但内容为空或内容太短,判断为无效的 pax.txt 文件:', remotePacFileUrl, ', body:', body)
return
- }
- else {
+ } else {
log.info('下载远程 pac.txt 文件成功:', remotePacFileUrl)
}
@@ -123,8 +118,7 @@ async function downloadPacAsync (pacConfig) {
pacTxt = Buffer.from(pacTxt, 'base64').toString('utf8')
// log.debug('解析 base64 后的 pax:', pacTxt)
}
- }
- catch {
+ } catch {
if (!pacTxt.includes('!---------------------EOF')) {
log.error(`远程 pac.txt 文件内容即不是base64格式,也不是要求的格式,url: ${remotePacFileUrl},body: ${body}`)
return
@@ -133,8 +127,7 @@ async function downloadPacAsync (pacConfig) {
// 保存到本地
savePacFile(pacTxt)
- }
- else {
+ } else {
log.error(`下载远程 pac.txt 文件失败: ${remotePacFileUrl}, response:`, response, ', body:', body)
}
})
@@ -183,8 +176,7 @@ function createOverwallMiddleware (overWallConfig) {
}
if (count.value == null) {
log.error('`count.value` is null, the count:', count)
- }
- else {
+ } else {
count.doCount(count.value)
proxyServer = count.value
context.requestCount = {
diff --git a/packages/mitmproxy/src/lib/proxy/middleware/source/pac.js b/packages/mitmproxy/src/lib/proxy/middleware/source/pac.js
index be6c752264..c0fae9df07 100644
--- a/packages/mitmproxy/src/lib/proxy/middleware/source/pac.js
+++ b/packages/mitmproxy/src/lib/proxy/middleware/source/pac.js
@@ -12,8 +12,7 @@ function createPacClient (pacFilePath) {
const filePath = path.resolve(location)
log.info('read pac path:', filePath)
return fs.readFileSync(location).toString()
- }
- catch (e) {
+ } catch (e) {
log.error('读取pac失败:', e)
return ''
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js
index ac040e5fe3..94534090b6 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createConnectHandler.js
@@ -45,8 +45,7 @@ module.exports = function createConnectHandler (sslConnectInterceptor, middlewar
}).catch((e) => {
log.error(`----- fakeServer getServerPromise error: ${hostname}:${port}, error:`, e)
})
- }
- else {
+ } else {
log.info(`不拦截请求,直连目标服务器: ${hostname}:${port}, headers:`, jsonApi.stringify2(req.headers))
connect(req, cltSocket, head, hostname, port, dnsConfig, true)
}
@@ -118,8 +117,7 @@ function connect (req, cltSocket, head, hostname, port, dnsConfig = null, isDire
const proxySocket = net.connect(options, () => {
if (!isDirect) {
log.info('Proxy connect start:', hostport)
- }
- else {
+ } else {
log.debug('Direct connect start:', hostport)
}
@@ -192,8 +190,7 @@ function connect (req, cltSocket, head, hostname, port, dnsConfig = null, isDire
}
return proxySocket
- }
- catch (e) {
+ } catch (e) {
log.error(`${isDirect ? '直连' : '代理连接'}错误: ${hostport}, error:`, e)
}
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createFakeServerCenter.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createFakeServerCenter.js
index 7bdf41cc53..f0b2a1401d 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createFakeServerCenter.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createFakeServerCenter.js
@@ -20,8 +20,7 @@ module.exports = function createFakeServerCenter ({
const caKeyPem = fs.readFileSync(caKeyPath)
caCert = forge.pki.certificateFromPem(caCertPem)
caKey = forge.pki.privateKeyFromPem(caKeyPem)
- }
- catch (e) {
+ } catch (e) {
log.error('Can not find `CA certificate` or `CA key`:', e)
process.exit(1)
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js
index 511956e2f6..a6e8fa0900 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js
@@ -23,11 +23,9 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
if (rOptions.headers.connection === 'close') {
req.socket.setKeepAlive(false)
- }
- else if (rOptions.customSocketId != null) { // for NTLM
+ } else if (rOptions.customSocketId != null) { // for NTLM
req.socket.setKeepAlive(true, 60 * 60 * 1000)
- }
- else {
+ } else {
req.socket.setKeepAlive(true, 30000)
}
const context = {
@@ -73,12 +71,10 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
}
}
next()
- }
- else {
+ } else {
next()
}
- }
- catch (e) {
+ } catch (e) {
reject(e)
}
})
@@ -129,12 +125,10 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
rOptions.lookup = dnsLookup.createLookupFunc(res, dns, 'request url', url, isDnsIntercept)
log.debug(`域名 ${rOptions.hostname} DNS: ${dns.name}`)
res.setHeader('DS-DNS', dns.name)
- }
- else {
+ } else {
log.info(`域名 ${rOptions.hostname} 在DNS中未配置`)
}
- }
- else {
+ } else {
log.info(`域名 ${rOptions.hostname} DNS配置不存在`)
}
@@ -163,8 +157,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
const cost = new Date() - start
if (rOptions.protocol === 'https:') {
log.info(`代理请求返回: 【${proxyRes.statusCode}】${url}, cost: ${cost} ms`)
- }
- else {
+ } else {
log.info(`请求返回: 【${proxyRes.statusCode}】${url}, cost: ${cost} ms`)
}
// console.log('request:', proxyReq, proxyReq.socket)
@@ -291,8 +284,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
if (append.body) {
body += append.body
}
- }
- else if (append === false) {
+ } else if (append === false) {
break // 返回false表示终止拦截器,跳出循环
}
}
@@ -300,12 +292,10 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
head,
body,
})
- }
- else {
+ } else {
next()
}
- }
- catch (e) {
+ } catch (e) {
reject(e)
}
})
@@ -341,15 +331,13 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
目标网站请求错误:【${e.code}】 ${e.message}
目标地址:${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}`,
)
- }
- catch (e) {
+ } catch (e) {
// do nothing
}
try {
res.end()
- }
- catch (e) {
+ } catch (e) {
// do nothing
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js
index 006b18991a..fe5edacadb 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js
@@ -17,8 +17,7 @@ module.exports = {
}
callback(null, aliveIpObj.host, 4)
return
- }
- else {
+ } else {
log.info(`----- ${action}: ${hostname}, no alive ip${target}, tester: { "ready": ${tester.ready}, "backupList": ${JSON.stringify(tester.backupList)} }`)
}
}
@@ -50,13 +49,11 @@ module.exports = {
}
callback(null, ip, 4)
return
- }
- else {
+ } else {
// 使用默认dns
log.info(`----- ${action}: ${hostname}, use hostname by default DNS: ${hostname}, skip test failed ip from dns '${dns.name}: ${ip}'${target}, options:`, options)
}
- }
- else {
+ } else {
// 使用默认dns
log.info(`----- ${action}: ${hostname}, use hostname by default DNS: ${hostname}${target}, options:`, options, ', dns:', dns)
}
diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/index.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/index.js
index acf3a7e988..9c272fb3da 100644
--- a/packages/mitmproxy/src/lib/proxy/mitmproxy/index.js
+++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/index.js
@@ -104,8 +104,7 @@ module.exports = {
server.on('upgrade', (req, cltSocket, head) => {
if (printDebugLog) {
log.debug(`【server upgrade, ssl: ${ssl}】\r\n----- req -----\r\n`, req)
- }
- else {
+ } else {
log.info(`【server upgrade, ssl: ${ssl}】`, req.url)
}
upgradeHandler(req, cltSocket, head, ssl)
diff --git a/packages/mitmproxy/src/lib/proxy/tls/CertAndKeyContainer.js b/packages/mitmproxy/src/lib/proxy/tls/CertAndKeyContainer.js
index 2a1131add7..0b2542a470 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/CertAndKeyContainer.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/CertAndKeyContainer.js
@@ -73,8 +73,7 @@ module.exports = class CertAndKeyContainer {
if (fast) {
certObj = tlsUtils.createFakeCertificateByDomain(this.caKey, this.caCert, hostname)
_resolve(certObj)
- }
- else {
+ } else {
// 这个太慢了
// const preReq = https.request({
// port: port,
diff --git a/packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js b/packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js
index 2b781cc5eb..acec84c7b6 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js
@@ -38,8 +38,7 @@ module.exports = class FakeServersCenter {
try {
log.info('超过最大服务数量,删除旧服务。delServerObj:', delServerObj)
delServerObj.serverObj.server.close()
- }
- catch (e) {
+ } catch (e) {
log.error('`delServerObj.serverObj.server.close()` error:', e)
}
}
@@ -50,8 +49,7 @@ module.exports = class FakeServersCenter {
getServerPromise (hostname, port, ssl, manualCompatibleConfig) {
if (port === 443 || port === 80) {
ssl = port === 443
- }
- else if (ssl) {
+ } else if (ssl) {
// 自动兼容程序:1
const compatibleConfig = compatible.getConnectCompatibleConfig(hostname, port, manualCompatibleConfig)
if (compatibleConfig && compatibleConfig.ssl != null) {
@@ -107,8 +105,7 @@ module.exports = class FakeServersCenter {
})()
},
})
- }
- else {
+ } else {
fakeServer = new http.Server()
}
const serverObj = {
@@ -149,8 +146,7 @@ module.exports = class FakeServersCenter {
fakeServer.on('upgrade', (req, socket, head) => {
if (printDebugLog) {
log.debug(`【fakeServer upgrade - ${hostname}:${port}】\r\n----- req -----\r\n`, req, '\r\n----- socket -----\r\n', socket, '\r\n----- head -----\r\n', head)
- }
- else {
+ } else {
log.info(`【fakeServer upgrade - ${hostname}:${port}】`, req.url)
}
this.upgradeHandler(req, socket, head, ssl)
@@ -169,8 +165,7 @@ module.exports = class FakeServersCenter {
if (ssl === true && err.code.indexOf('ERR_SSL_') === 0) {
compatible.setConnectSsl(hostname, port, false)
log.error(`自动兼容程序:SSL异常,现设置为禁用ssl: ${hostname}:${port}, ssl = false`)
- }
- else if (ssl === false && err.code === 'HPE_INVALID_METHOD') {
+ } else if (ssl === false && err.code === 'HPE_INVALID_METHOD') {
compatible.setConnectSsl(hostname, port, true)
log.error(`自动兼容程序:${err.code},现设置为启用ssl: ${hostname}:${port}, ssl = true`)
}
diff --git a/packages/mitmproxy/src/lib/proxy/tls/sniUtil.js b/packages/mitmproxy/src/lib/proxy/tls/sniUtil.js
index 9669f5fa0c..c44657e83b 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/sniUtil.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/sniUtil.js
@@ -172,13 +172,11 @@ module.exports = function extractSNI (data) {
end: n + nameLength,
length: nameLength,
}
- }
- else {
+ } else {
n += nameLength
}
}
- }
- else { // ExtensionType was something we are not interested in
+ } else { // ExtensionType was something we are not interested in
pos += extensionSize
}
}
diff --git a/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js b/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
index b545cad276..d2efe3ed87 100644
--- a/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
+++ b/packages/mitmproxy/src/lib/proxy/tls/tlsUtils.js
@@ -244,8 +244,7 @@ utils.initCA = function ({ caCertPath, caKeyPath }) {
caKeyPath,
create: false,
}
- }
- catch (e) {
+ } catch (e) {
const caObj = utils.createCA(config.caName)
const caCert = caObj.cert
diff --git a/packages/mitmproxy/src/lib/speed/SpeedTester.js b/packages/mitmproxy/src/lib/speed/SpeedTester.js
index dba881cf1e..a5f915eadd 100644
--- a/packages/mitmproxy/src/lib/speed/SpeedTester.js
+++ b/packages/mitmproxy/src/lib/speed/SpeedTester.js
@@ -124,8 +124,7 @@ class SpeedTester {
}
return a.time - b.time
})
- }
- catch (e) {
+ } catch (e) {
if (e.message !== 'timeout') {
log.warn('[speed] test error: ', this.hostname, `➜ ${item.host}:${item.port} from DNS '${item.dns}'`, ', errorMsg:', e.message)
}
diff --git a/packages/mitmproxy/src/lib/speed/index.js b/packages/mitmproxy/src/lib/speed/index.js
index 55b92db239..86b7ba0cca 100644
--- a/packages/mitmproxy/src/lib/speed/index.js
+++ b/packages/mitmproxy/src/lib/speed/index.js
@@ -60,8 +60,7 @@ function reSpeedTest () {
function action (event) {
if (event.key === 'reTest') {
reSpeedTest()
- }
- else if (event.key === 'getList') {
+ } else if (event.key === 'getList') {
process.send({ type: 'speed', event: { key: 'getList', value: getAllSpeedTester() } })
}
}
diff --git a/packages/mitmproxy/src/options.js b/packages/mitmproxy/src/options.js
index a880530d3f..82bebc5fc8 100644
--- a/packages/mitmproxy/src/options.js
+++ b/packages/mitmproxy/src/options.js
@@ -24,8 +24,7 @@ function getExclusionArray (exclusions) {
if (exclusions.length > 0) {
ret = exclusions
}
- }
- else if (lodash.isObject(exclusions)) {
+ } else if (lodash.isObject(exclusions)) {
ret = []
for (const exclusion in exclusions) {
ret.push(exclusion)
@@ -158,8 +157,7 @@ module.exports = (serverConfig) => {
}
}
}
- }
- catch (e) {
+ } catch (e) {
log.error(`判断拦截器是否排除当前path时出现异常, path: ${rOptions.path}, interceptOpt:`, interceptOpt, ', error:', e)
}
if (isExcluded) {
@@ -191,8 +189,7 @@ module.exports = (serverConfig) => {
interceptor.requestIntercept = (context, req, res, ssl, next) => {
return impl.requestIntercept(context, interceptOpt, req, res, ssl, next, matched)
}
- }
- else if (impl.responseIntercept) {
+ } else if (impl.responseIntercept) {
// res拦截器
interceptor.responseIntercept = (context, req, res, proxyReq, proxyRes, ssl, next) => {
return impl.responseIntercept(context, interceptOpt, req, res, proxyReq, proxyRes, ssl, next, matched)
@@ -202,8 +199,7 @@ module.exports = (serverConfig) => {
// log.info(`${action} interceptor: ${impl.name}, hostname: ${rOptions.hostname}, regexp: ${regexp}`)
if (action === 'add') {
matchIntercepts.push(interceptor)
- }
- else {
+ } else {
matchIntercepts[matchedInterceptOpt.index] = interceptor
}
matchInterceptsOpts[impl.name] = {
@@ -214,7 +210,9 @@ module.exports = (serverConfig) => {
}
}
- matchIntercepts.sort((a, b) => { return a.priority - b.priority })
+ matchIntercepts.sort((a, b) => {
+ return a.priority - b.priority
+ })
// for (const interceptor of matchIntercepts) {
// log.info('interceptor:', interceptor.name, 'priority:', interceptor.priority)
// }
diff --git a/packages/mitmproxy/src/utils/util.match.js b/packages/mitmproxy/src/utils/util.match.js
index 8668e6b1d0..4404ba0b6d 100644
--- a/packages/mitmproxy/src/utils/util.match.js
+++ b/packages/mitmproxy/src/utils/util.match.js
@@ -12,8 +12,7 @@ function isMatched (url, regexp) {
urlRegexp = `.${regexp}`
}
return url.match(urlRegexp)
- }
- catch (e) {
+ } catch (e) {
log.error('匹配串有问题:', regexp)
return null
}
@@ -40,8 +39,7 @@ function domainMapRegexply (hostMap) {
if (domain.indexOf('*') === 0 && domain.lastIndexOf('*') === 0) {
origin[domain] = value
}
- }
- else {
+ } else {
origin[domain] = value
}
})
@@ -170,8 +168,7 @@ function matchHostnameAll (hostMap, hostname, action) {
deleteNullItems(values)
log.info(`matchHostname-all: ${action}: '${hostname}':`, JSON.stringify(values))
return values
- }
- else {
+ } else {
log.debug(`matchHostname-all: ${action}: '${hostname}' Not-Matched`)
}
}
diff --git a/test/test.js b/test/test.js
index 5ea6546bf1..9b47d719a2 100644
--- a/test/test.js
+++ b/test/test.js
@@ -59,8 +59,7 @@ function testRequest () {
request('https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', (error, response, body) => {
if (error) {
console.error(error)
- }
- else {
+ } else {
console.log(body)
}
})
From ec473ce0f9688da0533643b1c6f57be6048d0073 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com>
Date: Mon, 18 Nov 2024 16:33:24 +0800
Subject: [PATCH 14/20] fix Style
---
README.md | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md
index 4e08a185fb..a07e636b55 100644
--- a/README.md
+++ b/README.md
@@ -151,21 +151,18 @@
#### 1)git clone 加速
--方式1:快捷复制:
+- 方式1:快捷复制:
+ > 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接
-> 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接
-
--方式2:
-
-> 1. 使用方式:用实际的名称替换 `{}`的内容,即可加速clone
-
-> 2.clone 出来的 remote "origin" 为fastgit的地址,需要手动改回来
-> 3. 你也可以直接使用他们的clone加速工具 [fgit-go](https://github.com/FastGitORG/fgit-go)
+- 方式2:
+ > 1. 使用方式:用实际的名称替换 `{}` 的内容,即可加速clone
+ > 2. clone 出来的 remote "origin" 为fastgit的地址,需要手动改回来
+ > 3. 你也可以直接使用他们的clone加速工具 [fgit-go](https://github.com/FastGitORG/fgit-go)
#### 2)`github.com` 的镜像网站(注意:部分镜像网站不能登录)
-> 1. [hub.fastgit.org](https://hub.fastgit.org/) (2024/11/18:这个好像失效了?)
-> 2. [github.com.cnpmjs.org](https://github.com.cnpmjs.org/) 这个很容易超限(2024/11/18:这个好像失效了?)
+> 1. [hub.fastgit.org](https://hub.fastgit.org/) (2024/11/18:这个好像失效了?)
+> 2. [github.com.cnpmjs.org](https://github.com.cnpmjs.org/) 这个很容易超限(2024/11/18:这个好像失效了?)
> 3. [dgithub.xyz](https://dgithub.xyz/)
## 五、api
@@ -318,8 +315,9 @@ DevSidecar Warning: Error: www.github.com:443, 代理请求超时
当应用意外关闭时,可能会因为没有将系统代理恢复,从而导致完全无法上网。
对于此问题有如下几种解决方案可供选择:
-1.重新打开应用即可(右键应用托盘图标可完全退出,将会正常关闭系统代理设置)
-2.如果应用被卸载了,此时需要[手动关闭系统代理设置](./doc/recover.md)
+
+1. 重新打开应用即可(右键应用托盘图标可完全退出,将会正常关闭系统代理设置)
+2. 如果应用被卸载了,此时需要[手动关闭系统代理设置](./doc/recover.md)
3. 如果你是因为开着ds的情况下重启电脑导致无法上网,你可以设置ds为开机自启
### 6.8、卸载应用后上不了网,git请求不了
From c0fcd3389ecf2bb178d5710e04236a7efee37855 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 18:07:05 +0800
Subject: [PATCH 15/20] fix: path
---
packages/cli/cli.js | 2 +-
packages/cli/src/index.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/cli/cli.js b/packages/cli/cli.js
index 2b8767cafa..8fa39e70ba 100755
--- a/packages/cli/cli.js
+++ b/packages/cli/cli.js
@@ -1,3 +1,3 @@
#!/usr/bin/env node
-require('../src')
+require('./src')
diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js
index 4dce5c8ada..92f42940d6 100644
--- a/packages/cli/src/index.js
+++ b/packages/cli/src/index.js
@@ -3,7 +3,7 @@ const DevSidecar = require('@docmirror/dev-sidecar')
const jsonApi = require('@docmirror/mitmproxy/src/json')
// 启动服务
-const mitmproxyPath = './src/mitmproxy'
+const mitmproxyPath = './mitmproxy'
async function startup () {
const banner = fs.readFileSync('./src/banner.txt')
console.log(banner.toString())
From 6f6d8f0842b4fd5f8e246754d4e5705032574eb0 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Mon, 18 Nov 2024 18:34:44 +0800
Subject: [PATCH 16/20] doc: update
---
README.md | 50 ++++++++++++++++++++------------------------------
1 file changed, 20 insertions(+), 30 deletions(-)
diff --git a/README.md b/README.md
index a07e636b55..5a9cdffdc8 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
开发者边车,命名取自service-mesh的service-sidecar,意为为开发者打辅助的边车工具(以下简称ds)
通过本地代理的方式将https请求代理到一些国内的加速通道上
-
+````
> Gitee上的同步项目已被封禁,此项目将不再更新与维护 【狗头保命】
>
@@ -12,7 +12,7 @@
## 打个广告
->
+> [https://github.com/certd/certd](https://github.com/certd/certd)
> 我的开源证书管理工具项目,全自动申请和部署证书,有需求的可以去试试,帮忙点个star
## 重要提醒
@@ -22,7 +22,7 @@
> 注意:由于electron无法监听windows的关机事件,开着ds情况下直接重启电脑,会导致无法上网,你可以手动启动ds即可恢复网络,你也可以将ds设置为开机自启。
>
> 关于此问题的更多讨论请前往:
->
+> [https://github.com/docmirror/dev-sidecar/issues/109](https://github.com/docmirror/dev-sidecar/issues/109)
> ------------------------------重要提醒2---------------------------------
>
@@ -54,12 +54,12 @@
- 解决git push 偶尔失败需要输入账号密码的问题(fatal: TaskCanceledException encountered / fatal: HttpRequestException encountered)
- raw/blame加速
-> 以上部分功能通过`X.I.U`的油猴脚本实现, 以下是仓库和脚本下载链接,大家可以去支持一下。
+> 以上部分功能通过 `X.I.U`的油猴脚本实现, 以下是仓库和脚本下载链接,大家可以去支持一下。
>
-> -
-> -
+> - [https://github.com/XIU2/UserScript](https://github.com/XIU2/UserScript)
+> - [https://greasyfork.org/scripts/412245](https://greasyfork.org/scripts/412245)
>
-> 由于此脚本在ds中是打包在本地的,更新会不及时,你可以直接通过浏览器安装油猴插件使用此脚本,从而获得最新更新(ds本地的可以通过`加速服务->基本设置->启用脚本`进行关闭)。
+> 由于此脚本在ds中是打包在本地的,更新会不及时,你可以直接通过浏览器安装油猴插件使用此脚本,从而获得最新更新(ds本地的可以通过 `加速服务->基本设置->启用脚本`进行关闭)。
### 1.4、 Stack Overflow 加速
@@ -152,12 +152,14 @@
#### 1)git clone 加速
- 方式1:快捷复制:
- > 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接
+
+ > 开启脚本支持,然后在复制clone链接下方,即可复制到加速链接
- 方式2:
- > 1. 使用方式:用实际的名称替换 `{}` 的内容,即可加速clone
- > 2. clone 出来的 remote "origin" 为fastgit的地址,需要手动改回来
- > 3. 你也可以直接使用他们的clone加速工具 [fgit-go](https://github.com/FastGitORG/fgit-go)
+
+ > 1. 使用方式:用实际的名称替换 `{}` 的内容,即可加速clone [https://hub.fastgit.org/{username}/{reponame}.git](https://hub.fastgit.org/%7Busername%7D/%7Breponame%7D.git)
+ > 2. clone 出来的 remote "origin" 为fastgit的地址,需要手动改回来
+ > 3. 你也可以直接使用他们的clone加速工具 [fgit-go](https://github.com/FastGitORG/fgit-go)
#### 2)`github.com` 的镜像网站(注意:部分镜像网站不能登录)
@@ -258,16 +260,11 @@ networksetup -setwebproxy 'WiFi' 127.0.0.1 31181
1. 本应用仅支持https加速
请务必确认你访问的地址是https开头的
- 比如:
-
+ 比如: [https://github.com/](https://github.com/)
2. 检查浏览器是否装了什么插件,与ds有冲突
-
3. 检查是否安装了其他代理软件,与ds有冲突
-
4. 请确认浏览器的代理设置为使用IE代理/或者使用系统代理状态
-
5. 可以尝试换个浏览器试试
-
6. 请确认网络代理设置处于勾选状态
正常情况下ds在“系统代理”开关打开时,会自动设置系统代理。
@@ -284,7 +281,7 @@ networksetup -setwebproxy 'WiFi' 127.0.0.1 31181
- 1. 火狐浏览器->选项->隐私与安全->证书->查看证书
- 2. 证书颁发机构->导入
- - 3. 选择证书文件`C:\Users(用户)\Administrator(你的账号)\.dev-sidecar\dev-sidecar.ca.crt`(Mac或linux为`~/.dev-sidecar`目录)
+ - 3. 选择证书文件`C:\Users(用户)\Administrator(你的账号)\.dev-sidecar\dev-sidecar.ca.crt`(Mac或linux为 `~/.dev-sidecar`目录)
- 4. 勾选信任由此证书颁发机构来标识网站,确定即可
### 6.4、打开github显示连接超时
@@ -350,18 +347,14 @@ npm config delete https-proxy
#### 1)安装 `nodejs`
-推荐安装 nodejs `16.x.x` 的版本,其他版本未做测试
+推荐安装 nodejs `22.x.x` 的版本,其他版本未做测试
-#### 2)安装 `lerna`
+#### 2)安装 `pnpm`
运行如下命令即可安装所需依赖:
-> 注:lerna指定为6.x版本,更高版本会导致打包失败(不兼容导致)
-
```shell
-npm install -g cnpm --registry=https://registry.npmmirror.com
-
-cnpm install -g lerna@6
+npm install -g pnpm --registry=https://registry.npmmirror.com
```
@@ -375,11 +368,8 @@ git clone https://github.com/docmirror/dev-sidecar
cd dev-sidecar
-# 注意不要使用 `npm install` 来安装依赖,因为 `lerna bootstrap` 会自动安装依赖
-lerna bootstrap
-# 如果 `lerna bootstrap` 有报错,可以尝试执行如下两行命令,用yarn替换掉npm:
-#cnpm install -g yarn
-#lerna bootstrap --npm-client=yarn
+# 注意不要使用 `npm install` 来安装依赖,因为 `pnpm` 会自动安装依赖
+pnpm install
# 运行DevSidecar
cd packages/gui
From 9ef07caf233717b2d21ce164c55717437dda860a Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Tue, 19 Nov 2024 00:18:57 +0800
Subject: [PATCH 17/20] fix: cli package path
---
packages/cli/src/mitmproxy.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/cli/src/mitmproxy.js b/packages/cli/src/mitmproxy.js
index a86035d063..f02a1df7db 100644
--- a/packages/cli/src/mitmproxy.js
+++ b/packages/cli/src/mitmproxy.js
@@ -2,7 +2,7 @@ const fs = require('node:fs')
const path = require('node:path')
const server = require('@docmirror/mitmproxy')
const jsonApi = require('@docmirror/mitmproxy/src/json')
-const log = require('../src/utils/util.log')
+const log = require('@docmirror/mitmproxy/src/utils/util.log')
const home = process.env.USER_HOME || process.env.HOME || 'C:/Users/Administrator/'
From 273af787c14f8160543d5efce5b37a22f1cbc894 Mon Sep 17 00:00:00 2001
From: starknt <1431880400@qq.com>
Date: Tue, 19 Nov 2024 00:26:07 +0800
Subject: [PATCH 18/20] fix: lru-cache err
---
packages/mitmproxy/src/lib/choice/index.js | 3 +++
packages/mitmproxy/src/lib/dns/base.js | 3 +++
2 files changed, 6 insertions(+)
diff --git a/packages/mitmproxy/src/lib/choice/index.js b/packages/mitmproxy/src/lib/choice/index.js
index 964c2c6ff5..734fc946c0 100644
--- a/packages/mitmproxy/src/lib/choice/index.js
+++ b/packages/mitmproxy/src/lib/choice/index.js
@@ -7,6 +7,9 @@ class ChoiceCache {
constructor () {
this.cache = new LRUCache({
maxSize: cacheSize,
+ sizeCalculation: () => {
+ return 1
+ },
})
}
diff --git a/packages/mitmproxy/src/lib/dns/base.js b/packages/mitmproxy/src/lib/dns/base.js
index cc40863640..d2dcf48e8b 100644
--- a/packages/mitmproxy/src/lib/dns/base.js
+++ b/packages/mitmproxy/src/lib/dns/base.js
@@ -25,6 +25,9 @@ module.exports = class BaseDNS {
constructor () {
this.cache = new LRUCache({
maxSize: cacheSize,
+ sizeCalculation: () => {
+ return 1
+ },
})
}
From 468eb62137d8852acfa5876b97f3a9c76d31b515 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com>
Date: Tue, 19 Nov 2024 01:48:35 +0800
Subject: [PATCH 19/20] fix Style
---
README.md | 8 ++++----
packages/gui/src/background.js | 2 +-
packages/gui/src/bridge/update/front.js | 1 -
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 29733bcb4b..39170af889 100644
--- a/README.md
+++ b/README.md
@@ -279,10 +279,10 @@ networksetup -setwebproxy 'WiFi' 127.0.0.1 31181
#### 3)火狐浏览器:火狐浏览器不走系统的根证书,需要在选项中添加根证书
- - 1. 火狐浏览器->选项->隐私与安全->证书->查看证书
- - 2. 证书颁发机构->导入
- - 3. 选择证书文件 `C:\Users(用户)\Administrator(你的账号)\.dev-sidecar\dev-sidecar.ca.crt`(Mac或linux为 `~/.dev-sidecar` 目录)
- - 4. 勾选信任由此证书颁发机构来标识网站,确定即可
+1. 火狐浏览器->选项->隐私与安全->证书->查看证书
+2. 证书颁发机构->导入
+3. 选择证书文件 `C:\Users(用户)\Administrator(你的账号)\.dev-sidecar\dev-sidecar.ca.crt`(Mac或linux为 `~/.dev-sidecar` 目录)
+4. 勾选信任由此证书颁发机构来标识网站,确定即可
### 6.4、打开github显示连接超时
diff --git a/packages/gui/src/background.js b/packages/gui/src/background.js
index bbd30a336b..00af78b0d5 100644
--- a/packages/gui/src/background.js
+++ b/packages/gui/src/background.js
@@ -372,7 +372,7 @@ if (app.getLoginItemSettings().wasOpenedAsHidden) {
startHideWindow = false
}
}
-log.info('start hide window:', startHideWindow, ', app.getLoginItemSettings() = ', jsonApi.stringify2(app.getLoginItemSettings()))
+log.info('startHideWindow = ', startHideWindow, ', app.getLoginItemSettings() = ', jsonApi.stringify2(app.getLoginItemSettings()))
// 禁止双开
const isFirstInstance = app.requestSingleInstanceLock()
diff --git a/packages/gui/src/bridge/update/front.js b/packages/gui/src/bridge/update/front.js
index 7e486b26de..51a0436f1e 100644
--- a/packages/gui/src/bridge/update/front.js
+++ b/packages/gui/src/bridge/update/front.js
@@ -85,7 +85,6 @@ function install (app, api) {
From 808568167522c1477d60d08bd11781fe19419a44 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com>
Date: Tue, 19 Nov 2024 01:52:39 +0800
Subject: [PATCH 20/20] revert
---
packages/cli/src/index.js | 4 ++--
packages/gui/public/index.html | 2 +-
packages/gui/src/view/pages/setting.vue | 2 +-
.../mitmproxy/src/lib/interceptor/index.js | 24 +++++++------------
.../impl/res/responseReplaceTest.js | 17 +++++--------
5 files changed, 19 insertions(+), 30 deletions(-)
diff --git a/packages/cli/src/index.js b/packages/cli/src/index.js
index 92f42940d6..ac7a2699f3 100644
--- a/packages/cli/src/index.js
+++ b/packages/cli/src/index.js
@@ -5,10 +5,10 @@ const jsonApi = require('@docmirror/mitmproxy/src/json')
// 启动服务
const mitmproxyPath = './mitmproxy'
async function startup () {
- const banner = fs.readFileSync('./src/banner.txt')
+ const banner = fs.readFileSync('./banner.txt')
console.log(banner.toString())
- const configPath = './src/user_config.json5'
+ const configPath = './user_config.json5'
if (fs.existsSync(configPath)) {
const file = fs.readFileSync(configPath)
const userConfig = jsonApi.parse(file.toString())
diff --git a/packages/gui/public/index.html b/packages/gui/public/index.html
index dceebc70b4..0e66115d5e 100644
--- a/packages/gui/public/index.html
+++ b/packages/gui/public/index.html
@@ -1,4 +1,4 @@
-
+
diff --git a/packages/gui/src/view/pages/setting.vue b/packages/gui/src/view/pages/setting.vue
index 940e539c74..607c0f90ed 100644
--- a/packages/gui/src/view/pages/setting.vue
+++ b/packages/gui/src/view/pages/setting.vue
@@ -264,7 +264,7 @@ export default {
this.$confirm({
title: '确定要恢复出厂设置吗?',
width: 610,
- content: h => (
+ content: (h) => (
diff --git a/packages/mitmproxy/src/lib/interceptor/index.js b/packages/mitmproxy/src/lib/interceptor/index.js
index be7cbc9c3c..a37b6f560a 100644
--- a/packages/mitmproxy/src/lib/interceptor/index.js
+++ b/packages/mitmproxy/src/lib/interceptor/index.js
@@ -1,17 +1,17 @@
-const abort = require('./impl/req/abort')
-
-const baiduOcr = require('./impl/req/baiduOcr')
-const cacheReq = require('./impl/req/cacheReq')
// request interceptor impls
const OPTIONS = require('./impl/req/OPTIONS.js')
-const proxy = require('./impl/req/proxy')
+const success = require('./impl/req/success')
const redirect = require('./impl/req/redirect')
+const abort = require('./impl/req/abort')
+const cacheReq = require('./impl/req/cacheReq')
const requestReplace = require('./impl/req/requestReplace')
+
+const proxy = require('./impl/req/proxy')
const sni = require('./impl/req/sni')
-const success = require('./impl/req/success')
+const baiduOcr = require('./impl/req/baiduOcr')
// response interceptor impls
const OPTIONSHeaders = require('./impl/res/AfterOPTIONSHeaders')
@@ -23,18 +23,12 @@ const script = require('./impl/res/script')
module.exports = [
// request interceptor impls
OPTIONS,
- success,
- redirect,
- abort,
- cacheReq,
+ success, redirect, abort, cacheReq,
requestReplace,
- proxy,
- sni,
+ proxy, sni,
baiduOcr,
// response interceptor impls
- OPTIONSHeaders,
- cacheRes,
- responseReplace,
+ OPTIONSHeaders, cacheRes, responseReplace,
script,
]
diff --git a/packages/mitmproxy/test/lib/interceptor/impl/res/responseReplaceTest.js b/packages/mitmproxy/test/lib/interceptor/impl/res/responseReplaceTest.js
index 050fc37db9..00ff519773 100644
--- a/packages/mitmproxy/test/lib/interceptor/impl/res/responseReplaceTest.js
+++ b/packages/mitmproxy/test/lib/interceptor/impl/res/responseReplaceTest.js
@@ -9,17 +9,12 @@ const res = {
const proxyRes = {
rawHeaders: [
- 'Content-Type',
- 'application/json; charset=utf-8',
- 'Content-Length',
- '2',
- 'ETag',
- 'W/"2"',
- 'Date',
- 'Thu, 01 Jan 1970 00:00:00 GMT',
- 'Connection',
- 'keep-alive',
- ],
+ 'Content-Type', 'application/json; charset=utf-8',
+ 'Content-Length', '2',
+ 'ETag', 'W/"2"',
+ 'Date', 'Thu, 01 Jan 1970 00:00:00 GMT',
+ 'Connection', 'keep-alive'
+ ]
}
const newHeaders = {
|
---|
|
---|