Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

429 Too Many Request #8

Open
zmlee0514 opened this issue Apr 24, 2024 · 0 comments
Open

429 Too Many Request #8

zmlee0514 opened this issue Apr 24, 2024 · 0 comments

Comments

@zmlee0514
Copy link

zmlee0514 commented Apr 24, 2024

Generally, retrieving more than 60 pages would result in a status code 429 error in "loadPage" of EhRetriever.retrieve(). Maybe we should add some sleeping mechanism.

A naive version:

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
let fetchPage;
try {
    const url = `${this.ehentaiHost}/api.php`;
    const config = {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        // assign e = {'imgkey': ..., 'page': ...} to object literal {'method': ..., 'gid': ..., 'showkey': ...}
        // does not modify e
        body: JSON.stringify(Object.assign({
            method: 'showpage',
            gid: this.gallery.gid,
            showkey: this.showkey
        }, e))
    };
    let response = await this.fetch(url, config);
    while (response.status == 429) {
        await sleep(30000);
        response = await this.fetch(url, config);
    }
  
    if (!response.ok) {
       throw new Error(response.statusText);
    }
    fetchPage = await response.json();
} catch (error) {
    console.warn(error);
    throw error;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant