perf: 优化宝塔报错提示

This commit is contained in:
xiaojunnuo
2026-07-21 14:13:07 +08:00
parent c8c269f612
commit 1cfa76683b
2 changed files with 32 additions and 19 deletions
@@ -1,15 +1,17 @@
import crypto from "node:crypto";
import { BaotaAccess } from "../access.js";
import { HttpClient, HttpRequestConfig } from "@certd/basic";
import { HttpClient, HttpRequestConfig, ILogger } from "@certd/basic";
import * as querystring from "node:querystring";
export class BaotaClient {
access: BaotaAccess;
http: HttpClient;
logger: ILogger
constructor(access: BaotaAccess, http: HttpClient) {
this.access = access;
this.http = http;
this.logger = access.ctx.logger;
}
//将以上 java代码 翻译成nodejs 代码
@@ -88,7 +88,7 @@ export class BaotaDeployWebSiteCert extends AbstractTaskPlugin {
})
siteName!: string | string[];
async onInstance() {}
async onInstance() { }
async execute(): Promise<void> {
const { cert, accessId } = this;
const access = await this.getAccess(accessId);
@@ -104,26 +104,37 @@ export class BaotaDeployWebSiteCert extends AbstractTaskPlugin {
}
const lockKey = `baota-lock-${accessId}`;
if (this.isDockerSite) {
this.logger.info(`当前已勾选docker站点(如果部署失败,请确认站点:${siteNames} 是否全部为docker站点)`);
}
for (const site of siteNames) {
// 加锁,防止并发部署证书, 宝塔并发部署会导致nginx的conf错乱
await this.ctx.utils.locker.execute(lockKey, async () => {
this.logger.info(`为站点:${site}设置证书,目前支持宝塔网站站点、docker站点`);
if (this.isDockerSite) {
const res = await client.doRequest("/mod/docker/com/set_ssl", "", {
site_name: site,
key: cert.key,
csr: cert.crt,
});
this.logger.info(res?.msg);
} else {
const res = await client.doRequest("/site", "SetSSL", {
type: 0,
siteName: site,
key: cert.key,
csr: cert.crt,
});
this.logger.info(res?.msg);
try {
if (this.isDockerSite) {
this.logger.info(`为Docker站点:${site} 设置证书`);
const res = await client.doRequest("/mod/docker/com/set_ssl", "", {
site_name: site,
key: cert.key,
csr: cert.crt,
});
this.logger.info(res?.msg);
} else {
this.logger.info(`为非Docker站点:${site} 设置证书`);
const res = await client.doRequest("/site", "SetSSL", {
type: 0,
siteName: site,
key: cert.key,
csr: cert.crt,
});
this.logger.info(res?.msg);
}
} catch (e: any) {
if (e?.message?.includes("没有服务器配置文件")) {
this.logger.error(e.message);
this.logger.warn(`首先请确认站点 ${site} 是否存在,如果存在,请到宝塔上手动保存一下该站点证书试试`);
}
throw e
}
});
}