I have implemented a function to fetch the drive files and display their path of the file in the drive. I take a file's parents field and hit the file API again to fetch the name of the parent folder name. If the folder has a parent again, then I call the same function again and so I made it recursive. I have a common array to populate the file paths name. So, If I can now process only one file at a time. If I try to process many files at a time since the array to populate path of a file is declared globally, the parallel process doesn't populate my file with appropriate results. Looking for a better approach.
let labels = [];
getDriveItems: ({params}) => {
// hit API to fetch all files
//for each file call get path
if (nextPageToken) {
getDriveItems({params})
}
}
getpath(fileDetails) {
if (fileDetails.parents) {
parentFileDetails = {get file details in parentFileDetails}
labels.push(parentFileDetails.title);
if (parentFileDetails.parents.length > 0) {
getpath(parentFileDetails);
}
}
}