UNPKG

many-cloud

Version:

A Node module for abstracting file management and interfacing with a variety of cloud storages.

37 lines (36 loc) 966 B
module.exports = data => { return function(folderID) { return new Promise((resolve, reject) => { let nextPageToken = null; let iteration = 0; let res = {}; res.files = []; let nextPage = () => { if (nextPageToken != null || iteration == 0) { data .list_files(folderID, 1000, nextPageToken) .then(value => { if (value.files.length == 0) { resolve(res); return; } value.files.forEach((file, i) => { res.files.push(file); if (i == value.files.length - 1) { nextPageToken = value.nextPageToken; iteration++; nextPage(); } }); }) .catch(e => { reject(e); }); } else { resolve(res); } }; nextPage(); }); }; };