Use pagination in model code for mailbox listing
This commit is contained in:
@@ -6,16 +6,30 @@ function create() {
|
||||
const accessToken = localStorage.token;
|
||||
|
||||
return {
|
||||
async list(domain, search = '') {
|
||||
let result;
|
||||
try {
|
||||
result = await fetcher.get(`${API_ORIGIN}/api/v1/mail/${domain}/mailboxes`, { page: 1, per_page: 10000, access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
async list(domain) {
|
||||
const perPage = 5000;
|
||||
|
||||
let page = 1;
|
||||
let mailboxes = [];
|
||||
|
||||
while (true) {
|
||||
let result;
|
||||
try {
|
||||
result = await fetcher.get(`${API_ORIGIN}/api/v1/mail/${domain}/mailboxes`, { page, per_page: perPage, access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
|
||||
if (result.status !== 200) return [result];
|
||||
|
||||
mailboxes = mailboxes.concat(result.body.mailboxes);
|
||||
|
||||
if (result.body.mailboxes.length < perPage) break;
|
||||
|
||||
page++;
|
||||
}
|
||||
|
||||
if (result.status !== 200) return [result];
|
||||
return [null, result.body.mailboxes];
|
||||
return [null, mailboxes];
|
||||
},
|
||||
async get(domain, name) {
|
||||
let result;
|
||||
|
||||
Reference in New Issue
Block a user