@bprotsyk/aso-core 2.0.41 → 2.0.42
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.
- package/lib/utils/server-util.d.ts +6 -3
- package/lib/utils/server-util.js +18 -7
- package/package.json +1 -1
- package/src/utils/server-util.ts +22 -11
|
@@ -11,8 +11,10 @@ interface ISFTP {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class ServerUtil {
|
|
13
13
|
DOMAIN_HOME: string;
|
|
14
|
-
ssh
|
|
15
|
-
|
|
14
|
+
ssh: NodeSSH;
|
|
15
|
+
sftpConfig: ISFTP;
|
|
16
|
+
constructor(sftpConfig: ISFTP);
|
|
17
|
+
connectSSH(): Promise<void>;
|
|
16
18
|
exec(command: string, options?: any): Promise<string>;
|
|
17
19
|
generateSSHKey(): Promise<string>;
|
|
18
20
|
createDirectories(): Promise<void>;
|
|
@@ -33,6 +35,7 @@ export declare class ServerUtil {
|
|
|
33
35
|
ensureDirectoryExistence(dirPath: string): void;
|
|
34
36
|
generateNginxConfig(domain: string, rootPath: string): Promise<string>;
|
|
35
37
|
extractUploadedZip(name: string, file: any, extractToPath: string): Promise<void>;
|
|
36
|
-
ensureDirectoryExistsViaSSH(
|
|
38
|
+
ensureDirectoryExistsViaSSH(remoteDir: string): Promise<void>;
|
|
39
|
+
disconnectSSH(): Promise<void>;
|
|
37
40
|
}
|
|
38
41
|
export {};
|
package/lib/utils/server-util.js
CHANGED
|
@@ -20,8 +20,18 @@ exports.PORT = 56777;
|
|
|
20
20
|
class ServerUtil {
|
|
21
21
|
DOMAIN_HOME = "/etc/nginx/sites-enabled";
|
|
22
22
|
ssh;
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
});
|
|
25
35
|
}
|
|
26
36
|
// Выконує команду або по SSH або локально, повертаючи текст незалежно від результату (помилка чи успіх)
|
|
27
37
|
async exec(command, options) {
|
|
@@ -254,13 +264,11 @@ class ServerUtil {
|
|
|
254
264
|
console.error('Error extracting file:', err);
|
|
255
265
|
}
|
|
256
266
|
}
|
|
257
|
-
async ensureDirectoryExistsViaSSH(
|
|
258
|
-
const ssh = new node_ssh_1.NodeSSH();
|
|
267
|
+
async ensureDirectoryExistsViaSSH(remoteDir) {
|
|
259
268
|
try {
|
|
260
|
-
await ssh.connect(sshConfig);
|
|
261
269
|
// Перевірка, чи існує директорія, і створення її, якщо вона не існує
|
|
262
270
|
const command = `if [ ! -d "${remoteDir}" ]; then mkdir -p "${remoteDir}"; fi`;
|
|
263
|
-
await ssh.execCommand(command);
|
|
271
|
+
await this.ssh.execCommand(command);
|
|
264
272
|
console.log(`Перевірено або створено папку: ${remoteDir}`);
|
|
265
273
|
}
|
|
266
274
|
catch (err) {
|
|
@@ -268,8 +276,11 @@ class ServerUtil {
|
|
|
268
276
|
throw err;
|
|
269
277
|
}
|
|
270
278
|
finally {
|
|
271
|
-
ssh.dispose();
|
|
279
|
+
this.ssh.dispose();
|
|
272
280
|
}
|
|
273
281
|
}
|
|
282
|
+
async disconnectSSH() {
|
|
283
|
+
this.ssh.dispose();
|
|
284
|
+
}
|
|
274
285
|
}
|
|
275
286
|
exports.ServerUtil = ServerUtil;
|
package/package.json
CHANGED
package/src/utils/server-util.ts
CHANGED
|
@@ -29,11 +29,22 @@ interface ISFTP {
|
|
|
29
29
|
export class ServerUtil {
|
|
30
30
|
DOMAIN_HOME = "/etc/nginx/sites-enabled";
|
|
31
31
|
|
|
32
|
-
ssh
|
|
32
|
+
ssh: NodeSSH;
|
|
33
|
+
sftpConfig: ISFTP;
|
|
33
34
|
|
|
34
|
-
constructor(
|
|
35
|
-
this.ssh =
|
|
36
|
-
|
|
35
|
+
constructor(sftpConfig: ISFTP) {
|
|
36
|
+
this.ssh = new NodeSSH();
|
|
37
|
+
this.sftpConfig = sftpConfig;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async connectSSH(): Promise<void> {
|
|
41
|
+
await this.ssh.connect({
|
|
42
|
+
host: this.sftpConfig.host,
|
|
43
|
+
port: this.sftpConfig.port,
|
|
44
|
+
username: this.sftpConfig.username,
|
|
45
|
+
password: this.sftpConfig.password,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
37
48
|
|
|
38
49
|
// Выконує команду або по SSH або локально, повертаючи текст незалежно від результату (помилка чи успіх)
|
|
39
50
|
async exec(command: string, options?: any): Promise<string> {
|
|
@@ -318,15 +329,12 @@ export class ServerUtil {
|
|
|
318
329
|
}
|
|
319
330
|
}
|
|
320
331
|
|
|
321
|
-
async ensureDirectoryExistsViaSSH(
|
|
322
|
-
const ssh = new NodeSSH();
|
|
332
|
+
async ensureDirectoryExistsViaSSH(remoteDir:string) {
|
|
323
333
|
|
|
324
334
|
try {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
// Перевірка, чи існує директорія, і створення її, якщо вона не існує
|
|
335
|
+
// Перевірка, чи існує директорія, і створення її, якщо вона не існує
|
|
328
336
|
const command = `if [ ! -d "${remoteDir}" ]; then mkdir -p "${remoteDir}"; fi`;
|
|
329
|
-
await ssh.execCommand(command);
|
|
337
|
+
await this.ssh.execCommand(command);
|
|
330
338
|
console.log(`Перевірено або створено папку: ${remoteDir}`);
|
|
331
339
|
} catch (err) {
|
|
332
340
|
console.error(
|
|
@@ -335,9 +343,12 @@ export class ServerUtil {
|
|
|
335
343
|
);
|
|
336
344
|
throw err;
|
|
337
345
|
} finally {
|
|
338
|
-
ssh.dispose();
|
|
346
|
+
this.ssh.dispose();
|
|
339
347
|
}
|
|
340
348
|
}
|
|
349
|
+
async disconnectSSH(): Promise<void> {
|
|
350
|
+
this.ssh.dispose();
|
|
351
|
+
}
|
|
341
352
|
}
|
|
342
353
|
|
|
343
354
|
|