refactor: mirrors

pull/180/head
xiaojunnuo 2020-10-27 22:11:43 +08:00
parent aa4f029f62
commit 9b831d3322
5 changed files with 11 additions and 9 deletions

View File

@ -14,7 +14,7 @@
### 3、 github的源代码查看raw/blame查看 ### 3、 github的源代码查看raw/blame查看
通过跳转到国内加速链接上 通过跳转到国内加速链接上
### 4、 Stack Overflow 加速 ### 4、 Stack Overflow 加速
将ajax.google.com代理到加速代理上 将ajax.google.com代理到加速代理上 ,recaptcha 加速
### 5、 google cdn 加速 ### 5、 google cdn 加速
通过代理到加速链接上 通过代理到加速链接上

View File

@ -34,11 +34,13 @@ const configApi = {
resetDefault () { resetDefault () {
configTarget = lodash.cloneDeep(defConfig) configTarget = lodash.cloneDeep(defConfig)
}, },
getMirrorEnv () { async getMirrorEnv () {
const envMap = Shell.getEnv() const envMap = await Shell.getEnv()
const list = [] const list = []
const mirrors = configTarget.mirrors const mirrors = configTarget.mirrors
console.log('envMap', envMap)
for (const key in mirrors) { for (const key in mirrors) {
console.log('equale', key, envMap[key])
const exists = envMap[key] != null const exists = envMap[key] != null
list.push({ list.push({
key, key,
@ -49,14 +51,14 @@ const configApi = {
console.log('mirrors:', list) console.log('mirrors:', list)
return list return list
}, },
setupMirrors () { async setupMirrors () {
const list = configApi.getMirrorEnv() const list = await configApi.getMirrorEnv()
const noSetList = list.filter(item => { const noSetList = list.filter(item => {
return !item.exists return !item.exists
}) })
console.log('mirrors will set:', noSetList) console.log('mirrors will set:', noSetList)
if (list.length > 0) { if (list.length > 0) {
Shell.setEnv({ list: noSetList }) return Shell.setEnv({ list: noSetList })
} }
} }
} }

View File

@ -1,6 +1,6 @@
const expose = require('./expose.js') const expose = require('./expose.js')
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' // process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
// 避免异常崩溃 // 避免异常崩溃
process.on('uncaughtException', function (err) { process.on('uncaughtException', function (err) {

View File

@ -12,7 +12,7 @@ const executor = {
for (const item of lines) { for (const item of lines) {
const kv = item.split('=') const kv = item.split('=')
if (kv.length > 1) { if (kv.length > 1) {
map[kv[0]] = kv[1] map[kv[0].trim()] = kv[1].trim()
} }
} }
} }

View File

@ -8,7 +8,7 @@ const executor = {
const cmds = [] const cmds = []
for (const item of list) { for (const item of list) {
// [Environment]::SetEnvironmentVariable('FOO', 'bar', 'Machine') // [Environment]::SetEnvironmentVariable('FOO', 'bar', 'Machine')
cmds.push(`[Environment]::SetEnvironmentVariable('${item.key} ', '${item.value}', 'Machine')`) cmds.push(`[Environment]::SetEnvironmentVariable('${item.key}', '${item.value}', 'Machine')`)
} }
const ret = await exec(cmds, { type: 'ps' }) const ret = await exec(cmds, { type: 'ps' })
return ret return ret