Skip to content

Instantly share code, notes, and snippets.

@killa-kyle
Created January 19, 2022 20:48
Show Gist options
  • Save killa-kyle/f56d1b9d7ec977c91c5fdb614544de41 to your computer and use it in GitHub Desktop.
Save killa-kyle/f56d1b9d7ec977c91c5fdb614544de41 to your computer and use it in GitHub Desktop.
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