mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 支持导入51dns域名
This commit is contained in:
@@ -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,将其自动注册到系统中
|
||||
|
||||
Reference in New Issue
Block a user