diff --git a/packages/core/src/modules/plugin/git/config.js b/packages/core/src/modules/plugin/git/config.js new file mode 100644 index 0000000..d70d80a --- /dev/null +++ b/packages/core/src/modules/plugin/git/config.js @@ -0,0 +1,7 @@ +module.exports = { + name: 'Git代理', + enabled: false, + setting: { + sslVerify: false + } +} diff --git a/packages/core/src/modules/plugin/git/index.js b/packages/core/src/modules/plugin/git/index.js new file mode 100644 index 0000000..434be01 --- /dev/null +++ b/packages/core/src/modules/plugin/git/index.js @@ -0,0 +1,65 @@ +const pluginConfig = require('./config') +const Plugin = function (context) { + const { config, shell, event, log } = context + const pluginApi = { + async start () { + const ip = '127.0.0.1' + const port = config.get().server.port + await pluginApi.setProxy(ip, port) + return { ip, port } + }, + + async close () { + return pluginApi.unsetProxy() + }, + + async restart () { + await pluginApi.close() + await pluginApi.start() + }, + + async save (newConfig) { + + }, + + async setProxy (ip, port) { + const cmds = [ + `git config --global http.proxy http://${ip}:${port}`, + `git config --global https.proxy http://${ip}:${port}` + ] + if (pluginConfig.setting.sslVerify === false) { + cmds.push('git config http.sslVerify "false"') + } + + const ret = await shell.exec(cmds, { type: 'cmd' }) + event.fire('status', { key: 'plugin.git.enabled', value: true }) + log.info('开启【Git】代理成功') + + return ret + }, + + async unsetProxy () { + const cmds = [ + 'git config --global --unset https.proxy', + 'git config --global --unset http.proxy' + ] + if (pluginConfig.setting.sslVerify === false) { + cmds.push('git config --unset http.sslVerify ') + } + const ret = await shell.exec(cmds, { type: 'cmd' }) + event.fire('status', { key: 'plugin.git.enabled', value: false }) + log.info('关闭【Git】代理成功') + return ret + } + } + return pluginApi +} + +module.exports = { + key: 'git', + config: pluginConfig, + status: { + enabled: false + }, + plugin: Plugin +} diff --git a/packages/core/src/modules/plugin/index.js b/packages/core/src/modules/plugin/index.js index 91ef4b1..06fcf96 100644 --- a/packages/core/src/modules/plugin/index.js +++ b/packages/core/src/modules/plugin/index.js @@ -1,5 +1,7 @@ const node = require('./node') +const git = require('./git') const overwall = require('./overwall') + module.exports = { - node, overwall + node, git, overwall } diff --git a/packages/gui/src/view/pages/plugin/git.vue b/packages/gui/src/view/pages/plugin/git.vue new file mode 100644 index 0000000..8e28b57 --- /dev/null +++ b/packages/gui/src/view/pages/plugin/git.vue @@ -0,0 +1,61 @@ + + + diff --git a/packages/gui/src/view/pages/plugin/node.vue b/packages/gui/src/view/pages/plugin/node.vue index 800650a..5c8e17f 100644 --- a/packages/gui/src/view/pages/plugin/node.vue +++ b/packages/gui/src/view/pages/plugin/node.vue @@ -19,7 +19,7 @@ 当前未启动 - + 关闭strict-ssl diff --git a/packages/gui/src/view/router/index.js b/packages/gui/src/view/router/index.js index f7bdf2f..8e25051 100644 --- a/packages/gui/src/view/router/index.js +++ b/packages/gui/src/view/router/index.js @@ -2,6 +2,7 @@ import Index from '../pages/index' import Server from '../pages/server' import Proxy from '../pages/proxy' import Node from '../pages/plugin/node' +import Git from '../pages/plugin/git' import Overwall from '../pages/plugin/overwall' const routes = [ @@ -10,6 +11,7 @@ const routes = [ { path: '/server', component: Server }, { path: '/proxy', component: Proxy }, { path: '/plugin/node', component: Node }, + { path: '/plugin/git', component: Git }, { path: '/plugin/overwall', component: Overwall } ] diff --git a/packages/gui/src/view/router/menu.js b/packages/gui/src/view/router/menu.js index 386930b..ce33db8 100644 --- a/packages/gui/src/view/router/menu.js +++ b/packages/gui/src/view/router/menu.js @@ -1,6 +1,7 @@ export default function createMenus (app) { const plugins = [ - { title: 'NPM加速', path: '/plugin/node', icon: 'like' } + { title: 'NPM加速', path: '/plugin/node', icon: 'like' }, + { title: 'Git代理', path: '/plugin/git', icon: 'github' } ] const menus = [ { title: '首页', path: '/index', icon: 'home' }, diff --git a/packages/gui/yarn.lock b/packages/gui/yarn.lock index eb52e51..516856b 100644 --- a/packages/gui/yarn.lock +++ b/packages/gui/yarn.lock @@ -901,12 +901,12 @@ ajv "^6.12.0" ajv-keywords "^3.4.1" -"@docmirror/dev-sidecar@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@docmirror/dev-sidecar/-/dev-sidecar-1.2.0.tgz#2320c31f786afd495b8e12557bea396cb96e0985" - integrity sha512-i96YlPjQtrrAgDW52YOpuVFmQDl1A0Nx3x6/riv2yKVN4nGqAugdJvcAuhNi7BDrJfdLyls2jI35uzN5+bpYfQ== +"@docmirror/dev-sidecar@^1.2.2": + version "1.2.2" + resolved "https://registry.yarnpkg.com/@docmirror/dev-sidecar/-/dev-sidecar-1.2.2.tgz#4963a9dd9f3f46e614e1c1479887b8680f0f6650" + integrity sha512-gWD5WPuyijIuFrpinMR0QSLdqdhLEfZVi9lnRSor9TnnaoBpeY6QlufHACpDDo6hME8f62adXGFmL3UoFJS49Q== dependencies: - "@docmirror/mitmproxy" "^1.2.0" + "@docmirror/mitmproxy" "^1.2.2" agentkeepalive "^2.1.1" charset "^1.0.0" child_process "^1.0.2" @@ -933,10 +933,10 @@ validator "^13.1.17" winreg "^1.2.4" -"@docmirror/mitmproxy@^1.2.0": - version "1.2.0" - resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.0.tgz#ab9910031272d8e16fe0e38d434f7b42971bc74e" - integrity sha512-DlzquSNVZOC/p5GwAdDwSiI4KCb3HlUY4A44pGGOBehsNThBoRU8ESKJjbyay9ah4RPSAWTSVYgMEiPZctR+wg== +"@docmirror/mitmproxy@^1.2.2": + version "1.2.2" + resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.2.tgz#a4d0020e073eaa68adb7902b5634ab2a1a3bc058" + integrity sha512-xW1xyqUfpGAZZTzqSjoQM0Mmq8VVEyvS8AiTUBvgpxUAYG2sqNCacLETwYfNBP1MStUBtGXKklcISpIY6+R+DA== dependencies: agentkeepalive "^2.1.1" child_process "^1.0.2"