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,49 +1,49 @@
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
/**
* HiPM DNSMgr Access
* 使用 API Token 认证(Bearer Token
*/
@IsAccess({
name: 'hipmdnsmgr',
title: 'HiPM DNSMgr',
icon: 'svg:icon-dns',
desc: 'HiPM DNSMgr API Token 授权',
name: "hipmdnsmgr",
title: "HiPM DNSMgr",
icon: "svg:icon-dns",
desc: "HiPM DNSMgr API Token 授权",
})
export class HipmDnsmgrAccess extends BaseAccess {
@AccessInput({
title: '服务器地址',
title: "服务器地址",
component: {
name: 'a-input',
name: "a-input",
allowClear: true,
placeholder: 'http://localhost:3001',
placeholder: "http://localhost:3001",
},
required: true,
helper: 'HiPM DNSMgr 服务器地址,例如: http://localhost:3001',
helper: "HiPM DNSMgr 服务器地址,例如: http://localhost:3001",
})
endpoint = '';
endpoint = "";
@AccessInput({
title: 'API Token',
title: "API Token",
required: true,
encrypt: true,
helper: '在 DNSMgr 设置 > API Token 中创建的令牌',
helper: "在 DNSMgr 设置 > API Token 中创建的令牌",
})
apiToken = '';
apiToken = "";
@AccessInput({
title: '测试连接',
title: "测试连接",
component: {
name: 'api-test',
action: 'TestRequest',
name: "api-test",
action: "TestRequest",
},
helper: '点击测试接口是否正常',
helper: "点击测试接口是否正常",
})
testRequest = true;
async onTestRequest() {
await this.getDomainList();
return '连接成功';
return "连接成功";
}
/**
@@ -51,10 +51,10 @@ export class HipmDnsmgrAccess extends BaseAccess {
*/
async getDomainList() {
this.ctx.logger.info(`[HiPM DNSMgr] 获取域名列表`);
const resp = await this.doRequest({
method: 'GET',
path: '/domains',
method: "GET",
path: "/domains",
params: {
page: 1,
pageSize: 100,
@@ -62,11 +62,13 @@ export class HipmDnsmgrAccess extends BaseAccess {
});
// DNSMgr 返回数组格式
return resp?.map((item: any) => ({
id: String(item.id),
domain: item.name,
...item,
})) || [];
return (
resp?.map((item: any) => ({
id: String(item.id),
domain: item.name,
...item,
})) || []
);
}
/**
@@ -74,14 +76,14 @@ export class HipmDnsmgrAccess extends BaseAccess {
*/
async getDomainRecords(domainId: string, params?: { type?: string; subdomain?: string; value?: string }) {
this.ctx.logger.info(`[HiPM DNSMgr] 获取域名记录列表:domainId=${domainId}`);
let path = `/domains/${domainId}/records?page=1&pageSize=100`;
if (params?.type) path += `&type=${encodeURIComponent(params.type)}`;
if (params?.subdomain) path += `&subdomain=${encodeURIComponent(params.subdomain)}`;
if (params?.value) path += `&value=${encodeURIComponent(params.value)}`;
const resp = await this.doRequest({
method: 'GET',
method: "GET",
path,
});
@@ -93,16 +95,16 @@ export class HipmDnsmgrAccess extends BaseAccess {
*/
async createDnsRecord(domainId: string, name: string, value: string, type: string) {
this.ctx.logger.info(`[HiPM DNSMgr] 创建DNS记录:${name} ${type} ${value}`);
const resp = await this.doRequest({
method: 'POST',
method: "POST",
path: `/domains/${domainId}/records`,
data: {
name,
type,
value,
ttl: 600,
line: '0',
line: "0",
},
});
@@ -114,9 +116,9 @@ export class HipmDnsmgrAccess extends BaseAccess {
*/
async deleteDnsRecord(domainId: string, recordId: string) {
this.ctx.logger.info(`[HiPM DNSMgr] 删除DNS记录:domainId=${domainId}, recordId=${recordId}`);
const resp = await this.doRequest({
method: 'DELETE',
method: "DELETE",
path: `/domains/${domainId}/records/${recordId}`,
});
@@ -129,16 +131,16 @@ export class HipmDnsmgrAccess extends BaseAccess {
async doRequest(req: { method: string; path: string; data?: any; params?: any }) {
// 处理 URL
let baseUrl = this.endpoint.trim();
baseUrl = baseUrl.replace(/\/$/, '');
baseUrl = baseUrl.replace(/\/api$/, '');
baseUrl = baseUrl.replace(/\/$/, "");
baseUrl = baseUrl.replace(/\/api$/, "");
let url = `${baseUrl}/api${req.path}`;
// 添加查询参数
if (req.params) {
const searchParams = new URLSearchParams();
for (const [key, value] of Object.entries(req.params)) {
if (value !== undefined && value !== null && value !== '') {
if (value !== undefined && value !== null && value !== "") {
searchParams.append(key, String(value));
}
}
@@ -154,8 +156,8 @@ export class HipmDnsmgrAccess extends BaseAccess {
url,
method: req.method,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiToken}`,
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiToken}`,
},
data: req.data,
});
@@ -164,7 +166,7 @@ export class HipmDnsmgrAccess extends BaseAccess {
// DNSMgr API 返回格式: { code: 0, data: ..., msg: ... }
if (res.code !== undefined && res.code !== 0) {
throw new Error(res.msg || '请求失败');
throw new Error(res.msg || "请求失败");
}
return res.data;
@@ -1 +1 @@
export * from './hipmdnsmgr-access.js';
export * from "./hipmdnsmgr-access.js";
@@ -1,23 +1,23 @@
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
import { HipmDnsmgrAccess } from '../access/hipmdnsmgr-access.js';
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
import { HipmDnsmgrAccess } from "../access/hipmdnsmgr-access.js";
/**
* HiPM DNSMgr DNS Provider
* 用于 ACME DNS-01 挑战验证
*/
@IsDnsProvider({
name: 'hipmdnsmgr',
title: 'HiPM DNSMgr',
desc: 'HiPM DNSMgr DNS 解析提供商',
accessType: 'hipmdnsmgr',
icon: 'svg:icon-dns',
name: "hipmdnsmgr",
title: "HiPM DNSMgr",
desc: "HiPM DNSMgr DNS 解析提供商",
accessType: "hipmdnsmgr",
icon: "svg:icon-dns",
})
export class HipmDnsmgrDnsProvider extends AbstractDnsProvider<{ domainId: string; recordId: string; name: string; value: string }> {
access!: HipmDnsmgrAccess;
async onInstance() {
this.access = this.ctx.access as HipmDnsmgrAccess;
this.logger.debug('[HiPM DNSMgr] 初始化完成');
this.logger.debug("[HiPM DNSMgr] 初始化完成");
}
/**
@@ -25,7 +25,7 @@ export class HipmDnsmgrDnsProvider extends AbstractDnsProvider<{ domainId: strin
*/
async createRecord(options: CreateRecordOptions): Promise<any> {
const { fullRecord, hostRecord, value, type, domain } = options;
this.logger.info('[HiPM DNSMgr] 添加域名解析:', fullRecord, value, type, domain);
this.logger.info("[HiPM DNSMgr] 添加域名解析:", fullRecord, value, type, domain);
// 1. 获取域名列表,找到对应的域名 ID
const domainList = await this.access.getDomainList();
@@ -36,13 +36,13 @@ export class HipmDnsmgrDnsProvider extends AbstractDnsProvider<{ domainId: strin
}
const domainId = String(domainInfo.id);
this.logger.debug('[HiPM DNSMgr] 找到域名:', domain, 'ID:', domainId);
this.logger.debug("[HiPM DNSMgr] 找到域名:", domain, "ID:", domainId);
// 2. 创建 DNS 记录
const name = hostRecord; // 使用子域名,如 _acme-challenge
const res = await this.access.createDnsRecord(domainId, name, value, type);
this.logger.info('[HiPM DNSMgr] 添加域名解析成功:', JSON.stringify(options), res?.id);
this.logger.info("[HiPM DNSMgr] 添加域名解析成功:", JSON.stringify(options), res?.id);
// 返回记录信息,用于后续删除
return {
@@ -60,18 +60,18 @@ export class HipmDnsmgrDnsProvider extends AbstractDnsProvider<{ domainId: strin
const { fullRecord, value } = options.recordReq;
const record = options.recordRes;
this.logger.info('[HiPM DNSMgr] 删除域名解析:', fullRecord, value, record);
this.logger.info("[HiPM DNSMgr] 删除域名解析:", fullRecord, value, record);
if (record && record.domainId && record.recordId) {
try {
await this.access.deleteDnsRecord(record.domainId, record.recordId);
this.logger.info('[HiPM DNSMgr] 删除域名解析成功:', fullRecord, value);
this.logger.info("[HiPM DNSMgr] 删除域名解析成功:", fullRecord, value);
} catch (e: any) {
// 记录可能已经被删除,忽略错误
this.logger.warn('[HiPM DNSMgr] 删除域名解析失败(可能已不存在):', e.message);
this.logger.warn("[HiPM DNSMgr] 删除域名解析失败(可能已不存在):", e.message);
}
} else {
this.logger.warn('[HiPM DNSMgr] 无法删除记录,缺少 domainId 或 recordId');
this.logger.warn("[HiPM DNSMgr] 无法删除记录,缺少 domainId 或 recordId");
}
}
}
@@ -1 +1 @@
export * from './hipmdnsmgr-dns-provider.js';
export * from "./hipmdnsmgr-dns-provider.js";
@@ -1,2 +1,2 @@
export * from './access/index.js';
export * from './dns-provider/index.js';
export * from "./access/index.js";
export * from "./dns-provider/index.js";