vtlab-generic-functions 1.0.26 → 1.0.27
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/ftp/ftpClientClass.js +13 -3
- package/package.json +1 -1
package/ftp/ftpClientClass.js
CHANGED
|
@@ -193,17 +193,27 @@ class FTPClientV2 {
|
|
|
193
193
|
/**
|
|
194
194
|
* Lists files in a folder on the FTP server.
|
|
195
195
|
* @param {string} folderPath Remote folder path to list files.
|
|
196
|
+
* @param {string} sort Sort order for the files. Possible values are 'asc' or 'desc'.
|
|
196
197
|
* @returns {Promise<Array<string>>} A Pro∏”mise resolving to an array of file names in the folder.
|
|
197
198
|
* @throws {Error} If listing files fails.
|
|
198
199
|
*/
|
|
199
|
-
async listFilesInFolder(folderPath) {
|
|
200
|
+
async listFilesInFolder(folderPath, sort='asc') {
|
|
200
201
|
try {
|
|
201
202
|
if (!this._isConnected) {
|
|
202
203
|
await this.connect(this._ftpCredentials);
|
|
203
204
|
}
|
|
204
205
|
const files = await this._ftpInstance.list(folderPath);
|
|
205
|
-
|
|
206
|
-
|
|
206
|
+
|
|
207
|
+
// remove directories
|
|
208
|
+
let filteredFiles = files && files.length ? files.filter(item => item.type !== 'd') : [];
|
|
209
|
+
// sort files by date
|
|
210
|
+
let filesOnly = filteredFiles.sort((a, b) => {
|
|
211
|
+
return sort === 'asc' ? a.date - b.date : b.date - a.date;
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// sort them from
|
|
215
|
+
return filesOnly.map((file) => file.name);
|
|
216
|
+
|
|
207
217
|
} catch (error) {
|
|
208
218
|
throw new Error(`Failed to list files in folder on FTP server: ${error.message}`);
|
|
209
219
|
}
|