refactor: transfer

master
xiaojunnuo 2021-02-08 15:12:35 +08:00
parent e41c084381
commit 2232f21b48
6 changed files with 76 additions and 5 deletions

View File

@ -1,9 +1,10 @@
import _ from 'lodash-es' import _ from 'lodash-es'
import logger from '../utils/util.log.js' import logger from '../utils/util.log.js'
import commonUtil from '../utils/util.common'
export class AbstractDnsProvider { export class AbstractDnsProvider {
constructor ({ accessProviders }) { constructor ({ accessProviders }) {
this.logger = logger this.logger = logger
this.accessProviders = accessProviders this.accessProviders = commonUtil.arrayToMap(accessProviders)
} }
async createRecord ({ fullRecord, type, value }) { async createRecord ({ fullRecord, type, value }) {

View File

@ -2,7 +2,7 @@ import fs from 'fs'
import logger from '../utils/util.log.js' import logger from '../utils/util.log.js'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import Sleep from '../utils/util.sleep.js' import Sleep from '../utils/util.sleep.js'
import commonUtil from '../utils/util.common.js'
export class AbstractPlugin { export class AbstractPlugin {
constructor (options) { constructor (options) {
if (options == null) { if (options == null) {
@ -10,7 +10,7 @@ export class AbstractPlugin {
} }
const { accessProviders } = options const { accessProviders } = options
this.logger = logger this.logger = logger
this.accessProviders = accessProviders this.accessProviders = commonUtil.arrayToMap(accessProviders)
} }
appendTimeSuffix (name) { appendTimeSuffix (name) {

View File

@ -2,6 +2,7 @@ import logger from './util.log.js'
import path from './util.path.js' import path from './util.path.js'
import { request } from './util.request.js' import { request } from './util.request.js'
import sleep from './util.sleep.js' import sleep from './util.sleep.js'
import common from './util.common.js'
export const util = { export const util = {
logger, path, request, sleep logger, path, request, sleep, common
} }

View File

@ -0,0 +1,33 @@
import _ from 'lodash-es'
export default {
arrayToMap (array) {
if (!array) {
return {}
}
if (!_.isArray(array)) {
return array
}
const map = {}
for (const item of array) {
if (item.key) {
map[item.key] = item
}
}
return map
},
mapToArray (map) {
if (!map) {
return []
}
if (_.isArray(map)) {
return map
}
const array = []
for (const key in map) {
const item = map[key]
item.key = key
array.push(item)
}
return array
}
}

View File

@ -0,0 +1,33 @@
import _ from 'lodash-es'
export default {
arrayToMap (array) {
if (!array) {
return {}
}
if (!_.isArray(array)) {
return array
}
const map = {}
for (const item of array) {
if (item.key) {
map[item.key] = item
}
}
return map
},
mapToArray (map) {
if (!map) {
return []
}
if (_.isArray(map)) {
return map
}
const array = []
for (const key in map) {
const item = map[key]
item.key = key
array.push(item)
}
return array
}
}

View File

@ -190,7 +190,7 @@ import TaskForm from './components/task-form'
import exportsApi from '../../api/api.exports' import exportsApi from '../../api/api.exports'
import _ from 'lodash-es' import _ from 'lodash-es'
import DContainer from '../../components/d-container' import DContainer from '../../components/d-container'
import commonUtil from '@/utils/util.common'
function useDeploy (options) { function useDeploy (options) {
const deployAdd = () => { const deployAdd = () => {
options.deploy.push({ options.deploy.push({
@ -248,6 +248,9 @@ export default {
const route = useRoute() const route = useRoute()
console.log('route', route) console.log('route', route)
const optionParams = route.params.options ? JSON.parse(route.params.options) : {} const optionParams = route.params.options ? JSON.parse(route.params.options) : {}
if (optionParams.accessProviders) {
optionParams.accessProviders = commonUtil.mapToArray(optionParams.accessProviders)
}
const optionsDefault = { const optionsDefault = {
cert: { cert: {
csr: { csr: {