mirror of
https://github.com/certd/certd.git
synced 2026-05-18 22:57:31 +08:00
refactor: ui prepare
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import _ from 'lodash-es'
|
||||
import logger from '../utils/util.log.js'
|
||||
export class AbstractDnsProvider {
|
||||
constructor () {
|
||||
this.logger = logger
|
||||
}
|
||||
|
||||
async createRecord ({ fullRecord, type, value }) {
|
||||
throw new Error('请实现 createRecord 方法')
|
||||
}
|
||||
|
||||
async removeRecord ({ fullRecord, type, value, record }) {
|
||||
throw new Error('请实现 removeRecord 方法')
|
||||
}
|
||||
|
||||
async getDomainList () {
|
||||
throw new Error('请实现 getDomainList 方法')
|
||||
}
|
||||
|
||||
async matchDomain (dnsRecord, domainPropName) {
|
||||
const list = await this.getDomainList()
|
||||
let domain = null
|
||||
for (const item of list) {
|
||||
if (_.endsWith(dnsRecord, item[domainPropName])) {
|
||||
domain = item
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!domain) {
|
||||
throw new Error('找不到域名,请检查域名是否正确:' + dnsRecord)
|
||||
}
|
||||
return domain
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,2 @@
|
||||
import _ from 'lodash-es'
|
||||
import logger from '../utils/util.log.js'
|
||||
export class AbstractDnsProvider {
|
||||
constructor () {
|
||||
this.logger = logger
|
||||
}
|
||||
|
||||
async createRecord ({ fullRecord, type, value }) {
|
||||
throw new Error('请实现 createRecord 方法')
|
||||
}
|
||||
|
||||
async removeRecord ({ fullRecord, type, value, record }) {
|
||||
throw new Error('请实现 removeRecord 方法')
|
||||
}
|
||||
|
||||
async getDomainList () {
|
||||
throw new Error('请实现 getDomainList 方法')
|
||||
}
|
||||
|
||||
async matchDomain (dnsRecord, domainPropName) {
|
||||
const list = await this.getDomainList()
|
||||
let domain = null
|
||||
for (const item of list) {
|
||||
if (_.endsWith(dnsRecord, item[domainPropName])) {
|
||||
domain = item
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!domain) {
|
||||
throw new Error('找不到域名,请检查域名是否正确:' + dnsRecord)
|
||||
}
|
||||
return domain
|
||||
}
|
||||
}
|
||||
export { providerRegistry } from './provider-registry.js'
|
||||
export { AbstractDnsProvider } from './abstract-provider.js'
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
export class ProviderRegistry {
|
||||
constructor () {
|
||||
this.providers = {}
|
||||
}
|
||||
|
||||
install (provider) {
|
||||
if (provider == null) {
|
||||
return
|
||||
}
|
||||
if (this.providers == null) {
|
||||
this.providers = {}
|
||||
}
|
||||
const name = provider.name || (provider.define && provider.define.name)
|
||||
this.providers[name] = provider
|
||||
}
|
||||
|
||||
get (name) {
|
||||
if (name) {
|
||||
return this.providers[name]
|
||||
}
|
||||
throw new Error(`找不到授权提供者:${name}`)
|
||||
}
|
||||
}
|
||||
|
||||
export const providerRegistry = new ProviderRegistry()
|
||||
Reference in New Issue
Block a user