chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -1,65 +1,60 @@
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";
/**
* Technitium DNS Server 授权配置
*/
@IsAccess({
name: 'technitium',
title: 'Technitium DNS Server',
icon: 'clarity:server-line',
desc: 'Technitium DNS Server 自建DNS服务器授权',
name: "technitium",
title: "Technitium DNS Server",
icon: "clarity:server-line",
desc: "Technitium DNS Server 自建DNS服务器授权",
})
export class TechnitiumAccess extends BaseAccess {
/**
* API地址
*/
@AccessInput({
title: 'API地址',
value: 'http://localhost:5380',
title: "API地址",
value: "http://localhost:5380",
component: {
name: "a-input",
allowClear: true,
placeholder: 'http://localhost:5380',
placeholder: "http://localhost:5380",
},
required: true,
})
apiUrl = 'http://localhost:5380';
apiUrl = "http://localhost:5380";
/**
* 用户名
*/
@AccessInput({
title: '用户名',
title: "用户名",
component: {
name: "a-input",
allowClear: true,
placeholder: 'admin',
placeholder: "admin",
},
required: false,
})
username = 'admin';
username = "admin";
/**
* 密码
*/
@AccessInput({
title: '密码',
title: "密码",
component: {
name: "a-input",
type: "password",
allowClear: true,
placeholder: '密码',
placeholder: "密码",
},
required: false,
encrypt: true,
})
password = '';
password = "";
/**
* 测试按钮
@@ -68,43 +63,43 @@ export class TechnitiumAccess extends BaseAccess {
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
action: "TestRequest",
},
helper: "点击测试接口是否正常"
helper: "点击测试接口是否正常",
})
testRequest = true;
token = '';
token = "";
/**
* 通用API调用方法
*/
async doRequest(options: { url: string; method: 'get' | 'post'; params?: URLSearchParams }) {
async doRequest(options: { url: string; method: "get" | "post"; params?: URLSearchParams }) {
// 每次请求前都获取最新的token
if (!options.url.includes('/api/user/login')) {
if (!options.url.includes("/api/user/login")) {
await this.getToken();
}
// 复制参数并添加token
const params = new URLSearchParams(options.params || '');
if (this.token && !options.url.includes('/api/user/login')) {
params.append('token', this.token);
const params = new URLSearchParams(options.params || "");
if (this.token && !options.url.includes("/api/user/login")) {
params.append("token", this.token);
}
let fullUrl = options.url;
if (params.toString()) {
fullUrl = `${options.url}?${params.toString()}`;
}
const response = await this.ctx.http.request({
url: fullUrl,
method: options.method,
});
if (response.status !== 'ok') {
throw new Error(`${response.errorMessage || 'API调用失败'}`);
if (response.status !== "ok") {
throw new Error(`${response.errorMessage || "API调用失败"}`);
}
return response;
}
@@ -123,34 +118,34 @@ export class TechnitiumAccess extends BaseAccess {
async GetDomainList(req: PageSearch): Promise<PageRes<DomainRecord>> {
this.ctx.logger.info(`获取域名列表,req:${JSON.stringify(req)}`);
const pager = new Pager(req);
// 规范API地址
this.apiUrl = this.normalizeEndpoint(this.apiUrl);
// 构建API URL
const apiUrl = `${this.apiUrl}/api/zones/list`;
// 构建查询参数
const params = new URLSearchParams();
// 调用API获取区域列表
const response = await this.doRequest({ url: apiUrl, method: 'get', params: params });
const response = await this.doRequest({ url: apiUrl, method: "get", params: params });
const zones = response.response.zones || [];
const total = zones.length;
// 转换为DomainRecord格式
let list = zones.map((zone: any) => ({
id: zone.name,
domain: zone.name,
}));
// 应用分页
list = list.slice(pager.getOffset(), pager.getOffset() + pager.pageSize);
return {
total,
list
list,
};
}
@@ -159,24 +154,23 @@ export class TechnitiumAccess extends BaseAccess {
*/
async getToken() {
const apiUrl = `${this.apiUrl}/api/user/login`;
const params = new URLSearchParams({
user: this.username,
pass: this.password,
});
// 直接使用ctx.http.request,避免递归调用doRequest
const response = await this.ctx.http.request({
url: `${apiUrl}?${params.toString()}`,
method: 'post',
method: "post",
});
if (response.status !== 'ok') {
throw new Error(`登录失败: ${response.errorMessage || '未知错误'}`);
if (response.status !== "ok") {
throw new Error(`登录失败: ${response.errorMessage || "未知错误"}`);
}
this.token = response.token;
return this.token;
}
}
@@ -1,6 +1,6 @@
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
import { TechnitiumAccess } from "./access.js"
import { TechnitiumAccess } from "./access.js";
type TechnitiumRecord = {
// 记录创建时返回的数据结构
@@ -26,11 +26,11 @@ type TechnitiumRecord = {
// 注册Technitium DNS Server的DNS提供商
@IsDnsProvider({
name: 'technitium',
title: 'Technitium DNS Server',
desc: 'Technitium DNS Server 自建DNS服务器',
icon: 'clarity:server-line',
accessType: 'technitium',
name: "technitium",
title: "Technitium DNS Server",
desc: "Technitium DNS Server 自建DNS服务器",
icon: "clarity:server-line",
accessType: "technitium",
order: 10,
})
export class TechnitiumDnsProvider extends AbstractDnsProvider<TechnitiumRecord> {
@@ -38,7 +38,7 @@ export class TechnitiumDnsProvider extends AbstractDnsProvider<TechnitiumRecord>
async onInstance() {
this.access = this.ctx.access as TechnitiumAccess;
this.logger.debug('access', this.access);
this.logger.debug("access", this.access);
}
/**
@@ -46,11 +46,11 @@ export class TechnitiumDnsProvider extends AbstractDnsProvider<TechnitiumRecord>
*/
async createRecord(options: CreateRecordOptions): Promise<TechnitiumRecord> {
const { fullRecord, value, type, domain } = options;
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
this.logger.info("添加域名解析:", fullRecord, value, type, domain);
// 构建API URL
const apiUrl = `${this.access.apiUrl}/api/zones/records/add`;
// 构建查询参数
const params = new URLSearchParams({
zone: domain,
@@ -61,9 +61,9 @@ export class TechnitiumDnsProvider extends AbstractDnsProvider<TechnitiumRecord>
});
// 调用Technitium API创建TXT记录
const response = await this.access.doRequest({ url: apiUrl, method: 'post', params: params });
const response = await this.access.doRequest({ url: apiUrl, method: "post", params: params });
this.logger.info('创建域名解析成功:', fullRecord, value);
this.logger.info("创建域名解析成功:", fullRecord, value);
return response as TechnitiumRecord;
}
@@ -73,23 +73,23 @@ export class TechnitiumDnsProvider extends AbstractDnsProvider<TechnitiumRecord>
async removeRecord(options: RemoveRecordOptions<TechnitiumRecord>): Promise<void> {
const { fullRecord, value, domain } = options.recordReq;
const record = options.recordRes;
this.logger.info('删除域名解析:', domain, fullRecord, value, record);
this.logger.info("删除域名解析:", domain, fullRecord, value, record);
// 构建API URL
const apiUrl = `${this.access.apiUrl}/api/zones/records/delete`;
// 构建查询参数
const params = new URLSearchParams({
zone: domain,
domain: fullRecord,
type: 'TXT',
type: "TXT",
text: value,
});
// 调用Technitium API删除TXT记录
await this.access.doRequest({ url: apiUrl, method: 'post', params: params });
await this.access.doRequest({ url: apiUrl, method: "post", params: params });
this.logger.info('删除域名解析成功:', fullRecord, value);
this.logger.info("删除域名解析成功:", fullRecord, value);
}
}
@@ -1,2 +1,2 @@
export * from './dns-provider.js';
export * from './access.js';
export * from "./dns-provider.js";
export * from "./access.js";