@bprotsyk/aso-core 2.0.52 → 2.0.54
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.js
CHANGED
|
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ServerUtil = exports.PORT = exports.HOST = exports.PASSWORD = exports.IP = void 0;
|
|
7
7
|
const node_ssh_1 = require("node-ssh");
|
|
8
8
|
const child_process_1 = __importDefault(require("child_process"));
|
|
9
|
-
|
|
9
|
+
// import Client from "ssh2-sftp-client";
|
|
10
10
|
const fs_1 = __importDefault(require("fs"));
|
|
11
11
|
const mustache_1 = __importDefault(require("mustache"));
|
|
12
12
|
const path_1 = __importDefault(require("path"));
|
|
13
|
-
|
|
13
|
+
const unzipper_1 = __importDefault(require("unzipper"));
|
|
14
14
|
const { promisify } = require("util");
|
|
15
15
|
const execPromise = promisify(child_process_1.default.exec);
|
|
16
16
|
exports.IP = "185.123.53.227";
|
|
@@ -184,18 +184,18 @@ class ServerUtil {
|
|
|
184
184
|
return true;
|
|
185
185
|
}
|
|
186
186
|
async uploadDirectoryToSftp(localPath, remotePath, sftpConfig) {
|
|
187
|
-
const sftp = new
|
|
187
|
+
// const sftp = new Client();
|
|
188
188
|
try {
|
|
189
|
-
await sftp.connect(sftpConfig);
|
|
189
|
+
// await sftp.connect(sftpConfig);
|
|
190
190
|
const stats = fs_1.default.statSync(localPath);
|
|
191
191
|
if (stats.isDirectory()) {
|
|
192
192
|
// Якщо це директорія
|
|
193
|
-
await sftp.mkdir(remotePath, true).catch(async (err) => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
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
199
|
const items = fs_1.default.readdirSync(localPath, { withFileTypes: true });
|
|
200
200
|
for (const item of items) {
|
|
201
201
|
const localItemPath = path_1.default.join(localPath, item.name);
|
|
@@ -204,14 +204,14 @@ class ServerUtil {
|
|
|
204
204
|
await this.uploadDirectoryToSftp(localItemPath, remoteItemPath, sftpConfig);
|
|
205
205
|
}
|
|
206
206
|
else {
|
|
207
|
-
await sftp.put(localItemPath, remoteItemPath);
|
|
207
|
+
// await sftp.put(localItemPath, remoteItemPath);
|
|
208
208
|
console.log(`Передано файл: ${localItemPath} -> ${remoteItemPath}`);
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
else if (stats.isFile()) {
|
|
213
213
|
// Якщо це файл
|
|
214
|
-
await sftp.put(localPath, remotePath);
|
|
214
|
+
// await sftp.put(localPath, remotePath);
|
|
215
215
|
console.log(`Передано файл: ${localPath} -> ${remotePath}`);
|
|
216
216
|
}
|
|
217
217
|
console.log('Усі файли та папки успішно передані.');
|
|
@@ -220,7 +220,7 @@ class ServerUtil {
|
|
|
220
220
|
console.error('Помилка під час передавання файлів через SFTP:', err);
|
|
221
221
|
}
|
|
222
222
|
finally {
|
|
223
|
-
await sftp.end();
|
|
223
|
+
// await sftp.end();
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
ensureDirectoryExistence(dirPath) {
|
|
@@ -248,23 +248,21 @@ class ServerUtil {
|
|
|
248
248
|
}
|
|
249
249
|
try {
|
|
250
250
|
await new Promise((resolve, reject) => {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
// .on('close', resolve)
|
|
267
|
-
// .on('error', 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);
|
|
268
266
|
});
|
|
269
267
|
console.log('File successfully extracted.');
|
|
270
268
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bprotsyk/aso-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.54",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@types/mongoose": "^5.11.97",
|
|
28
28
|
"@types/node-ssh": "^7.0.6",
|
|
29
29
|
"@types/styled-components": "^5.1.26",
|
|
30
|
+
"@types/unzipper": "^0.10.10",
|
|
30
31
|
"axios": "^1.4.0",
|
|
31
32
|
"module-alias": "^2.2.2",
|
|
32
33
|
"mongoose": "^6.8.3",
|
|
@@ -36,7 +37,6 @@
|
|
|
36
37
|
"react-dom": "^18.3.1",
|
|
37
38
|
"replace-in-file": "^7.0.1",
|
|
38
39
|
"sleep-promise": "^9.1.0",
|
|
39
|
-
"ssh2-sftp-client": "^11.0.0",
|
|
40
40
|
"styled-components": "^5.3.9",
|
|
41
41
|
"unzipper": "^0.12.3"
|
|
42
42
|
},
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"@types/node": "^20.14.12",
|
|
46
46
|
"@types/react": "^18.3.12",
|
|
47
47
|
"@types/react-dom": "^18.3.0",
|
|
48
|
-
"@types/ssh2-sftp-client": "^9.0.4",
|
|
49
48
|
"copyfiles": "^2.4.1",
|
|
50
49
|
"typedoc": "^0.23.28",
|
|
51
50
|
"typescript": "^4.9.5"
|
package/src/utils/server-util.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { NodeSSH } from "node-ssh";
|
|
2
2
|
import ChildProcess from "child_process";
|
|
3
|
-
import Client from "ssh2-sftp-client";
|
|
3
|
+
// import Client from "ssh2-sftp-client";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import mustache from "mustache";
|
|
6
6
|
import path from "path";
|
|
7
|
-
|
|
7
|
+
import unzipper from 'unzipper';
|
|
8
8
|
|
|
9
9
|
const { promisify } = require("util");
|
|
10
10
|
const execPromise = promisify(ChildProcess.exec);
|
|
@@ -234,21 +234,21 @@ export class ServerUtil {
|
|
|
234
234
|
localPath: string,
|
|
235
235
|
remotePath: string,
|
|
236
236
|
sftpConfig: any) {
|
|
237
|
-
const sftp = new Client();
|
|
237
|
+
// const sftp = new Client();
|
|
238
238
|
|
|
239
239
|
try {
|
|
240
|
-
await sftp.connect(sftpConfig);
|
|
240
|
+
// await sftp.connect(sftpConfig);
|
|
241
241
|
|
|
242
242
|
const stats = fs.statSync(localPath);
|
|
243
243
|
|
|
244
244
|
if (stats.isDirectory()) {
|
|
245
245
|
// Якщо це директорія
|
|
246
|
-
await sftp.mkdir(remotePath, true).catch(async (err) => {
|
|
247
|
-
if (err.code !== 4) { // Ігноруємо помилку "Directory already exists"
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
});
|
|
246
|
+
// await sftp.mkdir(remotePath, true).catch(async (err) => {
|
|
247
|
+
// if (err.code !== 4) { // Ігноруємо помилку "Directory already exists"
|
|
248
|
+
// console.error(`Помилка під час створення папки: ${remotePath}`, err);
|
|
249
|
+
// throw err;
|
|
250
|
+
// }
|
|
251
|
+
// });
|
|
252
252
|
|
|
253
253
|
const items = fs.readdirSync(localPath, { withFileTypes: true });
|
|
254
254
|
|
|
@@ -259,14 +259,14 @@ export class ServerUtil {
|
|
|
259
259
|
if (item.isDirectory()) {
|
|
260
260
|
await this.uploadDirectoryToSftp(localItemPath, remoteItemPath, sftpConfig);
|
|
261
261
|
} else {
|
|
262
|
-
await sftp.put(localItemPath, remoteItemPath);
|
|
262
|
+
// await sftp.put(localItemPath, remoteItemPath);
|
|
263
263
|
console.log(`Передано файл: ${localItemPath} -> ${remoteItemPath}`);
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
} else if (stats.isFile()) {
|
|
268
268
|
// Якщо це файл
|
|
269
|
-
await sftp.put(localPath, remotePath);
|
|
269
|
+
// await sftp.put(localPath, remotePath);
|
|
270
270
|
console.log(`Передано файл: ${localPath} -> ${remotePath}`);
|
|
271
271
|
}
|
|
272
272
|
|
|
@@ -274,7 +274,7 @@ export class ServerUtil {
|
|
|
274
274
|
} catch (err) {
|
|
275
275
|
console.error('Помилка під час передавання файлів через SFTP:', err);
|
|
276
276
|
} finally {
|
|
277
|
-
await sftp.end();
|
|
277
|
+
// await sftp.end();
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
@@ -315,24 +315,24 @@ export class ServerUtil {
|
|
|
315
315
|
|
|
316
316
|
try {
|
|
317
317
|
await new Promise((resolve, reject) => {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
318
|
+
fs.createReadStream(zipFilePath)
|
|
319
|
+
.pipe(unzipper.Parse())
|
|
320
|
+
.on('entry', (entry) => {
|
|
321
|
+
// Видаляємо перший сегмент шляху, щоб уникнути кореневої директорії
|
|
322
|
+
const entryPath = path.join(
|
|
323
|
+
outputDir,
|
|
324
|
+
...entry.path.split('/').slice(1)
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
if (entry.type === 'Directory') {
|
|
328
|
+
this.ensureDirectoryExistence(entryPath);
|
|
329
|
+
} else {
|
|
330
|
+
this.ensureDirectoryExistence(path.dirname(entryPath));
|
|
331
|
+
entry.pipe(fs.createWriteStream(entryPath));
|
|
332
|
+
}
|
|
333
|
+
})
|
|
334
|
+
.on('close', resolve)
|
|
335
|
+
.on('error', reject);
|
|
336
336
|
});
|
|
337
337
|
|
|
338
338
|
console.log('File successfully extracted.');
|