mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-23 16:13:50 +00:00
download household on same address
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
|
||||
const _fetchAction = (page, uri, params) => {
|
||||
const item_per_page = 50;
|
||||
if (params === undefined) {
|
||||
params = {};
|
||||
}
|
||||
let url = uri + '?' + new URLSearchParams({ item_per_page, page, ...params });
|
||||
|
||||
return fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
}).then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error({ m: response.statusText });
|
||||
});
|
||||
};
|
||||
|
||||
const fetchResults = async (uri, params) => {
|
||||
let promises = [],
|
||||
page = 1;
|
||||
let firstData = await _fetchAction(page, uri, params);
|
||||
console.log('firstData', firstData);
|
||||
|
||||
promises.push(Promise.resolve(firstData.results));
|
||||
console.log('more ?', firstData.pagination.more);
|
||||
|
||||
if (firstData.pagination.more) {
|
||||
do {
|
||||
page = ++page;
|
||||
promises.push(_fetchAction(page, uri, params).then(r => Promise.resolve(r.results)));
|
||||
} while (page * firstData.pagination.items_per_page < firstData.count)
|
||||
}
|
||||
|
||||
return Promise.all(promises).then(values => values.flat());
|
||||
};
|
||||
|
||||
export {
|
||||
fetchResults
|
||||
};
|
@@ -1,15 +1,7 @@
|
||||
import { fetchResults } from 'ChillMainAssets/lib/api/download.js';
|
||||
|
||||
const fetchScopes = () => {
|
||||
return window.fetch('/api/1.0/main/scope.json').then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
}).then(data => {
|
||||
//console.log(data);
|
||||
return new Promise((resolve, reject) => {
|
||||
//console.log(data);
|
||||
resolve(data.results);
|
||||
});
|
||||
});
|
||||
return fetchResults('/api/1.0/main/scope.json');
|
||||
};
|
||||
|
||||
export {
|
||||
|
Reference in New Issue
Block a user