mirror of
https://github.com/certd/certd.git
synced 2026-07-13 17:07:32 +08:00
chore: format
This commit is contained in:
+43
-41
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user