From 335cf9397080a5e09074d5a89d03f59bd051cda5 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Fri, 7 Nov 2025 01:46:44 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20doge=E4=BA=91=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=87=E6=9C=9F=E8=AF=81=E4=B9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/plugins/plugin-doge/lib/index.ts | 7 ++++-- .../plugins/deploy-to-cdn/index.ts | 25 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/ui/certd-server/src/plugins/plugin-doge/lib/index.ts b/packages/ui/certd-server/src/plugins/plugin-doge/lib/index.ts index 977553ac..9c6ca471 100644 --- a/packages/ui/certd-server/src/plugins/plugin-doge/lib/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-doge/lib/index.ts @@ -1,16 +1,18 @@ import crypto from 'crypto'; import querystring from 'querystring'; import { DogeCloudAccess } from '../access.js'; -import { HttpClient } from '@certd/basic'; +import { HttpClient, ILogger } from '@certd/basic'; export class DogeClient { accessKey: string; secretKey: string; http: HttpClient; - constructor(access: DogeCloudAccess, http: HttpClient) { + logger: ILogger; + constructor(access: DogeCloudAccess, http: HttpClient,logger: ILogger) { this.accessKey = access.accessKey; this.secretKey = access.secretKey; this.http = http; + this.logger = logger; } async request(apiPath: string, data: any = {}, jsonMode = false, ignoreResNullCode = false) { @@ -36,6 +38,7 @@ export class DogeClient { if (res.code == null && ignoreResNullCode) { //ignore + this.logger.warn('执行出错:', res); } else if (res.code !== 200) { throw new Error('API Error: ' + res.msg); } diff --git a/packages/ui/certd-server/src/plugins/plugin-doge/plugins/deploy-to-cdn/index.ts b/packages/ui/certd-server/src/plugins/plugin-doge/plugins/deploy-to-cdn/index.ts index 5ca381e7..e5f0bbd0 100644 --- a/packages/ui/certd-server/src/plugins/plugin-doge/plugins/deploy-to-cdn/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-doge/plugins/deploy-to-cdn/index.ts @@ -68,7 +68,7 @@ export class DogeCloudDeployToCDNPlugin extends AbstractTaskPlugin { async onInstance() { const access = await this.getAccess(this.accessId); - this.dogeClient = new DogeClient(access, this.ctx.http); + this.dogeClient = new DogeClient(access, this.ctx.http, this.ctx.logger); } async execute(): Promise { const certId: number = await this.updateCert(); @@ -81,7 +81,10 @@ export class DogeCloudDeployToCDNPlugin extends AbstractTaskPlugin { this.ctx.logger.info(`绑定证书${certId}到域名${domain}`); await this.bindCert(certId,domain); } - this.logger.info("执行完成") + this.logger.info("执行完成,3秒后删除过期证书"); + + await this.ctx.utils.sleep(3000); + await this.clearExpiredCert(); } async updateCert() { @@ -104,6 +107,24 @@ export class DogeCloudDeployToCDNPlugin extends AbstractTaskPlugin { ); } + async clearExpiredCert() { + const res = await this.dogeClient.request( + '/cdn/cert/list.json', + {}, + ); + const list = res.certs?.filter((item: any) => item.expire < dayjs().unix() && item.domainCount === 0) || []; + for (const item of list) { + this.ctx.logger.info(`删除过期证书${item.id}->${item.domain}`); + await this.dogeClient.request( + '/cdn/cert/delete.json', + { + id: item.id, + }, + this.ignoreDeployNullCode + ); + } + } + async onGetDomainList(data: PageSearch = {}) { const res = await this.dogeClient.request(