mirror of
https://github.com/certd/certd.git
synced 2026-07-30 09:17:36 +08:00
chore: format
This commit is contained in:
@@ -1,41 +1,39 @@
|
||||
import { IsAccess, AccessInput, BaseAccess, PageSearch, PageRes, Pager } from '@certd/pipeline';
|
||||
import { DomainRecord } from '@certd/plugin-lib';
|
||||
import { merge } from 'lodash-es';
|
||||
import qs from 'qs';
|
||||
import { IsAccess, AccessInput, BaseAccess, PageSearch, PageRes, Pager } from "@certd/pipeline";
|
||||
import { DomainRecord } from "@certd/plugin-lib";
|
||||
import { merge } from "lodash-es";
|
||||
import qs from "qs";
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
||||
*/
|
||||
@IsAccess({
|
||||
name: 'namesilo',
|
||||
title: 'namesilo授权',
|
||||
desc: '',
|
||||
icon: 'simple-icons:namesilo',
|
||||
name: "namesilo",
|
||||
title: "namesilo授权",
|
||||
desc: "",
|
||||
icon: "simple-icons:namesilo",
|
||||
})
|
||||
export class NamesiloAccess extends BaseAccess {
|
||||
/**
|
||||
* 授权属性配置
|
||||
*/
|
||||
@AccessInput({
|
||||
title: 'API Key',
|
||||
title: "API Key",
|
||||
component: {
|
||||
placeholder: 'api key',
|
||||
placeholder: "api key",
|
||||
},
|
||||
helper:
|
||||
'前往 [获取API Key](https://www.namesilo.com/account/api-manager)\n不要勾选第一项(Generate key for read-only access)\n勾选第二项(Submitting this form...)\n然后点击Generate按钮',
|
||||
helper: "前往 [获取API Key](https://www.namesilo.com/account/api-manager)\n不要勾选第一项(Generate key for read-only access)\n勾选第二项(Submitting this form...)\n然后点击Generate按钮",
|
||||
required: true,
|
||||
encrypt: true,
|
||||
})
|
||||
apiKey = '';
|
||||
apiKey = "";
|
||||
|
||||
|
||||
@AccessInput({
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "TestRequest"
|
||||
action: "TestRequest",
|
||||
},
|
||||
helper: "点击测试接口是否正常"
|
||||
helper: "点击测试接口是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
@@ -44,57 +42,53 @@ export class NamesiloAccess extends BaseAccess {
|
||||
pageNo: 1,
|
||||
pageSize: 1,
|
||||
});
|
||||
return "ok"
|
||||
return "ok";
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
|
||||
const pager = new Pager(req);
|
||||
const ret =await this.doRequest('/api/listDomains', {
|
||||
key:req.searchKey,
|
||||
page: pager.pageNo,
|
||||
pageSize: pager.pageSize,
|
||||
});
|
||||
let list = ret.domains ||[]
|
||||
// this.logger.info("获取域名列表成功:", ret);
|
||||
list = list.map((item: any) => ({
|
||||
id: item.domain,
|
||||
domain: item.domain,
|
||||
}));
|
||||
return {
|
||||
total:ret.pager?.total || list.length,
|
||||
list,
|
||||
};
|
||||
const pager = new Pager(req);
|
||||
const ret = await this.doRequest("/api/listDomains", {
|
||||
key: req.searchKey,
|
||||
page: pager.pageNo,
|
||||
pageSize: pager.pageSize,
|
||||
});
|
||||
let list = ret.domains || [];
|
||||
// this.logger.info("获取域名列表成功:", ret);
|
||||
list = list.map((item: any) => ({
|
||||
id: item.domain,
|
||||
domain: item.domain,
|
||||
}));
|
||||
return {
|
||||
total: ret.pager?.total || list.length,
|
||||
list,
|
||||
};
|
||||
}
|
||||
|
||||
async doRequest(url: string, params: any = null) {
|
||||
params = merge(
|
||||
{
|
||||
version: 1,
|
||||
type: "json",
|
||||
key: this.apiKey,
|
||||
},
|
||||
params
|
||||
);
|
||||
const qsString = qs.stringify(params);
|
||||
url = `${url}?${qsString}`;
|
||||
const res = await this.ctx.http.request<any, any>({
|
||||
url,
|
||||
baseURL: "https://www.namesilo.com",
|
||||
method: "get",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (res.reply?.code !== "300" && res.reply?.code !== 300 && res.reply?.detail !== "success") {
|
||||
throw new Error(`${JSON.stringify(res.reply.detail)}`);
|
||||
}
|
||||
|
||||
|
||||
|
||||
async doRequest(url: string, params: any = null) {
|
||||
params = merge(
|
||||
{
|
||||
version: 1,
|
||||
type: 'json',
|
||||
key: this.apiKey,
|
||||
},
|
||||
params
|
||||
);
|
||||
const qsString = qs.stringify(params);
|
||||
url = `${url}?${qsString}`;
|
||||
const res = await this.ctx.http.request<any, any>({
|
||||
url,
|
||||
baseURL: 'https://www.namesilo.com',
|
||||
method: 'get',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (res.reply?.code !== '300' && res.reply?.code !== 300 && res.reply?.detail!=="success") {
|
||||
throw new Error(`${JSON.stringify(res.reply.detail)}`);
|
||||
}
|
||||
return res.reply;
|
||||
}
|
||||
|
||||
return res.reply;
|
||||
}
|
||||
}
|
||||
|
||||
new NamesiloAccess();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PageRes, PageSearch } from '@certd/pipeline';
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { NamesiloAccess } from './access.js';
|
||||
import { PageRes, PageSearch } from "@certd/pipeline";
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { NamesiloAccess } from "./access.js";
|
||||
|
||||
export type NamesiloRecord = {
|
||||
record_id: string;
|
||||
@@ -8,12 +8,12 @@ export type NamesiloRecord = {
|
||||
|
||||
// 这里通过IsDnsProvider注册一个dnsProvider
|
||||
@IsDnsProvider({
|
||||
name: 'namesilo',
|
||||
title: 'namesilo',
|
||||
desc: 'namesilo dns provider',
|
||||
icon: 'simple-icons:namesilo',
|
||||
name: "namesilo",
|
||||
title: "namesilo",
|
||||
desc: "namesilo dns provider",
|
||||
icon: "simple-icons:namesilo",
|
||||
// 这里是对应的 cloudflare的access类型名称
|
||||
accessType: 'namesilo',
|
||||
accessType: "namesilo",
|
||||
})
|
||||
export class NamesiloDnsProvider extends AbstractDnsProvider<NamesiloRecord> {
|
||||
access!: NamesiloAccess;
|
||||
@@ -28,7 +28,6 @@ export class NamesiloDnsProvider extends AbstractDnsProvider<NamesiloRecord> {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建dns解析记录,用于验证域名所有权
|
||||
*/
|
||||
@@ -40,10 +39,10 @@ export class NamesiloDnsProvider extends AbstractDnsProvider<NamesiloRecord> {
|
||||
* domain: 'example.com'
|
||||
*/
|
||||
const { fullRecord, hostRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
|
||||
this.logger.info("添加域名解析:", fullRecord, value, type, domain);
|
||||
|
||||
//domain=namesilo.com&rrtype=A&rrhost=test&rrvalue=55.55.55.55&rrttl=7207
|
||||
const record: any = await this.access.doRequest('/api/dnsAddRecord', {
|
||||
const record: any = await this.access.doRequest("/api/dnsAddRecord", {
|
||||
domain,
|
||||
rrtype: type,
|
||||
rrhost: hostRecord,
|
||||
@@ -62,15 +61,15 @@ export class NamesiloDnsProvider extends AbstractDnsProvider<NamesiloRecord> {
|
||||
async removeRecord(options: RemoveRecordOptions<NamesiloRecord>): Promise<void> {
|
||||
const { fullRecord, value } = options.recordReq;
|
||||
const record = options.recordRes;
|
||||
this.logger.info('删除域名解析:', fullRecord, value);
|
||||
this.logger.info("删除域名解析:", fullRecord, value);
|
||||
if (!record && !record.record_id) {
|
||||
this.logger.info('record为空,不执行删除');
|
||||
this.logger.info("record为空,不执行删除");
|
||||
return;
|
||||
}
|
||||
//这里调用删除txt dns解析记录接口
|
||||
|
||||
const recordId = record.record_id;
|
||||
await this.access.doRequest('/api/dnsDeleteRecord', {
|
||||
await this.access.doRequest("/api/dnsDeleteRecord", {
|
||||
domain: options.recordReq.domain,
|
||||
rrid: recordId,
|
||||
});
|
||||
@@ -78,7 +77,7 @@ export class NamesiloDnsProvider extends AbstractDnsProvider<NamesiloRecord> {
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
return await this.access.getDomainListPage(req);
|
||||
return await this.access.getDomainListPage(req);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './dns-provider.js';
|
||||
export * from './access.js';
|
||||
export * from "./dns-provider.js";
|
||||
export * from "./access.js";
|
||||
|
||||
Reference in New Issue
Block a user