mirror of
https://github.com/certd/certd.git
synced 2026-07-29 08:37:36 +08:00
chore: format
This commit is contained in:
@@ -1,49 +1,49 @@
|
||||
import { AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch } from '@certd/pipeline';
|
||||
import { DomainRecord } from '@certd/plugin-lib';
|
||||
import { AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||
import { DomainRecord } from "@certd/plugin-lib";
|
||||
|
||||
@IsAccess({
|
||||
name: 'dnsmgr',
|
||||
title: '彩虹DNS',
|
||||
icon: 'clarity:plugin-line',
|
||||
desc: '彩虹DNS管理系统授权',
|
||||
name: "dnsmgr",
|
||||
title: "彩虹DNS",
|
||||
icon: "clarity:plugin-line",
|
||||
desc: "彩虹DNS管理系统授权",
|
||||
})
|
||||
export class DnsmgrAccess extends BaseAccess {
|
||||
@AccessInput({
|
||||
title: '系统地址',
|
||||
title: "系统地址",
|
||||
component: {
|
||||
name: "a-input",
|
||||
allowClear: true,
|
||||
placeholder: 'https://dnsmgr.example.com',
|
||||
placeholder: "https://dnsmgr.example.com",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
endpoint = '';
|
||||
endpoint = "";
|
||||
|
||||
@AccessInput({
|
||||
title: '用户ID',
|
||||
title: "用户ID",
|
||||
component: {
|
||||
name: "a-input",
|
||||
allowClear: true,
|
||||
placeholder: '123456',
|
||||
placeholder: "123456",
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
uid = '';
|
||||
uid = "";
|
||||
|
||||
@AccessInput({
|
||||
title: 'API密钥',
|
||||
title: "API密钥",
|
||||
required: true,
|
||||
encrypt: true,
|
||||
})
|
||||
key = '';
|
||||
key = "";
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "TestRequest"
|
||||
action: "TestRequest",
|
||||
},
|
||||
helper: "点击测试接口是否正常"
|
||||
helper: "点击测试接口是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
@@ -56,7 +56,7 @@ export class DnsmgrAccess extends BaseAccess {
|
||||
this.ctx.logger.info(`获取域名列表,req:${JSON.stringify(req)}`);
|
||||
const pager = new Pager(req);
|
||||
const resp = await this.doRequest({
|
||||
url: '/api/domain',
|
||||
url: "/api/domain",
|
||||
data: {
|
||||
offset: pager.getOffset(),
|
||||
limit: pager.pageSize,
|
||||
@@ -64,7 +64,7 @@ export class DnsmgrAccess extends BaseAccess {
|
||||
},
|
||||
});
|
||||
const total = resp?.total || 0;
|
||||
let list = resp?.rows?.map((item: any) => {
|
||||
const list = resp?.rows?.map((item: any) => {
|
||||
return {
|
||||
domain: item.name,
|
||||
...item,
|
||||
@@ -76,17 +76,15 @@ export class DnsmgrAccess extends BaseAccess {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
async createDnsRecord(domainId: string, record: string, value: string, type: string, domain: string) {
|
||||
this.ctx.logger.info(`创建DNS记录:${record} ${type} ${value}`);
|
||||
const resp = await this.doRequest({
|
||||
url: `/api/record/add/${domainId}`,
|
||||
data: {
|
||||
name: record.replace(`.${domain}`, ''),
|
||||
name: record.replace(`.${domain}`, ""),
|
||||
type,
|
||||
value,
|
||||
line: 'default',
|
||||
line: "default",
|
||||
ttl: 600,
|
||||
},
|
||||
});
|
||||
@@ -121,12 +119,12 @@ export class DnsmgrAccess extends BaseAccess {
|
||||
const timestamp = Math.floor(Date.now() / 1000);
|
||||
const sign = this.ctx.utils.hash.md5(`${this.uid}${timestamp}${this.key}`);
|
||||
const url = `${this.endpoint}${req.url}`;
|
||||
|
||||
|
||||
const res = await this.ctx.http.request({
|
||||
url,
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data: {
|
||||
uid: this.uid,
|
||||
@@ -137,7 +135,7 @@ export class DnsmgrAccess extends BaseAccess {
|
||||
});
|
||||
|
||||
if (res.code !== undefined && res.code !== 0) {
|
||||
throw new Error(res.msg || '请求失败');
|
||||
throw new Error(res.msg || "请求失败");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { DnsmgrAccess } from './access.js';
|
||||
import { PageRes, PageSearch } from '@certd/pipeline';
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { DnsmgrAccess } from "./access.js";
|
||||
import { PageRes, PageSearch } from "@certd/pipeline";
|
||||
|
||||
type DnsmgrRecord = {
|
||||
domainId: string;
|
||||
@@ -9,11 +9,11 @@ type DnsmgrRecord = {
|
||||
};
|
||||
|
||||
@IsDnsProvider({
|
||||
name: 'dnsmgr',
|
||||
title: '彩虹DNS',
|
||||
desc: '彩虹DNS管理系统',
|
||||
icon: 'clarity:plugin-line',
|
||||
accessType: 'dnsmgr',
|
||||
name: "dnsmgr",
|
||||
title: "彩虹DNS",
|
||||
desc: "彩虹DNS管理系统",
|
||||
icon: "clarity:plugin-line",
|
||||
accessType: "dnsmgr",
|
||||
order: 99,
|
||||
})
|
||||
export class DnsmgrDnsProvider extends AbstractDnsProvider<DnsmgrRecord> {
|
||||
@@ -21,39 +21,39 @@ export class DnsmgrDnsProvider extends AbstractDnsProvider<DnsmgrRecord> {
|
||||
|
||||
async onInstance() {
|
||||
this.access = this.ctx.access as DnsmgrAccess;
|
||||
this.logger.debug('access', this.access);
|
||||
this.logger.debug("access", this.access);
|
||||
}
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
|
||||
this.logger.info("添加域名解析:", fullRecord, value, type, domain);
|
||||
|
||||
const domainList = await this.access.GetDomainList({ searchKey: domain });
|
||||
const domainInfo = domainList.list?.find((item: any) => item.name === domain);
|
||||
|
||||
|
||||
if (!domainInfo) {
|
||||
throw new Error(`未找到域名:${domain}`);
|
||||
}
|
||||
|
||||
const name = fullRecord.replace(`.${domain}`, '');
|
||||
const name = fullRecord.replace(`.${domain}`, "");
|
||||
const res = await this.access.createDnsRecord(domainInfo.id, fullRecord, value, type, domain);
|
||||
return { domainId: domainInfo.id, name, value,res };
|
||||
return { domainId: domainInfo.id, name, value, res };
|
||||
}
|
||||
|
||||
async removeRecord(options: RemoveRecordOptions<DnsmgrRecord>): Promise<void> {
|
||||
const { fullRecord, value } = options.recordReq;
|
||||
const record = options.recordRes;
|
||||
this.logger.info('删除域名解析:', fullRecord, value, record);
|
||||
this.logger.info("删除域名解析:", fullRecord, value, record);
|
||||
|
||||
if (record && record.domainId) {
|
||||
const records = await this.access.getDnsRecords(record.domainId, 'TXT', record.name, record.value);
|
||||
const records = await this.access.getDnsRecords(record.domainId, "TXT", record.name, record.value);
|
||||
if (records && records.rows && records.rows.length > 0) {
|
||||
const recordToDelete = records.rows[0];
|
||||
await this.access.deleteDnsRecord(record.domainId, recordToDelete.RecordId);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.info('删除域名解析成功:', fullRecord, value);
|
||||
this.logger.info("删除域名解析成功:", fullRecord, value);
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './access.js';
|
||||
export * from './dns-provider.js';
|
||||
export * from "./access.js";
|
||||
export * from "./dns-provider.js";
|
||||
|
||||
Reference in New Issue
Block a user