perf: 支持导入51dns域名

This commit is contained in:
xiaojunnuo
2026-01-23 15:28:33 +08:00
parent b8f0d37420
commit 7eb9694221
5 changed files with 95 additions and 9 deletions
+12 -4
View File
@@ -5,12 +5,20 @@
![](./images/1.png)
:::tip
接口key分两种权限范围:
1. 仅开放接口: 仅能访问下面`接口文档`中的接口
2. 用户级别: 可访问Certd所有接口,没有文档,可以在浏览器中F12抓取网络请求参考
:::
## 接口文档
https://apifox.com/apidoc/shared-2e76f8c4-7c58-413b-a32d-a1316529af44/254949529e0
## Token生成方法
### Token生成方法
header中传入x-certd-token即可调用开放接口
1、首先从OpenKey页面生成keyIdkeySecret
@@ -19,10 +27,10 @@ header中传入x-certd-token即可调用开放接口
4、然后将content和sign分别base64后用.号连接: x-certd-token = base64(content) +"."+base64(sign)
## 参数
### 参数
支持证书id和域名两种方式获取证书。
## 创建新的证书申请
### 创建新的证书申请
参数autoApply=true,将在没有证书时自动触发申请证书,检查逻辑如下:
1. 如果证书仓库里面有,且没有过期,就直接返回证书
2. 如果没有或者已过期,就会去找流水线,有就触发流水线执行
@@ -30,7 +38,7 @@ header中传入x-certd-token即可调用开放接口
4. 再次采用相同参数请求接口,如果在申请过程中,就会提示`正在申请中`,可轮循获取状态,直到证书申请成功。
## SDK
### SDK
待开发
## 客户端工具
@@ -339,10 +339,14 @@ export default function ({ crudExpose, context }: CreateCrudOptionsProps): Creat
title: t("certd.domain.fromType"),
type: "dict-select",
dict: Dicts.domainFromTypeDict,
form: {
show: false,
},
column: {
component: {
color: "auto",
},
show: false,
},
},
disabled: {
@@ -248,8 +248,12 @@ export class DomainService extends BaseService<DomainEntity> {
}
})
if (old) {
if (old.fromType !== 'auto') {
//如果是手动的,跳过更新校验配置
// if (old.fromType !== 'auto') {
// //如果是手动的,跳过更新校验配置
// return
// }
if (old) {
//如果old存在,直接跳过
return
}
const updateObj: any = {
@@ -269,8 +273,9 @@ export class DomainService extends BaseService<DomainEntity> {
dnsProviderAccess: dnsProviderAccessId,
challengeType,
disabled: false,
fromType: 'auto',
fromType: 'manual',
})
logger.info(`导入域名${domain}到用户${userId}`)
}
}
const batchHandle = async (pageRes: PageRes<any>) => {
@@ -278,6 +283,7 @@ export class DomainService extends BaseService<DomainEntity> {
}
const start = async () => {
await doPageTurn({ pager, getPage, itemHandle, batchHandle })
logger.info(`同步用户(${req.userId ?? '全部'})从域名提供商${dnsProviderType}导入域名完成`)
}
start()
@@ -397,5 +403,6 @@ export class DomainService extends BaseService<DomainEntity> {
}
await doPageTurn({ pager, getPage: getDomainPage, itemHandle: itemHandle })
logger.info(`同步用户(${req.userId ?? '全部'})注册域名过期时间完成`)
}
}
@@ -1,6 +1,8 @@
import {createAxiosService, HttpClient, ILogger} from "@certd/basic";
import {Dns51Access} from "./access.js";
import qs from "qs"
import { Pager, PageRes } from "@certd/pipeline";
import { DomainRecord } from "@certd/plugin-lib/dist/cert/dns-provider/api.js";
export class Dns51Client {
logger: ILogger;
access: Dns51Access;
@@ -234,4 +236,64 @@ _token: ieOfM21eDd9nWJv3OZtMJF6ogDsnPKQHJ17dlMck
}
}
async getDomainListPage(pager: Pager): Promise<PageRes<DomainRecord>> {
if (pager.pageNo >=2) { //不知道翻页查询的参数是什么
return {
total: 0,
list: []
}
}
await this.login();
const query = {
//domain=&id=&status=&perPage=500
perPage: 1000,
}
const res = await this.http.request({
url: 'https://www.51dns.com/domain?' + qs.stringify(query),
method: 'get',
withCredentials: true,
logRes: false,
returnOriginRes: true,
headers: this.getRequestHeaders()
});
//提取记录
const content = res.data || ""
const startIndex = content.indexOf(`<table cellpadding="0" cellspacing="0" class="domiantable">`)
if (startIndex < 0) {
throw new Error("解析域名列表失败,未找到域名列表")
}
const endIndex = content.indexOf(`</table>`, startIndex)
const tableContent = content.substring(startIndex, endIndex + 8)
// <tr class="">
// <a target="_blank" href="https://www.51dns.com/domain/record/199820259"
// class="color47">docmirror.cn</a>
const list: DomainRecord[] = []
const trArr = tableContent.split(`<tr class="">`)
for (const tr of trArr) {
const lines = tr.trim().split("\n")
const row:any = {}
for (const line of lines) {
if (line.includes(`<a target="_blank" href="https://www.51dns.com/domain/record/`)) {
// 提取id
const domainId = line.match(/record\/(\d+)"/i)[1];
row.id = parseInt(domainId);
}
if (line.includes(`class="color47"`)) {
// 提取域名
const domain = line.match(/class="color47">(.*?)<\/a>/i)[1];
row.domain = domain;
}
}
if (row.domain) {
list.push(row)
}
}
return {
total: list.length,
list
}
}
}
@@ -1,7 +1,8 @@
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
import { Dns51Access } from "./access.js";
import { Dns51Client } from "./client.js";
import { Pager, PageRes } from "@certd/pipeline";
export type Dns51Record = {
id: number;
@@ -92,6 +93,10 @@ export class Dns51DnsProvider extends AbstractDnsProvider<Dns51Record> {
})
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},id=${id}`);
}
async getDomainListPage(pager: Pager): Promise<PageRes<DomainRecord>> {
return await this.client.getDomainListPage(pager)
}
}
//实例化这个provider,将其自动注册到系统中