@bprotsyk/aso-core 2.0.28 → 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.
@@ -167,20 +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 normalizedFileName = path_1.default.basename(file.name);
179
- const remoteFilePath = path_1.default.join(remotePath, normalizedFileName);
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
180
184
  await sftp.put(Buffer.from(file.content, "base64"), remoteFilePath);
181
185
  }
182
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
+ }
183
191
  finally {
192
+ // Ensure that the SFTP connection is closed even if an error occurs
184
193
  sftp.end();
185
194
  }
186
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "2.0.28",
3
+ "version": "2.0.29",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -201,32 +201,42 @@ export class ServerUtil {
201
201
 
202
202
 
203
203
 
204
- async deployLandingPage(
204
+ async deployLandingPage(
205
205
  host: string,
206
206
  username: string,
207
207
  password: string,
208
208
  remotePath: string,
209
209
  port: number,
210
210
  files: FileObject[]
211
- ): Promise<void> {
212
- let sftp = new Client();
211
+ ): Promise<void> {
212
+ const sftp = new Client();
213
+
213
214
  try {
215
+ // Connecting to the server
214
216
  await sftp.connect({ host, username, password, port });
215
217
 
218
+ // Check if the directory exists, create it if not
216
219
  const dirExists = await sftp.exists(remotePath);
217
220
  if (!dirExists) {
218
- await sftp.mkdir(remotePath, true);
221
+ await sftp.mkdir(remotePath, true); // true ensures recursive creation
219
222
  }
220
223
 
224
+ // Upload files to the server
221
225
  for (const file of files) {
222
- const normalizedFileName = path.basename(file.name);
223
- const remoteFilePath = path.join(remotePath, normalizedFileName);
224
- await sftp.put(Buffer.from(file.content, "base64"), remoteFilePath);
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
230
+ await sftp.put(Buffer.from(file.content, "base64"), remoteFilePath);
225
231
  }
232
+ } catch (error) {
233
+ console.error('An error occurred during SFTP upload:', error);
234
+ throw error; // Re-throw the error for further handling
226
235
  } finally {
236
+ // Ensure that the SFTP connection is closed even if an error occurs
227
237
  sftp.end();
228
238
  }
229
- }
239
+ }
230
240
 
231
241
 
232
242
  async generateNginxConfig(domain: string, rootPath: string): Promise<string> {