@bprotsyk/aso-core 2.0.35 → 2.0.37

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.
@@ -29,10 +29,10 @@ export declare class ServerUtil {
29
29
  setupCertbot(): Promise<boolean>;
30
30
  setupSSL(email: string, host: string): Promise<void>;
31
31
  refresh(): Promise<boolean>;
32
- uploadDirectoryToSftp(localDir: string, remoteDir: string, sftpConfig: any): Promise<void>;
32
+ uploadDirectoryToSftp(localPath: string, remotePath: string, sftpConfig: any): Promise<void>;
33
33
  ensureDirectoryExistence(dirPath: string): void;
34
34
  generateNginxConfig(domain: string, rootPath: string): Promise<string>;
35
- extractUploadedZip(name: string, file: any): Promise<void>;
35
+ extractUploadedZip(name: string, file: any, extractToPath: string): Promise<void>;
36
36
  ensureDirectoryExistsViaSSH(sshConfig: ISFTP, remoteDir: string): Promise<void>;
37
37
  }
38
38
  export {};
@@ -167,31 +167,37 @@ class ServerUtil {
167
167
  await this.exec(`git stash; rm-rf built; git pull`);
168
168
  return true;
169
169
  }
170
- async uploadDirectoryToSftp(localDir, remoteDir, sftpConfig) {
170
+ async uploadDirectoryToSftp(localPath, remotePath, sftpConfig) {
171
171
  const sftp = new ssh2_sftp_client_1.default();
172
172
  try {
173
173
  await sftp.connect(sftpConfig);
174
- const items = fs_1.default.readdirSync(localDir, { withFileTypes: true });
175
- for (const item of items) {
176
- const localPath = path_1.default.join(localDir, item.name);
177
- const remotePath = `${remoteDir}/${item.name}`;
178
- if (item.isDirectory()) {
179
- // Створення підкаталогу на віддаленому сервері
180
- await sftp.mkdir(remotePath, true).catch(async (err) => {
181
- if (err.code !== 4) { // Ігноруємо помилку "Directory already exists"
182
- console.error(`Помилка під час створення папки: ${remotePath}`, err);
183
- throw err;
184
- }
185
- });
186
- // Рекурсивне копіювання вмісту директорії
187
- await this.uploadDirectoryToSftp(localPath, remotePath, sftpConfig);
188
- }
189
- else {
190
- // Завантаження файлу на віддалений сервер
191
- await sftp.put(localPath, remotePath);
192
- console.log(`Передано файл: ${localPath} -> ${remotePath}`);
174
+ const stats = fs_1.default.statSync(localPath);
175
+ if (stats.isDirectory()) {
176
+ // Якщо це директорія
177
+ await sftp.mkdir(remotePath, true).catch(async (err) => {
178
+ if (err.code !== 4) { // Ігноруємо помилку "Directory already exists"
179
+ console.error(`Помилка під час створення папки: ${remotePath}`, err);
180
+ throw err;
181
+ }
182
+ });
183
+ const items = fs_1.default.readdirSync(localPath, { withFileTypes: true });
184
+ for (const item of items) {
185
+ const localItemPath = path_1.default.join(localPath, item.name);
186
+ const remoteItemPath = `${remotePath}/${item.name}`;
187
+ if (item.isDirectory()) {
188
+ await this.uploadDirectoryToSftp(localItemPath, remoteItemPath, sftpConfig);
189
+ }
190
+ else {
191
+ await sftp.put(localItemPath, remoteItemPath);
192
+ console.log(`Передано файл: ${localItemPath} -> ${remoteItemPath}`);
193
+ }
193
194
  }
194
195
  }
196
+ else if (stats.isFile()) {
197
+ // Якщо це файл
198
+ await sftp.put(localPath, remotePath);
199
+ console.log(`Передано файл: ${localPath} -> ${remotePath}`);
200
+ }
195
201
  console.log('Усі файли та папки успішно передані.');
196
202
  }
197
203
  catch (err) {
@@ -212,9 +218,9 @@ class ServerUtil {
212
218
  const config = mustache_1.default.render(template, { domain, rootPath });
213
219
  return config;
214
220
  }
215
- async extractUploadedZip(name, file) {
221
+ async extractUploadedZip(name, file, extractToPath) {
216
222
  const zipFilePath = file.path;
217
- const outputDir = path_1.default.join(__dirname, '..', 'uploads', name);
223
+ const outputDir = path_1.default.join(extractToPath, name);
218
224
  console.log('Looking for ZIP file at:', zipFilePath);
219
225
  console.log('Extracting to:', outputDir);
220
226
  this.ensureDirectoryExistence(outputDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "2.0.35",
3
+ "version": "2.0.37",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -207,37 +207,44 @@ export class ServerUtil {
207
207
  return true;
208
208
  }
209
209
 
210
- async uploadDirectoryToSftp(
211
- localDir: string,
212
- remoteDir: string,
213
- sftpConfig: any
214
- ) {
210
+ async uploadDirectoryToSftp(
211
+ localPath: string,
212
+ remotePath: string,
213
+ sftpConfig: any) {
215
214
  const sftp = new Client();
216
215
 
217
216
  try {
218
217
  await sftp.connect(sftpConfig);
219
- const items = fs.readdirSync(localDir, { withFileTypes: true });
220
218
 
221
- for (const item of items) {
222
- const localPath = path.join(localDir, item.name);
223
- const remotePath = `${remoteDir}/${item.name}`;
219
+ const stats = fs.statSync(localPath);
224
220
 
225
- if (item.isDirectory()) {
226
- // Створення підкаталогу на віддаленому сервері
227
- await sftp.mkdir(remotePath, true).catch(async (err) => {
228
- if (err.code !== 4) { // Ігноруємо помилку "Directory already exists"
229
- console.error(`Помилка під час створення папки: ${remotePath}`, err);
230
- throw err;
231
- }
232
- });
221
+ if (stats.isDirectory()) {
222
+ // Якщо це директорія
223
+ await sftp.mkdir(remotePath, true).catch(async (err) => {
224
+ if (err.code !== 4) { // Ігноруємо помилку "Directory already exists"
225
+ console.error(`Помилка під час створення папки: ${remotePath}`, err);
226
+ throw err;
227
+ }
228
+ });
229
+
230
+ const items = fs.readdirSync(localPath, { withFileTypes: true });
233
231
 
234
- // Рекурсивне копіювання вмісту директорії
235
- await this.uploadDirectoryToSftp(localPath, remotePath, sftpConfig);
236
- } else {
237
- // Завантаження файлу на віддалений сервер
238
- await sftp.put(localPath, remotePath);
239
- console.log(`Передано файл: ${localPath} -> ${remotePath}`);
232
+ for (const item of items) {
233
+ const localItemPath = path.join(localPath, item.name);
234
+ const remoteItemPath = `${remotePath}/${item.name}`;
235
+
236
+ if (item.isDirectory()) {
237
+ await this.uploadDirectoryToSftp(localItemPath, remoteItemPath, sftpConfig);
238
+ } else {
239
+ await sftp.put(localItemPath, remoteItemPath);
240
+ console.log(`Передано файл: ${localItemPath} -> ${remoteItemPath}`);
241
+ }
240
242
  }
243
+
244
+ } else if (stats.isFile()) {
245
+ // Якщо це файл
246
+ await sftp.put(localPath, remotePath);
247
+ console.log(`Передано файл: ${localPath} -> ${remotePath}`);
241
248
  }
242
249
 
243
250
  console.log('Усі файли та папки успішно передані.');
@@ -267,9 +274,9 @@ export class ServerUtil {
267
274
  }
268
275
 
269
276
 
270
- async extractUploadedZip(name:string, file:any) {
277
+ async extractUploadedZip(name:string, file:any, extractToPath:string ) {
271
278
  const zipFilePath = file.path;
272
- const outputDir = path.join(__dirname, '..', 'uploads', name);
279
+ const outputDir = path.join(extractToPath, name);
273
280
 
274
281
  console.log('Looking for ZIP file at:', zipFilePath);
275
282
  console.log('Extracting to:', outputDir);