mirror of
https://github.com/certd/certd.git
synced 2026-08-03 12:05:06 +08:00
perf: 优化宝塔报错提示
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
import { BaotaAccess } from "../access.js";
|
import { BaotaAccess } from "../access.js";
|
||||||
import { HttpClient, HttpRequestConfig } from "@certd/basic";
|
import { HttpClient, HttpRequestConfig, ILogger } from "@certd/basic";
|
||||||
import * as querystring from "node:querystring";
|
import * as querystring from "node:querystring";
|
||||||
|
|
||||||
export class BaotaClient {
|
export class BaotaClient {
|
||||||
access: BaotaAccess;
|
access: BaotaAccess;
|
||||||
http: HttpClient;
|
http: HttpClient;
|
||||||
|
logger: ILogger
|
||||||
|
|
||||||
constructor(access: BaotaAccess, http: HttpClient) {
|
constructor(access: BaotaAccess, http: HttpClient) {
|
||||||
this.access = access;
|
this.access = access;
|
||||||
this.http = http;
|
this.http = http;
|
||||||
|
this.logger = access.ctx.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
//将以上 java代码 翻译成nodejs 代码
|
//将以上 java代码 翻译成nodejs 代码
|
||||||
|
|||||||
+29
-18
@@ -88,7 +88,7 @@ export class BaotaDeployWebSiteCert extends AbstractTaskPlugin {
|
|||||||
})
|
})
|
||||||
siteName!: string | string[];
|
siteName!: string | string[];
|
||||||
|
|
||||||
async onInstance() {}
|
async onInstance() { }
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const { cert, accessId } = this;
|
const { cert, accessId } = this;
|
||||||
const access = await this.getAccess(accessId);
|
const access = await this.getAccess(accessId);
|
||||||
@@ -104,26 +104,37 @@ export class BaotaDeployWebSiteCert extends AbstractTaskPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const lockKey = `baota-lock-${accessId}`;
|
const lockKey = `baota-lock-${accessId}`;
|
||||||
|
if (this.isDockerSite) {
|
||||||
|
this.logger.info(`当前已勾选docker站点(如果部署失败,请确认站点:${siteNames}, 是否全部为docker站点)`);
|
||||||
|
}
|
||||||
for (const site of siteNames) {
|
for (const site of siteNames) {
|
||||||
// 加锁,防止并发部署证书, 宝塔并发部署会导致nginx的conf错乱
|
// 加锁,防止并发部署证书, 宝塔并发部署会导致nginx的conf错乱
|
||||||
await this.ctx.utils.locker.execute(lockKey, async () => {
|
await this.ctx.utils.locker.execute(lockKey, async () => {
|
||||||
this.logger.info(`为站点:${site}设置证书,目前支持宝塔网站站点、docker站点`);
|
try {
|
||||||
if (this.isDockerSite) {
|
if (this.isDockerSite) {
|
||||||
const res = await client.doRequest("/mod/docker/com/set_ssl", "", {
|
this.logger.info(`为Docker站点:${site} 设置证书`);
|
||||||
site_name: site,
|
const res = await client.doRequest("/mod/docker/com/set_ssl", "", {
|
||||||
key: cert.key,
|
site_name: site,
|
||||||
csr: cert.crt,
|
key: cert.key,
|
||||||
});
|
csr: cert.crt,
|
||||||
this.logger.info(res?.msg);
|
});
|
||||||
} else {
|
this.logger.info(res?.msg);
|
||||||
const res = await client.doRequest("/site", "SetSSL", {
|
} else {
|
||||||
type: 0,
|
this.logger.info(`为非Docker站点:${site} 设置证书`);
|
||||||
siteName: site,
|
const res = await client.doRequest("/site", "SetSSL", {
|
||||||
key: cert.key,
|
type: 0,
|
||||||
csr: cert.crt,
|
siteName: site,
|
||||||
});
|
key: cert.key,
|
||||||
this.logger.info(res?.msg);
|
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
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user