@bprotsyk/aso-core 2.0.36 → 2.0.38

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.
@@ -18,13 +18,13 @@ server {
18
18
 
19
19
  error_log /var/log/nginx/{{domain}}.error.log error;
20
20
 
21
- root {{rootPath}}{{domain}};
21
+ root {{rootPath}}/{{domain}};
22
22
  error_page 404 /policy/index.html;
23
23
 
24
24
  server_name www.{{domain}} {{domain}};
25
25
 
26
26
  location / {
27
- root {{rootPath}}{{domain}};
27
+ root {{rootPath}}/{{domain}};
28
28
  add_header 'Access-Control-Allow-Origin' '*';
29
29
  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
30
30
  add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Accept, Content-Type, X-Requested-With';
@@ -29,7 +29,7 @@ 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
35
  extractUploadedZip(name: string, file: any, extractToPath: string): Promise<void>;
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "2.0.36",
3
+ "version": "2.0.38",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -18,13 +18,13 @@ server {
18
18
 
19
19
  error_log /var/log/nginx/{{domain}}.error.log error;
20
20
 
21
- root {{rootPath}}{{domain}};
21
+ root {{rootPath}}/{{domain}};
22
22
  error_page 404 /policy/index.html;
23
23
 
24
24
  server_name www.{{domain}} {{domain}};
25
25
 
26
26
  location / {
27
- root {{rootPath}}{{domain}};
27
+ root {{rootPath}}/{{domain}};
28
28
  add_header 'Access-Control-Allow-Origin' '*';
29
29
  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
30
30
  add_header 'Access-Control-Allow-Headers' 'Origin, Authorization, Accept, Content-Type, X-Requested-With';
@@ -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('Усі файли та папки успішно передані.');