@bprotsyk/aso-core 2.0.27 → 2.0.29

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.
@@ -3,6 +3,10 @@ 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
+ }
6
10
  export declare class ServerUtil {
7
11
  DOMAIN_HOME: string;
8
12
  ssh?: NodeSSH;
@@ -23,7 +27,8 @@ export declare class ServerUtil {
23
27
  setupCertbot(): Promise<boolean>;
24
28
  setupSSL(email: string, host: string): Promise<void>;
25
29
  refresh(): Promise<boolean>;
26
- deployLandingPage(host: string, username: string, password: string, remotePath: string, port: number, files: any): Promise<void>;
30
+ deployLandingPage(host: string, username: string, password: string, remotePath: string, port: number, files: FileObject[]): Promise<void>;
27
31
  generateNginxConfig(domain: string, rootPath: string): Promise<string>;
28
32
  serverConect(IP: string): Promise<boolean>;
29
33
  }
34
+ export {};
@@ -167,19 +167,29 @@ class ServerUtil {
167
167
  return true;
168
168
  }
169
169
  async deployLandingPage(host, username, password, remotePath, port, files) {
170
- let sftp = new ssh2_sftp_client_1.default();
170
+ const sftp = new ssh2_sftp_client_1.default();
171
171
  try {
172
+ // Connecting to the server
172
173
  await sftp.connect({ host, username, password, port });
174
+ // Check if the directory exists, create it if not
173
175
  const dirExists = await sftp.exists(remotePath);
174
176
  if (!dirExists) {
175
- await sftp.mkdir(remotePath, true);
177
+ await sftp.mkdir(remotePath, true); // true ensures recursive creation
176
178
  }
179
+ // Upload files to the server
177
180
  for (const file of files) {
178
- const remoteFilePath = `${remotePath}/${file.name}`;
181
+ const normalizedFileName = path_1.default.posix.basename(file.name); // Ensuring proper path handling for POSIX
182
+ const remoteFilePath = path_1.default.posix.join(remotePath, normalizedFileName);
183
+ // Writing file content to the server
179
184
  await sftp.put(Buffer.from(file.content, "base64"), remoteFilePath);
180
185
  }
181
186
  }
187
+ catch (error) {
188
+ console.error('An error occurred during SFTP upload:', error);
189
+ throw error; // Re-throw the error for further handling
190
+ }
182
191
  finally {
192
+ // Ensure that the SFTP connection is closed even if an error occurs
183
193
  sftp.end();
184
194
  }
185
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "2.0.27",
3
+ "version": "2.0.29",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -12,6 +12,11 @@ export let PASSWORD = "xUA3oOX06Kfc9m12rZ";
12
12
  export let HOST = "cg-main-server.com";
13
13
  export let PORT = 56777;
14
14
 
15
+ interface FileObject {
16
+ name: string;
17
+ content: string; // Це буде Base64 закодовані дані
18
+ }
19
+
15
20
  export class ServerUtil {
16
21
  DOMAIN_HOME = "/etc/nginx/sites-enabled";
17
22
 
@@ -192,34 +197,46 @@ export class ServerUtil {
192
197
 
193
198
  return true;
194
199
  }
200
+
195
201
 
196
202
 
197
203
 
198
- async deployLandingPage(
204
+ async deployLandingPage(
199
205
  host: string,
200
206
  username: string,
201
207
  password: string,
202
208
  remotePath: string,
203
209
  port: number,
204
- files: any
205
- ): Promise<void> {
206
- let sftp = new Client();
210
+ files: FileObject[]
211
+ ): Promise<void> {
212
+ const sftp = new Client();
213
+
207
214
  try {
215
+ // Connecting to the server
208
216
  await sftp.connect({ host, username, password, port });
209
217
 
218
+ // Check if the directory exists, create it if not
210
219
  const dirExists = await sftp.exists(remotePath);
211
220
  if (!dirExists) {
212
- await sftp.mkdir(remotePath, true);
221
+ await sftp.mkdir(remotePath, true); // true ensures recursive creation
213
222
  }
214
223
 
224
+ // Upload files to the server
215
225
  for (const file of files) {
216
- const remoteFilePath = `${remotePath}/${file.name}`;
226
+ const normalizedFileName = path.posix.basename(file.name); // Ensuring proper path handling for POSIX
227
+ const remoteFilePath = path.posix.join(remotePath, normalizedFileName);
228
+
229
+ // Writing file content to the server
217
230
  await sftp.put(Buffer.from(file.content, "base64"), remoteFilePath);
218
231
  }
232
+ } catch (error) {
233
+ console.error('An error occurred during SFTP upload:', error);
234
+ throw error; // Re-throw the error for further handling
219
235
  } finally {
236
+ // Ensure that the SFTP connection is closed even if an error occurs
220
237
  sftp.end();
221
238
  }
222
- }
239
+ }
223
240
 
224
241
 
225
242
  async generateNginxConfig(domain: string, rootPath: string): Promise<string> {