Created
January 19, 2022 20:48
-
-
Save killa-kyle/f56d1b9d7ec977c91c5fdb614544de41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAll(request) { | |
return request.then(function (response) { | |
if (!response._paging || !response._paging.next) { | |
return response; | |
} | |
// progress is next / total pages * 10 | |
let _next = response._paging.next._options.endpoint.split("=")[1]; | |
let _total = response._paging.totalPages; | |
let _progress = (_next / _total) * 10; | |
progressBar.start(_total, _next - 1); | |
progressBar.update(_next); | |
// Request the next page and return both responses as one collection | |
return Promise.all([response, getAll(response._paging.next)]).then( | |
function (responses) { | |
return _.flatten(responses); | |
} | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment