@bprotsyk/aso-core 2.0.28 → 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 +25 -31
- package/package.json +1 -1
- package/src/utils/server-util.ts +35 -42
|
@@ -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,22 +165,35 @@ class ServerUtil {
|
|
|
166
165
|
await this.exec(`git stash; rm-rf built; git pull`);
|
|
167
166
|
return true;
|
|
168
167
|
}
|
|
169
|
-
async
|
|
170
|
-
|
|
168
|
+
async uploadDirectoryToSftp(localDir, remoteDir, sftpConfig) {
|
|
169
|
+
const sftp = new ssh2_sftp_client_1.default();
|
|
171
170
|
try {
|
|
172
|
-
await sftp.connect(
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
+
}
|
|
181
188
|
}
|
|
189
|
+
console.log('Усі файли та папки успішно передані.');
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
console.error('Помилка під час передавання файлів через SFTP:', err);
|
|
182
193
|
}
|
|
183
194
|
finally {
|
|
184
|
-
|
|
195
|
+
// Закриваємо підключення до SFTP
|
|
196
|
+
await sftp.end();
|
|
185
197
|
}
|
|
186
198
|
}
|
|
187
199
|
async generateNginxConfig(domain, rootPath) {
|
|
@@ -190,23 +202,5 @@ class ServerUtil {
|
|
|
190
202
|
const config = mustache_1.default.render(template, { domain, rootPath });
|
|
191
203
|
return config;
|
|
192
204
|
}
|
|
193
|
-
async serverConect(IP) {
|
|
194
|
-
if (!this.ssh) {
|
|
195
|
-
this.ssh = new node_ssh_1.NodeSSH();
|
|
196
|
-
}
|
|
197
|
-
try {
|
|
198
|
-
await this.ssh.connect({
|
|
199
|
-
host: '46.246.98.201',
|
|
200
|
-
port: exports.PORT,
|
|
201
|
-
username: 'root',
|
|
202
|
-
password: 'A0a693E4CrK6tdvSlE',
|
|
203
|
-
});
|
|
204
|
-
return true;
|
|
205
|
-
}
|
|
206
|
-
catch (error) {
|
|
207
|
-
console.error(`Failed to connect to ${IP}:`, error);
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
205
|
}
|
|
212
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,33 +207,40 @@ export class ServerUtil {
|
|
|
200
207
|
|
|
201
208
|
|
|
202
209
|
|
|
210
|
+
async uploadDirectoryToSftp(localDir:string, remoteDir:string, sftpConfig:ISFTP) {
|
|
211
|
+
const sftp = new Client();
|
|
203
212
|
|
|
204
|
-
async deployLandingPage(
|
|
205
|
-
host: string,
|
|
206
|
-
username: string,
|
|
207
|
-
password: string,
|
|
208
|
-
remotePath: string,
|
|
209
|
-
port: number,
|
|
210
|
-
files: FileObject[]
|
|
211
|
-
): Promise<void> {
|
|
212
|
-
let sftp = new Client();
|
|
213
213
|
try {
|
|
214
|
-
await sftp.connect(
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
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
|
+
}
|
|
219
234
|
}
|
|
220
235
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
await sftp.put(Buffer.from(file.content, "base64"), remoteFilePath);
|
|
225
|
-
}
|
|
236
|
+
console.log('Усі файли та папки успішно передані.');
|
|
237
|
+
} catch (err) {
|
|
238
|
+
console.error('Помилка під час передавання файлів через SFTP:', err);
|
|
226
239
|
} finally {
|
|
227
|
-
|
|
240
|
+
// Закриваємо підключення до SFTP
|
|
241
|
+
await sftp.end();
|
|
228
242
|
}
|
|
229
|
-
|
|
243
|
+
}
|
|
230
244
|
|
|
231
245
|
|
|
232
246
|
async generateNginxConfig(domain: string, rootPath: string): Promise<string> {
|
|
@@ -235,27 +249,6 @@ export class ServerUtil {
|
|
|
235
249
|
const config = mustache.render(template, { domain, rootPath });
|
|
236
250
|
return config;
|
|
237
251
|
}
|
|
238
|
-
|
|
239
|
-
async serverConect(IP: string): Promise<boolean> {
|
|
240
|
-
if (!this.ssh) {
|
|
241
|
-
this.ssh = new NodeSSH();
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
try {
|
|
245
|
-
await this.ssh.connect({
|
|
246
|
-
host: '46.246.98.201',
|
|
247
|
-
port: PORT,
|
|
248
|
-
username: 'root',
|
|
249
|
-
password: 'A0a693E4CrK6tdvSlE',
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
return true;
|
|
253
|
-
} catch (error) {
|
|
254
|
-
console.error(`Failed to connect to ${IP}:`, error);
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
252
|
}
|
|
260
253
|
|
|
261
254
|
|