mirror of
https://github.com/certd/certd.git
synced 2025-11-25 09:10:11 +08:00
perf: 支持http校验方式申请证书
This commit is contained in:
@@ -7,6 +7,7 @@ import { SshAccess } from "./ssh-access.js";
|
||||
import stripAnsi from "strip-ansi";
|
||||
import { SocksClient } from "socks";
|
||||
import { SocksProxy, SocksProxyType } from "socks/typings/common/constants.js";
|
||||
export type TransportItem = { localPath: string; remotePath: string };
|
||||
|
||||
export class AsyncSsh2Client {
|
||||
conn: ssh2.Client;
|
||||
@@ -95,6 +96,21 @@ export class AsyncSsh2Client {
|
||||
});
|
||||
}
|
||||
|
||||
async unlink(options: { sftp: any; remotePath: string }) {
|
||||
const { sftp, remotePath } = options;
|
||||
return new Promise((resolve, reject) => {
|
||||
this.logger.info(`开始删除远程文件:${remotePath}`);
|
||||
sftp.unlink(remotePath, (err: Error) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
this.logger.info(`删除文件成功:${remotePath}`);
|
||||
resolve({});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async exec(
|
||||
script: string,
|
||||
opts: {
|
||||
@@ -239,7 +255,7 @@ export class SshClient {
|
||||
}
|
||||
* @param options
|
||||
*/
|
||||
async uploadFiles(options: { connectConf: SshAccess; transports: any; mkdirs: boolean }) {
|
||||
async uploadFiles(options: { connectConf: SshAccess; transports: TransportItem[]; mkdirs: boolean }) {
|
||||
const { connectConf, transports, mkdirs } = options;
|
||||
await this._call({
|
||||
connectConf,
|
||||
@@ -272,6 +288,24 @@ export class SshClient {
|
||||
});
|
||||
}
|
||||
|
||||
async removeFiles(opts: { connectConf: SshAccess; files: string[] }) {
|
||||
const { connectConf, files } = opts;
|
||||
await this._call({
|
||||
connectConf,
|
||||
callable: async (conn: AsyncSsh2Client) => {
|
||||
const sftp = await conn.getSftp();
|
||||
this.logger.info("开始删除");
|
||||
for (const file of files) {
|
||||
await conn.unlink({
|
||||
sftp,
|
||||
remotePath: file,
|
||||
});
|
||||
}
|
||||
this.logger.info("文件全部删除成功");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async isCmd(conn: AsyncSsh2Client) {
|
||||
const spec = await conn.exec("echo %COMSPEC% ");
|
||||
if (spec.toString().trim() === "%COMSPEC%") {
|
||||
|
||||
Reference in New Issue
Block a user