@bprotsyk/aso-core 2.0.29 → 2.0.30
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 -5
- package/lib/utils/server-util.js +23 -38
- package/package.json +1 -1
- package/src/utils/server-util.ts +33 -50
|
@@ -3,9 +3,11 @@ export declare let IP: string;
|
|
|
3
3
|
export declare let PASSWORD: string;
|
|
4
4
|
export declare let HOST: string;
|
|
5
5
|
export declare let PORT: number;
|
|
6
|
-
interface
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
interface ISFTP {
|
|
7
|
+
ip: string;
|
|
8
|
+
port: number;
|
|
9
|
+
username: string;
|
|
10
|
+
password: string;
|
|
9
11
|
}
|
|
10
12
|
export declare class ServerUtil {
|
|
11
13
|
DOMAIN_HOME: string;
|
|
@@ -27,8 +29,7 @@ export declare class ServerUtil {
|
|
|
27
29
|
setupCertbot(): Promise<boolean>;
|
|
28
30
|
setupSSL(email: string, host: string): Promise<void>;
|
|
29
31
|
refresh(): Promise<boolean>;
|
|
30
|
-
|
|
32
|
+
uploadDirectoryToSftp(localDir: string, remoteDir: string, sftpConfig: ISFTP): Promise<void>;
|
|
31
33
|
generateNginxConfig(domain: string, rootPath: string): Promise<string>;
|
|
32
|
-
serverConect(IP: string): Promise<boolean>;
|
|
33
34
|
}
|
|
34
35
|
export {};
|
package/lib/utils/server-util.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ServerUtil = exports.PORT = exports.HOST = exports.PASSWORD = exports.IP = void 0;
|
|
7
|
-
const node_ssh_1 = require("node-ssh");
|
|
8
7
|
const child_process_1 = __importDefault(require("child_process"));
|
|
9
8
|
const ssh2_sftp_client_1 = __importDefault(require("ssh2-sftp-client"));
|
|
10
9
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -166,31 +165,35 @@ class ServerUtil {
|
|
|
166
165
|
await this.exec(`git stash; rm-rf built; git pull`);
|
|
167
166
|
return true;
|
|
168
167
|
}
|
|
169
|
-
async
|
|
168
|
+
async uploadDirectoryToSftp(localDir, remoteDir, sftpConfig) {
|
|
170
169
|
const sftp = new ssh2_sftp_client_1.default();
|
|
171
170
|
try {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
//
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
171
|
+
await sftp.connect(sftpConfig);
|
|
172
|
+
const items = fs_1.default.readdirSync(localDir, { withFileTypes: true });
|
|
173
|
+
// Перебираємо кожен елемент (файл чи папку)
|
|
174
|
+
for (const item of items) {
|
|
175
|
+
const localPath = path_1.default.join(localDir, item.name);
|
|
176
|
+
const remotePath = path_1.default.join(remoteDir, item.name);
|
|
177
|
+
if (item.isDirectory()) {
|
|
178
|
+
// Якщо це директорія, створюємо її на сервері
|
|
179
|
+
await sftp.mkdir(remotePath, true);
|
|
180
|
+
// Рекурсивно передаємо вміст цієї директорії
|
|
181
|
+
await this.uploadDirectoryToSftp(localPath, remotePath, sftpConfig);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// Якщо це файл, передаємо його на сервер
|
|
185
|
+
await sftp.put(localPath, remotePath);
|
|
186
|
+
console.log(`Передано файл: ${localPath} -> ${remotePath}`);
|
|
187
|
+
}
|
|
185
188
|
}
|
|
189
|
+
console.log('Усі файли та папки успішно передані.');
|
|
186
190
|
}
|
|
187
|
-
catch (
|
|
188
|
-
console.error('
|
|
189
|
-
throw error; // Re-throw the error for further handling
|
|
191
|
+
catch (err) {
|
|
192
|
+
console.error('Помилка під час передавання файлів через SFTP:', err);
|
|
190
193
|
}
|
|
191
194
|
finally {
|
|
192
|
-
//
|
|
193
|
-
sftp.end();
|
|
195
|
+
// Закриваємо підключення до SFTP
|
|
196
|
+
await sftp.end();
|
|
194
197
|
}
|
|
195
198
|
}
|
|
196
199
|
async generateNginxConfig(domain, rootPath) {
|
|
@@ -199,23 +202,5 @@ class ServerUtil {
|
|
|
199
202
|
const config = mustache_1.default.render(template, { domain, rootPath });
|
|
200
203
|
return config;
|
|
201
204
|
}
|
|
202
|
-
async serverConect(IP) {
|
|
203
|
-
if (!this.ssh) {
|
|
204
|
-
this.ssh = new node_ssh_1.NodeSSH();
|
|
205
|
-
}
|
|
206
|
-
try {
|
|
207
|
-
await this.ssh.connect({
|
|
208
|
-
host: '46.246.98.201',
|
|
209
|
-
port: exports.PORT,
|
|
210
|
-
username: 'root',
|
|
211
|
-
password: 'A0a693E4CrK6tdvSlE',
|
|
212
|
-
});
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
catch (error) {
|
|
216
|
-
console.error(`Failed to connect to ${IP}:`, error);
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
205
|
}
|
|
221
206
|
exports.ServerUtil = ServerUtil;
|
package/package.json
CHANGED
package/src/utils/server-util.ts
CHANGED
|
@@ -17,6 +17,13 @@ interface FileObject {
|
|
|
17
17
|
content: string; // Це буде Base64 закодовані дані
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
interface ISFTP{
|
|
21
|
+
ip:string ,
|
|
22
|
+
port: number,
|
|
23
|
+
username: string,
|
|
24
|
+
password: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
export class ServerUtil {
|
|
21
28
|
DOMAIN_HOME = "/etc/nginx/sites-enabled";
|
|
22
29
|
|
|
@@ -200,41 +207,38 @@ export class ServerUtil {
|
|
|
200
207
|
|
|
201
208
|
|
|
202
209
|
|
|
203
|
-
|
|
204
|
-
async deployLandingPage(
|
|
205
|
-
host: string,
|
|
206
|
-
username: string,
|
|
207
|
-
password: string,
|
|
208
|
-
remotePath: string,
|
|
209
|
-
port: number,
|
|
210
|
-
files: FileObject[]
|
|
211
|
-
): Promise<void> {
|
|
210
|
+
async uploadDirectoryToSftp(localDir:string, remoteDir:string, sftpConfig:ISFTP) {
|
|
212
211
|
const sftp = new Client();
|
|
213
212
|
|
|
214
213
|
try {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
214
|
+
await sftp.connect(sftpConfig);
|
|
215
|
+
|
|
216
|
+
const items = fs.readdirSync(localDir, { withFileTypes: true });
|
|
217
|
+
|
|
218
|
+
// Перебираємо кожен елемент (файл чи папку)
|
|
219
|
+
for (const item of items) {
|
|
220
|
+
const localPath = path.join(localDir, item.name);
|
|
221
|
+
const remotePath = path.join(remoteDir, item.name);
|
|
222
|
+
|
|
223
|
+
if (item.isDirectory()) {
|
|
224
|
+
// Якщо це директорія, створюємо її на сервері
|
|
225
|
+
await sftp.mkdir(remotePath, true);
|
|
226
|
+
|
|
227
|
+
// Рекурсивно передаємо вміст цієї директорії
|
|
228
|
+
await this.uploadDirectoryToSftp(localPath, remotePath, sftpConfig);
|
|
229
|
+
} else {
|
|
230
|
+
// Якщо це файл, передаємо його на сервер
|
|
231
|
+
await sftp.put(localPath, remotePath);
|
|
232
|
+
console.log(`Передано файл: ${localPath} -> ${remotePath}`);
|
|
233
|
+
}
|
|
222
234
|
}
|
|
223
235
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const remoteFilePath = path.posix.join(remotePath, normalizedFileName);
|
|
228
|
-
|
|
229
|
-
// Writing file content to the server
|
|
230
|
-
await sftp.put(Buffer.from(file.content, "base64"), remoteFilePath);
|
|
231
|
-
}
|
|
232
|
-
} catch (error) {
|
|
233
|
-
console.error('An error occurred during SFTP upload:', error);
|
|
234
|
-
throw error; // Re-throw the error for further handling
|
|
236
|
+
console.log('Усі файли та папки успішно передані.');
|
|
237
|
+
} catch (err) {
|
|
238
|
+
console.error('Помилка під час передавання файлів через SFTP:', err);
|
|
235
239
|
} finally {
|
|
236
|
-
//
|
|
237
|
-
sftp.end();
|
|
240
|
+
// Закриваємо підключення до SFTP
|
|
241
|
+
await sftp.end();
|
|
238
242
|
}
|
|
239
243
|
}
|
|
240
244
|
|
|
@@ -245,27 +249,6 @@ export class ServerUtil {
|
|
|
245
249
|
const config = mustache.render(template, { domain, rootPath });
|
|
246
250
|
return config;
|
|
247
251
|
}
|
|
248
|
-
|
|
249
|
-
async serverConect(IP: string): Promise<boolean> {
|
|
250
|
-
if (!this.ssh) {
|
|
251
|
-
this.ssh = new NodeSSH();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
try {
|
|
255
|
-
await this.ssh.connect({
|
|
256
|
-
host: '46.246.98.201',
|
|
257
|
-
port: PORT,
|
|
258
|
-
username: 'root',
|
|
259
|
-
password: 'A0a693E4CrK6tdvSlE',
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
return true;
|
|
263
|
-
} catch (error) {
|
|
264
|
-
console.error(`Failed to connect to ${IP}:`, error);
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
252
|
}
|
|
270
253
|
|
|
271
254
|
|