@bprotsyk/aso-core 2.0.36 → 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.
- package/lib/utils/server-util.d.ts +1 -1
- package/lib/utils/server-util.js +26 -20
- package/package.json +1 -1
- package/src/utils/server-util.ts +30 -23
|
@@ -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(
|
|
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>;
|
package/lib/utils/server-util.js
CHANGED
|
@@ -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(
|
|
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
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
package/src/utils/server-util.ts
CHANGED
|
@@ -207,37 +207,44 @@ export class ServerUtil {
|
|
|
207
207
|
return true;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
async uploadDirectoryToSftp(
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
222
|
-
const localPath = path.join(localDir, item.name);
|
|
223
|
-
const remotePath = `${remoteDir}/${item.name}`;
|
|
219
|
+
const stats = fs.statSync(localPath);
|
|
224
220
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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('Усі файли та папки успішно передані.');
|