@bprotsyk/aso-core 2.0.53 → 2.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,292 +1,303 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ServerUtil = exports.PORT = exports.HOST = exports.PASSWORD = exports.IP = void 0;
7
- const node_ssh_1 = require("node-ssh");
8
- const child_process_1 = __importDefault(require("child_process"));
9
- const ssh2_sftp_client_1 = __importDefault(require("ssh2-sftp-client"));
10
- const fs_1 = __importDefault(require("fs"));
11
- const mustache_1 = __importDefault(require("mustache"));
12
- const path_1 = __importDefault(require("path"));
13
- const unzipper_1 = __importDefault(require("unzipper"));
14
- const { promisify } = require("util");
15
- const execPromise = promisify(child_process_1.default.exec);
16
- exports.IP = "185.123.53.227";
17
- exports.PASSWORD = "xUA3oOX06Kfc9m12rZ";
18
- exports.HOST = "cg-main-server.com";
19
- exports.PORT = 56777;
20
- class ServerUtil {
21
- DOMAIN_HOME = "/etc/nginx/sites-enabled";
22
- ssh;
23
- sftpConfig;
24
- constructor(sftpConfig) {
25
- this.ssh = new node_ssh_1.NodeSSH();
26
- this.sftpConfig = sftpConfig;
27
- }
28
- async connectSSH() {
29
- await this?.ssh?.connect({
30
- host: this?.sftpConfig?.host,
31
- port: this?.sftpConfig?.port,
32
- username: this?.sftpConfig?.username,
33
- password: this?.sftpConfig?.password,
34
- });
35
- }
36
- async ensureConnected() {
37
- if (!this?.ssh?.isConnected()) {
38
- await this.connectSSH(); // Підключення, якщо ще не підключено
39
- }
40
- }
41
- // Выконує команду або по SSH або локально, повертаючи текст незалежно від результату (помилка чи успіх)
42
- async exec(command, options) {
43
- await this.ensureConnected();
44
- if (this?.ssh?.isConnected()) {
45
- return (await this?.ssh?.execCommand(command, options)).stdout;
46
- }
47
- else {
48
- return await new Promise((resolve) => {
49
- execPromise(command, (err, stdout) => {
50
- resolve(stdout);
51
- });
52
- });
53
- }
54
- }
55
- // SSH
56
- async generateSSHKey() {
57
- await this.exec(`ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa <<< n`);
58
- let sshFingerprint = await this.exec(`cat ~/.ssh/id_rsa.pub`);
59
- return sshFingerprint;
60
- }
61
- // create Directories in /Var
62
- async createDirectories() {
63
- await this.exec(`mkdir -p /var/www/ai`);
64
- }
65
- // install git
66
- async installGit() {
67
- await this.exec(`apt-get update; apt-get install -y git`);
68
- }
69
- // add ssh to bitbucket
70
- async addBitbucketToKnownHosts() {
71
- await this.exec(`ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts`);
72
- }
73
- // clone bitbucket Repository
74
- async cloneRepository(repoName, targetPath) {
75
- let gitResponse = await this.exec(`git clone git@bitbucket.org:bprtsk/${repoName}.git`, { cwd: targetPath });
76
- if (gitResponse.includes(`Please make sure you have the correct access rights`)) {
77
- throw new Error(`No access to the remote repository!`);
78
- }
79
- }
80
- // не знаю чи треба але додав ?
81
- // async checkoutBranch(branch: string, repoPath: string): Promise<void> {
82
- // await this.exec(`git checkout -b ${branch}; git branch --set-upstream-to=origin/${branch} ${branch}; git reset --hard origin/${branch};`, { cwd: repoPath });
83
- // }
84
- // не знаю чи треба але додав ?
85
- // async installJava(): Promise<void> {
86
- // await this.exec(`apt-get update; apt-get install -y default-jre default-jdk`);
87
- // }
88
- // install Nginx
89
- async installNginx() {
90
- await this.exec(`apt-get update; apt-get install -y nginx`);
91
- await this.exec(`systemctl enable nginx`);
92
- await this.exec(`systemctl start nginx`);
93
- }
94
- // Nginx
95
- async isNginxActive() {
96
- try {
97
- let result = await this.exec("systemctl status nginx");
98
- if (result.includes("Active: active"))
99
- return true;
100
- }
101
- catch (e) {
102
- console.error(e);
103
- }
104
- return false;
105
- }
106
- // Mongo
107
- async isMongoActive() {
108
- try {
109
- let result = await this.exec("systemctl status mongod");
110
- if (result.includes("Active: active"))
111
- return true;
112
- }
113
- catch (e) {
114
- console.error(e);
115
- }
116
- return false;
117
- }
118
- mongoInstallCommand = `
119
- echo "deb http://security.ubuntu.com/ubuntu focal-security main" | tee /etc/apt/sources.list.d/focal-security.list;
120
- apt-get update;
121
- apt-get install libssl1.1;
122
- rm /etc/apt/sources.list.d/focal-security.list;
123
-
124
- curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -;
125
- echo "deb http://security.ubuntu.com/ubuntu impish-security main" | tee /etc/apt/sources.list.d/impish-security.list;
126
- echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list;
127
- apt-get update;
128
- apt-get install -y mongodb-org;
129
- systemctl enable mongod.service;
130
- systemctl start mongod;
131
- `;
132
- // checking if nginx configuration exists
133
- async domainNginxConfigExists(host) {
134
- try {
135
- let result = await this.exec(`ls ${this.DOMAIN_HOME}/${host}.nginx.ssl.conf`);
136
- if (result.includes("No such file or directory"))
137
- return false;
138
- }
139
- catch (e) {
140
- console.error(e);
141
- }
142
- return true;
143
- }
144
- // checking if the ssl certificate exists
145
- async domainNginxCertsExist(host) {
146
- try {
147
- let result = await this.exec(`ls /etc/letsencrypt/live/${host}`);
148
- if (result.includes("No such file or directory"))
149
- return false;
150
- }
151
- catch (e) {
152
- console.error(e);
153
- }
154
- return true;
155
- }
156
- // Certbot CRON
157
- async isCerbotActive() {
158
- try {
159
- let result = await this.exec("which certbot");
160
- if (result.includes("/usr/bin/certbot"))
161
- return true;
162
- }
163
- catch (e) {
164
- console.error(e);
165
- }
166
- return false;
167
- }
168
- // install certbot
169
- async setupCertbot() {
170
- await this?.ssh?.execCommand(`apt-get install -y certbot python3-certbot-nginx;`);
171
- return true;
172
- }
173
- async setupSSL(email, host) {
174
- // Прямий виклик this?.ssh?.execCommand
175
- let certbotResponse = await this?.ssh?.execCommand(`certbot --non-interactive --agree-tos --nginx -m "${email}" -d "${host}"`);
176
- if (certbotResponse?.stdout.includes(`Some challenges have failed.`)) {
177
- throw new Error("Certbot encountered an error");
178
- }
179
- await this?.ssh?.execCommand(`echo "0 12 * * * /usr/bin/certbot renew --quiet" | crontab -`);
180
- }
181
- // Git
182
- async refresh() {
183
- await this.exec(`git stash; rm-rf built; git pull`);
184
- return true;
185
- }
186
- async uploadDirectoryToSftp(localPath, remotePath, sftpConfig) {
187
- const sftp = new ssh2_sftp_client_1.default();
188
- try {
189
- await sftp.connect(sftpConfig);
190
- const stats = fs_1.default.statSync(localPath);
191
- if (stats.isDirectory()) {
192
- // Якщо це директорія
193
- await sftp.mkdir(remotePath, true).catch(async (err) => {
194
- if (err.code !== 4) { // Ігноруємо помилку "Directory already exists"
195
- console.error(`Помилка під час створення папки: ${remotePath}`, err);
196
- throw err;
197
- }
198
- });
199
- const items = fs_1.default.readdirSync(localPath, { withFileTypes: true });
200
- for (const item of items) {
201
- const localItemPath = path_1.default.join(localPath, item.name);
202
- const remoteItemPath = `${remotePath}/${item.name}`;
203
- if (item.isDirectory()) {
204
- await this.uploadDirectoryToSftp(localItemPath, remoteItemPath, sftpConfig);
205
- }
206
- else {
207
- await sftp.put(localItemPath, remoteItemPath);
208
- console.log(`Передано файл: ${localItemPath} -> ${remoteItemPath}`);
209
- }
210
- }
211
- }
212
- else if (stats.isFile()) {
213
- // Якщо це файл
214
- await sftp.put(localPath, remotePath);
215
- console.log(`Передано файл: ${localPath} -> ${remotePath}`);
216
- }
217
- console.log('Усі файли та папки успішно передані.');
218
- }
219
- catch (err) {
220
- console.error('Помилка під час передавання файлів через SFTP:', err);
221
- }
222
- finally {
223
- await sftp.end();
224
- }
225
- }
226
- ensureDirectoryExistence(dirPath) {
227
- if (!fs_1.default.existsSync(dirPath)) {
228
- fs_1.default.mkdirSync(dirPath, { recursive: true });
229
- }
230
- }
231
- async generateNginxConfig(domain, rootPath) {
232
- const templatePath = path_1.default.join(__dirname, "..", "templates", "nginx-template.conf");
233
- const template = fs_1.default.readFileSync(templatePath, "utf8");
234
- let config = mustache_1.default.render(template, { domain, rootPath });
235
- // Заміна закодованих символів назад на їх оригінальні значення
236
- config = config.replace(/&#x2F;/g, '/');
237
- return config;
238
- }
239
- async extractUploadedZip(name, file, extractToPath) {
240
- const zipFilePath = file.path;
241
- const outputDir = path_1.default.join(extractToPath, name);
242
- console.log('Looking for ZIP file at:', zipFilePath);
243
- console.log('Extracting to:', outputDir);
244
- this.ensureDirectoryExistence(outputDir);
245
- if (!fs_1.default.existsSync(zipFilePath)) {
246
- console.error('Error: File not found:', zipFilePath);
247
- return;
248
- }
249
- try {
250
- await new Promise((resolve, reject) => {
251
- fs_1.default.createReadStream(zipFilePath)
252
- .pipe(unzipper_1.default.Parse())
253
- .on('entry', (entry) => {
254
- // Видаляємо перший сегмент шляху, щоб уникнути кореневої директорії
255
- const entryPath = path_1.default.join(outputDir, ...entry.path.split('/').slice(1));
256
- if (entry.type === 'Directory') {
257
- this.ensureDirectoryExistence(entryPath);
258
- }
259
- else {
260
- this.ensureDirectoryExistence(path_1.default.dirname(entryPath));
261
- entry.pipe(fs_1.default.createWriteStream(entryPath));
262
- }
263
- })
264
- .on('close', resolve)
265
- .on('error', reject);
266
- });
267
- console.log('File successfully extracted.');
268
- }
269
- catch (err) {
270
- console.error('Error extracting file:', err);
271
- }
272
- }
273
- async ensureDirectoryExistsViaSSH(remoteDir) {
274
- try {
275
- // Перевірка, чи існує директорія, і створення її, якщо вона не існує
276
- const command = `if [ ! -d "${remoteDir}" ]; then mkdir -p "${remoteDir}"; fi`;
277
- await this?.ssh?.execCommand(command);
278
- console.log(`Перевірено або створено папку: ${remoteDir}`);
279
- }
280
- catch (err) {
281
- console.error('Помилка під час перевірки або створення папки через SSH:', err);
282
- throw err;
283
- }
284
- finally {
285
- this?.ssh?.dispose();
286
- }
287
- }
288
- async disconnectSSH() {
289
- this?.ssh?.dispose();
290
- }
291
- }
292
- exports.ServerUtil = ServerUtil;
2
+ // import { NodeSSH } from "node-ssh";
3
+ // import ChildProcess from "child_process";
4
+ // // import Client from "ssh2-sftp-client";
5
+ // import fs from "fs";
6
+ // import mustache from "mustache";
7
+ // import path from "path";
8
+ // import unzipper from 'unzipper';
9
+ // const { promisify } = require("util");
10
+ // const execPromise = promisify(ChildProcess.exec);
11
+ // export let IP = "185.123.53.227";
12
+ // export let PASSWORD = "xUA3oOX06Kfc9m12rZ";
13
+ // export let HOST = "cg-main-server.com";
14
+ // export let PORT = 56777;
15
+ // interface FileObject {
16
+ // name: string;
17
+ // content: string; // Це буде Base64 закодовані дані
18
+ // }
19
+ // interface ISFTP {
20
+ // host: string;
21
+ // port: number;
22
+ // username: string;
23
+ // password: string;
24
+ // }
25
+ // export class ServerUtil {
26
+ // DOMAIN_HOME = "/etc/nginx/sites-enabled";
27
+ // ssh?: NodeSSH
28
+ // sftpConfig?: ISFTP;
29
+ // constructor(sftpConfig?: ISFTP) {
30
+ // this.ssh = new NodeSSH();
31
+ // this.sftpConfig = sftpConfig;
32
+ // }
33
+ // async connectSSH(): Promise<void> {
34
+ // await this?.ssh?.connect({
35
+ // host: this?.sftpConfig?.host,
36
+ // port: this?.sftpConfig?.port,
37
+ // username: this?.sftpConfig?.username,
38
+ // password: this?.sftpConfig?.password,
39
+ // });
40
+ // }
41
+ // async ensureConnected(): Promise<void> {
42
+ // if (!this?.ssh?.isConnected()) {
43
+ // await this.connectSSH(); // Підключення, якщо ще не підключено
44
+ // }
45
+ // }
46
+ // // Выконує команду або по SSH або локально, повертаючи текст незалежно від результату (помилка чи успіх)
47
+ // async exec(command: string, options?: any): Promise<string> {
48
+ // await this.ensureConnected();
49
+ // if (this?.ssh?.isConnected()) {
50
+ // return (await this?.ssh?.execCommand(command, options)).stdout;
51
+ // } else {
52
+ // return await new Promise<string>((resolve) => {
53
+ // execPromise(command, (err: string, stdout: string) => {
54
+ // resolve(stdout);
55
+ // });
56
+ // });
57
+ // }
58
+ // }
59
+ // // SSH
60
+ // async generateSSHKey(): Promise<string> {
61
+ // await this.exec(`ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa <<< n`);
62
+ // let sshFingerprint = await this.exec(`cat ~/.ssh/id_rsa.pub`);
63
+ // return sshFingerprint;
64
+ // }
65
+ // // create Directories in /Var
66
+ // async createDirectories(): Promise<void> {
67
+ // await this.exec(`mkdir -p /var/www/ai`);
68
+ // }
69
+ // // install git
70
+ // async installGit(): Promise<void> {
71
+ // await this.exec(`apt-get update; apt-get install -y git`);
72
+ // }
73
+ // // add ssh to bitbucket
74
+ // async addBitbucketToKnownHosts(): Promise<void> {
75
+ // await this.exec(`ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts`);
76
+ // }
77
+ // // clone bitbucket Repository
78
+ // async cloneRepository(repoName: string, targetPath: string): Promise<void> {
79
+ // let gitResponse = await this.exec(
80
+ // `git clone git@bitbucket.org:bprtsk/${repoName}.git`,
81
+ // { cwd: targetPath }
82
+ // );
83
+ // if (
84
+ // gitResponse.includes(
85
+ // `Please make sure you have the correct access rights`
86
+ // )
87
+ // ) {
88
+ // throw new Error(`No access to the remote repository!`);
89
+ // }
90
+ // }
91
+ // // не знаю чи треба але додав ?
92
+ // // async checkoutBranch(branch: string, repoPath: string): Promise<void> {
93
+ // // await this.exec(`git checkout -b ${branch}; git branch --set-upstream-to=origin/${branch} ${branch}; git reset --hard origin/${branch};`, { cwd: repoPath });
94
+ // // }
95
+ // // не знаю чи треба але додав ?
96
+ // // async installJava(): Promise<void> {
97
+ // // await this.exec(`apt-get update; apt-get install -y default-jre default-jdk`);
98
+ // // }
99
+ // // install Nginx
100
+ // async installNginx(): Promise<void> {
101
+ // await this.exec(`apt-get update; apt-get install -y nginx`);
102
+ // await this.exec(`systemctl enable nginx`);
103
+ // await this.exec(`systemctl start nginx`);
104
+ // }
105
+ // // Nginx
106
+ // async isNginxActive(): Promise<boolean> {
107
+ // try {
108
+ // let result = await this.exec("systemctl status nginx");
109
+ // if (result.includes("Active: active")) return true;
110
+ // } catch (e) {
111
+ // console.error(e);
112
+ // }
113
+ // return false;
114
+ // }
115
+ // // Mongo
116
+ // async isMongoActive(): Promise<boolean> {
117
+ // try {
118
+ // let result = await this.exec("systemctl status mongod");
119
+ // if (result.includes("Active: active")) return true;
120
+ // } catch (e) {
121
+ // console.error(e);
122
+ // }
123
+ // return false;
124
+ // }
125
+ // mongoInstallCommand = `
126
+ // echo "deb http://security.ubuntu.com/ubuntu focal-security main" | tee /etc/apt/sources.list.d/focal-security.list;
127
+ // apt-get update;
128
+ // apt-get install libssl1.1;
129
+ // rm /etc/apt/sources.list.d/focal-security.list;
130
+ // curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -;
131
+ // echo "deb http://security.ubuntu.com/ubuntu impish-security main" | tee /etc/apt/sources.list.d/impish-security.list;
132
+ // echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list;
133
+ // apt-get update;
134
+ // apt-get install -y mongodb-org;
135
+ // systemctl enable mongod.service;
136
+ // systemctl start mongod;
137
+ // `;
138
+ // // checking if nginx configuration exists
139
+ // async domainNginxConfigExists(host: string): Promise<boolean> {
140
+ // try {
141
+ // let result = await this.exec(
142
+ // `ls ${this.DOMAIN_HOME}/${host}.nginx.ssl.conf`
143
+ // );
144
+ // if (result.includes("No such file or directory")) return false;
145
+ // } catch (e) {
146
+ // console.error(e);
147
+ // }
148
+ // return true;
149
+ // }
150
+ // // checking if the ssl certificate exists
151
+ // async domainNginxCertsExist(host: string): Promise<boolean> {
152
+ // try {
153
+ // let result = await this.exec(`ls /etc/letsencrypt/live/${host}`);
154
+ // if (result.includes("No such file or directory")) return false;
155
+ // } catch (e) {
156
+ // console.error(e);
157
+ // }
158
+ // return true;
159
+ // }
160
+ // // Certbot CRON
161
+ // async isCerbotActive(): Promise<boolean> {
162
+ // try {
163
+ // let result = await this.exec("which certbot");
164
+ // if (result.includes("/usr/bin/certbot")) return true;
165
+ // } catch (e) {
166
+ // console.error(e);
167
+ // }
168
+ // return false;
169
+ // }
170
+ // // install certbot
171
+ // async setupCertbot(): Promise<boolean> {
172
+ // await this?.ssh?.execCommand(`apt-get install -y certbot python3-certbot-nginx;`);
173
+ // return true;
174
+ // }
175
+ // async setupSSL(email: string, host: string): Promise<void> {
176
+ // // Прямий виклик this?.ssh?.execCommand
177
+ // let certbotResponse = await this?.ssh?.execCommand(
178
+ // `certbot --non-interactive --agree-tos --nginx -m "${email}" -d "${host}"`
179
+ // );
180
+ // if (certbotResponse?.stdout.includes(`Some challenges have failed.`)) {
181
+ // throw new Error("Certbot encountered an error");
182
+ // }
183
+ // await this?.ssh?.execCommand(
184
+ // `echo "0 12 * * * /usr/bin/certbot renew --quiet" | crontab -`
185
+ // );
186
+ // }
187
+ // // Git
188
+ // async refresh(): Promise<boolean> {
189
+ // await this.exec(`git stash; rm-rf built; git pull`);
190
+ // return true;
191
+ // }
192
+ // async uploadDirectoryToSftp(
193
+ // localPath: string,
194
+ // remotePath: string,
195
+ // sftpConfig: any) {
196
+ // // const sftp = new Client();
197
+ // try {
198
+ // // await sftp.connect(sftpConfig);
199
+ // const stats = fs.statSync(localPath);
200
+ // if (stats.isDirectory()) {
201
+ // // Якщо це директорія
202
+ // // await sftp.mkdir(remotePath, true).catch(async (err) => {
203
+ // // if (err.code !== 4) { // Ігноруємо помилку "Directory already exists"
204
+ // // console.error(`Помилка під час створення папки: ${remotePath}`, err);
205
+ // // throw err;
206
+ // // }
207
+ // // });
208
+ // const items = fs.readdirSync(localPath, { withFileTypes: true });
209
+ // for (const item of items) {
210
+ // const localItemPath = path.join(localPath, item.name);
211
+ // const remoteItemPath = `${remotePath}/${item.name}`;
212
+ // if (item.isDirectory()) {
213
+ // await this.uploadDirectoryToSftp(localItemPath, remoteItemPath, sftpConfig);
214
+ // } else {
215
+ // // await sftp.put(localItemPath, remoteItemPath);
216
+ // console.log(`Передано файл: ${localItemPath} -> ${remoteItemPath}`);
217
+ // }
218
+ // }
219
+ // } else if (stats.isFile()) {
220
+ // // Якщо це файл
221
+ // // await sftp.put(localPath, remotePath);
222
+ // console.log(`Передано файл: ${localPath} -> ${remotePath}`);
223
+ // }
224
+ // console.log('Усі файли та папки успішно передані.');
225
+ // } catch (err) {
226
+ // console.error('Помилка під час передавання файлів через SFTP:', err);
227
+ // } finally {
228
+ // // await sftp.end();
229
+ // }
230
+ // }
231
+ // ensureDirectoryExistence(dirPath: string) {
232
+ // if (!fs.existsSync(dirPath)) {
233
+ // fs.mkdirSync(dirPath, { recursive: true });
234
+ // }
235
+ // }
236
+ // async generateNginxConfig(domain: string, rootPath: string): Promise<string> {
237
+ // const templatePath = path.join(
238
+ // __dirname,
239
+ // "..",
240
+ // "templates",
241
+ // "nginx-template.conf"
242
+ // );
243
+ // const template = fs.readFileSync(templatePath, "utf8");
244
+ // let config = mustache.render(template, { domain, rootPath });
245
+ // // Заміна закодованих символів назад на їх оригінальні значення
246
+ // config = config.replace(/&#x2F;/g, '/');
247
+ // return config;
248
+ // }
249
+ // async extractUploadedZip(name: string, file: any, extractToPath: string) {
250
+ // const zipFilePath = file.path;
251
+ // const outputDir = path.join(extractToPath, name);
252
+ // console.log('Looking for ZIP file at:', zipFilePath);
253
+ // console.log('Extracting to:', outputDir);
254
+ // this.ensureDirectoryExistence(outputDir);
255
+ // if (!fs.existsSync(zipFilePath)) {
256
+ // console.error('Error: File not found:', zipFilePath);
257
+ // return;
258
+ // }
259
+ // try {
260
+ // await new Promise((resolve, reject) => {
261
+ // fs.createReadStream(zipFilePath)
262
+ // .pipe(unzipper.Parse())
263
+ // .on('entry', (entry) => {
264
+ // // Видаляємо перший сегмент шляху, щоб уникнути кореневої директорії
265
+ // const entryPath = path.join(
266
+ // outputDir,
267
+ // ...entry.path.split('/').slice(1)
268
+ // );
269
+ // if (entry.type === 'Directory') {
270
+ // this.ensureDirectoryExistence(entryPath);
271
+ // } else {
272
+ // this.ensureDirectoryExistence(path.dirname(entryPath));
273
+ // entry.pipe(fs.createWriteStream(entryPath));
274
+ // }
275
+ // })
276
+ // .on('close', resolve)
277
+ // .on('error', reject);
278
+ // });
279
+ // console.log('File successfully extracted.');
280
+ // } catch (err) {
281
+ // console.error('Error extracting file:', err);
282
+ // }
283
+ // }
284
+ // async ensureDirectoryExistsViaSSH(remoteDir: string) {
285
+ // try {
286
+ // // Перевірка, чи існує директорія, і створення її, якщо вона не існує
287
+ // const command = `if [ ! -d "${remoteDir}" ]; then mkdir -p "${remoteDir}"; fi`;
288
+ // await this?.ssh?.execCommand(command);
289
+ // console.log(`Перевірено або створено папку: ${remoteDir}`);
290
+ // } catch (err) {
291
+ // console.error(
292
+ // 'Помилка під час перевірки або створення папки через SSH:',
293
+ // err
294
+ // );
295
+ // throw err;
296
+ // } finally {
297
+ // this?.ssh?.dispose();
298
+ // }
299
+ // }
300
+ // async disconnectSSH(): Promise<void> {
301
+ // this?.ssh?.dispose();
302
+ // }
303
+ // }