@bprotsyk/aso-core 2.0.29 → 2.0.31
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 +1 -7
- package/lib/utils/server-util.js +23 -38
- package/package.json +1 -1
- package/src/utils/server-util.ts +40 -53
|
@@ -3,10 +3,6 @@ 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 FileObject {
|
|
7
|
-
name: string;
|
|
8
|
-
content: string;
|
|
9
|
-
}
|
|
10
6
|
export declare class ServerUtil {
|
|
11
7
|
DOMAIN_HOME: string;
|
|
12
8
|
ssh?: NodeSSH;
|
|
@@ -27,8 +23,6 @@ export declare class ServerUtil {
|
|
|
27
23
|
setupCertbot(): Promise<boolean>;
|
|
28
24
|
setupSSL(email: string, host: string): Promise<void>;
|
|
29
25
|
refresh(): Promise<boolean>;
|
|
30
|
-
|
|
26
|
+
uploadDirectoryToSftp(localDir: string, remoteDir: string, sftpConfig: any): Promise<void>;
|
|
31
27
|
generateNginxConfig(domain: string, rootPath: string): Promise<string>;
|
|
32
|
-
serverConect(IP: string): Promise<boolean>;
|
|
33
28
|
}
|
|
34
|
-
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 = `${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,43 +207,44 @@ export class ServerUtil {
|
|
|
200
207
|
|
|
201
208
|
|
|
202
209
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
remotePath: string,
|
|
209
|
-
port: number,
|
|
210
|
-
files: FileObject[]
|
|
211
|
-
): Promise<void> {
|
|
210
|
+
async uploadDirectoryToSftp(
|
|
211
|
+
localDir: string,
|
|
212
|
+
remoteDir: string,
|
|
213
|
+
sftpConfig: any
|
|
214
|
+
) {
|
|
212
215
|
const sftp = new Client();
|
|
213
|
-
|
|
216
|
+
|
|
214
217
|
try {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
218
|
+
await sftp.connect(sftpConfig);
|
|
219
|
+
|
|
220
|
+
const items = fs.readdirSync(localDir, { withFileTypes: true });
|
|
221
|
+
|
|
222
|
+
// Перебираємо кожен елемент (файл чи папку)
|
|
223
|
+
for (const item of items) {
|
|
224
|
+
const localPath = path.join(localDir, item.name);
|
|
225
|
+
const remotePath = `${remoteDir}/${item.name}`;
|
|
226
|
+
|
|
227
|
+
if (item.isDirectory()) {
|
|
228
|
+
// Якщо це директорія, створюємо її на сервері
|
|
229
|
+
await sftp.mkdir(remotePath, true);
|
|
230
|
+
|
|
231
|
+
// Рекурсивно передаємо вміст цієї директорії
|
|
232
|
+
await this.uploadDirectoryToSftp(localPath, remotePath, sftpConfig);
|
|
233
|
+
} else {
|
|
234
|
+
// Якщо це файл, передаємо його на сервер
|
|
235
|
+
await sftp.put(localPath, remotePath);
|
|
236
|
+
console.log(`Передано файл: ${localPath} -> ${remotePath}`);
|
|
231
237
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
console.log('Усі файли та папки успішно передані.');
|
|
241
|
+
} catch (err) {
|
|
242
|
+
console.error('Помилка під час передавання файлів через SFTP:', err);
|
|
235
243
|
} finally {
|
|
236
|
-
|
|
237
|
-
|
|
244
|
+
// Закриваємо підключення до SFTP
|
|
245
|
+
await sftp.end();
|
|
238
246
|
}
|
|
239
|
-
}
|
|
247
|
+
}
|
|
240
248
|
|
|
241
249
|
|
|
242
250
|
async generateNginxConfig(domain: string, rootPath: string): Promise<string> {
|
|
@@ -245,27 +253,6 @@ export class ServerUtil {
|
|
|
245
253
|
const config = mustache.render(template, { domain, rootPath });
|
|
246
254
|
return config;
|
|
247
255
|
}
|
|
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
256
|
}
|
|
270
257
|
|
|
271
258
|
|