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,45 +1,44 @@
import { AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch } from '@certd/pipeline';
import { AccessInput, BaseAccess, IsAccess, Pager, PageRes, PageSearch } from "@certd/pipeline";
/**
* Next Terminal 授权配置
*/
@IsAccess({
name: 'nextTerminal',
title: 'Next Terminal 授权',
icon: 'clarity:plugin-line',
desc: '用于访问 Next Terminal API 的授权配置',
name: "nextTerminal",
title: "Next Terminal 授权",
icon: "clarity:plugin-line",
desc: "用于访问 Next Terminal API 的授权配置",
})
export class NextTerminalAccess extends BaseAccess {
/**
* Next Terminal 系统地址
*/
@AccessInput({
title: '系统地址',
title: "系统地址",
component: {
name: "a-input",
allowClear: true,
placeholder: 'https://nt.example.com:8088',
placeholder: "https://nt.example.com:8088",
},
required: true,
})
baseUrl = '';
baseUrl = "";
/**
* API 令牌
*/
@AccessInput({
title: 'API 令牌',
helper: '个人中心->授权令牌->创建令牌',
title: "API 令牌",
helper: "个人中心->授权令牌->创建令牌",
component: {
name: "a-input",
allowClear: true,
placeholder: 'NT_xxxxx',
placeholder: "NT_xxxxx",
},
required: true,
encrypt: true,
})
apiToken = '';
apiToken = "";
/**
* 测试按钮
@@ -48,9 +47,9 @@ export class NextTerminalAccess extends BaseAccess {
title: "测试",
component: {
name: "api-test",
action: "TestRequest"
action: "TestRequest",
},
helper: "点击测试接口是否正常"
helper: "点击测试接口是否正常",
})
testRequest = true;
@@ -69,66 +68,56 @@ export class NextTerminalAccess extends BaseAccess {
this.ctx.logger.info(`获取 Next Terminal 证书列表,req:${JSON.stringify(req)}`);
const pager = new Pager(req);
const resp = await this.doRequest({
url: '/api/admin/certificates/paging',
method: 'GET',
url: "/api/admin/certificates/paging",
method: "GET",
params: {
pageIndex: pager.pageNo,
pageSize: pager.pageSize,
sortOrder: 'ascend',
sortField: 'notAfter',
}
sortOrder: "ascend",
sortField: "notAfter",
},
});
const total = resp?.total || 0;
const list = resp?.items || [];
return {
total,
list
list,
};
}
/**
* 更新证书
*/
async UpdateCertificate(req: {
certId: string;
commonName: string;
crt: string;
key: string;
}) {
async UpdateCertificate(req: { certId: string; commonName: string; crt: string; key: string }) {
this.ctx.logger.info(`更新 Next Terminal 证书,certId:${req.certId}, commonName:${req.commonName}`);
await this.doRequest({
url: `/api/admin/certificates/${req.certId}`,
method: 'PUT',
method: "PUT",
data: {
commonName: req.commonName,
type: 'imported',
type: "imported",
id: req.certId,
certificate: req.crt,
privateKey: req.key,
renewBefore: 30,
}
},
});
}
/**
* 通用 API 调用方法
*/
async doRequest(req: {
url: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
params?: any;
data?: any;
}) {
async doRequest(req: { url: string; method: "GET" | "POST" | "PUT" | "DELETE"; params?: any; data?: any }) {
const headers = {
'X-Auth-Token': `${this.apiToken}`,
'Content-Type': 'application/json',
"X-Auth-Token": `${this.apiToken}`,
"Content-Type": "application/json",
};
const baseUrl = this.normalizeEndpoint(this.baseUrl);
this.ctx.logger.debug(`Next Terminal API 请求: ${req.method} ${baseUrl}${req.url}`);
const resp = await this.ctx.http.request({
url: req.url,
baseURL: baseUrl,
@@ -139,11 +128,11 @@ export class NextTerminalAccess extends BaseAccess {
validateStatus: () => true, // 不自动抛出异常,让我们自己处理
});
if (resp.code >0) {
if (resp.code > 0) {
throw new Error(resp.message);
}
return resp
}
return resp;
}
}
new NextTerminalAccess()
new NextTerminalAccess();
@@ -1,2 +1,2 @@
export * from './access.js';
export * from './plugins/index.js';
export * from "./access.js";
export * from "./plugins/index.js";
@@ -1 +1 @@
export * from './plugin-refresh-cert.js';
export * from "./plugin-refresh-cert.js";
@@ -1,12 +1,12 @@
import { AbstractTaskPlugin, IsTaskPlugin, PageSearch, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
import { CertInfo } from '@certd/plugin-cert';
import { CertReader, createRemoteSelectInputDefine } from '@certd/plugin-lib';
import { AbstractTaskPlugin, IsTaskPlugin, PageSearch, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
import { CertInfo } from "@certd/plugin-cert";
import { CertReader, createRemoteSelectInputDefine } from "@certd/plugin-lib";
@IsTaskPlugin({
name: 'NextTerminalRefreshCert',
title: 'NextTerminal-更新证书',
icon: 'clarity:plugin-line',
desc: '更新 Next Terminal 证书',
name: "NextTerminalRefreshCert",
title: "NextTerminal-更新证书",
icon: "clarity:plugin-line",
desc: "更新 Next Terminal 证书",
group: pluginGroups.panel.key,
default: {
strategy: {
@@ -19,11 +19,11 @@ export class NextTerminalRefreshCert extends AbstractTaskPlugin {
* 证书选择
*/
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
title: "域名证书",
helper: "请选择前置任务输出的域名证书",
component: {
name: 'output-selector',
from: ['CertApply'],
name: "output-selector",
from: ["CertApply"],
},
required: true,
})
@@ -33,11 +33,11 @@ export class NextTerminalRefreshCert extends AbstractTaskPlugin {
* Next Terminal 授权
*/
@TaskInput({
title: 'Next Terminal 授权',
helper: '选择 Next Terminal 授权配置',
title: "Next Terminal 授权",
helper: "选择 Next Terminal 授权配置",
component: {
name: 'access-selector',
type: 'nextTerminal',
name: "access-selector",
type: "nextTerminal",
},
required: true,
})
@@ -48,10 +48,10 @@ export class NextTerminalRefreshCert extends AbstractTaskPlugin {
*/
@TaskInput(
createRemoteSelectInputDefine({
title: '选择证书',
helper: '选择要更新的 Next Terminal 证书(支持多选),如果这里没有列出,需要先前往控制台上传证书,之后就可以自动更新',
title: "选择证书",
helper: "选择要更新的 Next Terminal 证书(支持多选),如果这里没有列出,需要先前往控制台上传证书,之后就可以自动更新",
action: NextTerminalRefreshCert.prototype.onGetCertList.name,
watches: ['accessId'],
watches: ["accessId"],
required: true,
single: false,
})
@@ -63,10 +63,10 @@ export class NextTerminalRefreshCert extends AbstractTaskPlugin {
*/
async onGetCertList(req: PageSearch) {
if (!this.accessId) {
throw new Error('请选择 Next Terminal 授权');
throw new Error("请选择 Next Terminal 授权");
}
const access = await this.getAccess(this.accessId) as any;
const access = (await this.getAccess(this.accessId)) as any;
const certList = await access.GetCertificateList(req);
const options = certList.list.map((item: any) => {
@@ -87,31 +87,31 @@ export class NextTerminalRefreshCert extends AbstractTaskPlugin {
const { cert, accessId, certIds } = this;
try {
const access = await this.getAccess(accessId) as any;
const access = (await this.getAccess(accessId)) as any;
// 确保 certIds 是数组
const ids = Array.isArray(certIds) ? certIds : [certIds];
const certReader = new CertReader(cert);
const mainDomain = certReader.getMainDomain();
for (const certId of ids) {
this.logger.info(`更新 Next Terminal 证书: ${certId}`);
await access.UpdateCertificate({
certId,
commonName: mainDomain,
crt: cert.crt,
key: cert.key,
});
this.logger.info(`证书 ${certId} 更新成功`);
}
this.logger.info(`成功更新 ${ids.length} 个 Next Terminal 证书`);
} catch (e) {
this.logger.error('更新 Next Terminal 证书失败', e);
this.logger.error("更新 Next Terminal 证书失败", e);
throw e;
}
}
}
}