chore(cert): add md5 hash naming and duplicate cert handling

1. 新增buildCertName方法的useHash参数,使用域名列表MD5哈希作为证书名后缀避免时间戳重复
2. 为asiaisp上传证书添加重复证书检测逻辑,已存在时直接复用已有证书
This commit is contained in:
xiaojunnuo
2026-06-25 23:12:38 +08:00
parent b48831e60b
commit eeb83f9024
2 changed files with 40 additions and 16 deletions
@@ -280,9 +280,14 @@ export class CertReader {
return `${prefix}_${domain}_${timeStr}.${suffix}`;
}
buildCertName(prefix: string = "") {
buildCertName(prefix: string = "", useHash: boolean = false) {
let domain = this.getMainDomain();
domain = domain.replaceAll(".", "_").replaceAll("*", "_");
if (useHash) {
const domains = JSON.stringify(this.getAllDomains());
const hash = cryptoLib.createHash("md5").update(domains).digest("hex").slice(0, 16);
return `${prefix}_${domain}_${hash}`;
}
return `${prefix}_${domain}_${dayjs().format("YYYYMMDDHHmmssSSS")}`;
}
@@ -293,7 +298,7 @@ export class CertReader {
return name + "_" + dayjs().format("YYYYMMDDHHmmssSSS");
}
static buildCertName(cert: CertInfo) {
return new CertReader(cert).buildCertName();
static buildCertName(cert: CertInfo, useHash: boolean = false) {
return new CertReader(cert).buildCertName("", useHash);
}
}