Multiple asynchronous calls breaks
nesticle8bit opened this issue · 1 comments
nesticle8bit commented
I created an algorithm to map all the files and folders from my ftp but i get an error when the folder is too big and breaks with this error:
[grunt-develop] > \app\controllers\mapper.controller.js:27
Promise.all(list.map(async (file) => {
^
TypeError: Cannot read property 'map' of undefined
My code is this:
let ftpPathMapper = async (folder) => {
let listaArchivosCarpetas = await returnPathDocumentList(folder).then(list => list);
let json = JSON.stringify(listaArchivosCarpetas);
fs.writeFileSync(`./mapper/${folder.replace('/docs/', '')}.json`, json);
};
let returnPathDocumentList = async (path) => {
return await new Promise((resolve, reject) => {
let ftpClient = new ftp();
ftpClient.on('ready', function () {
ftpClient.list(path, function (err, list) {
if (err)
reject(err);
Promise.all(list.map(async (file) => {
let folderPath = `${path}/${file.name}/`.replace('//', '/');
let currentRes = {
name: file.name,
type: file.type,
path: folderPath,
Subcarpeta: []
};
if (currentRes.type === 'd')
currentRes.Subcarpeta = await returnPathDocumentList(folderPath);
console.log(folderPath);
return currentRes;
})).then(s => {
// ftpClient.destroy();
resolve(s);
ftpClient.end();
ftpClient.destroy();
});
});
}).connect({
host: "url",
port: 21,
user: "user",
password: "pass",
});
})
};
But i dont really know why with bigger folders crash
nesticle8bit commented
The problem that I found with this library is that it does not recognize accents in Spanish (á, é, í, ó, ú), so when I'm going through all the FTP when it finds a folder with that accent immediately crashes, there is some way that the bookstore accept special characters? or Unicode?
Thank you