diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/js/notSoFast/notSoFast.js | |
add: graphs et rushs
Diffstat (limited to 'graphs/js/notSoFast/notSoFast.js')
| -rw-r--r-- | graphs/js/notSoFast/notSoFast.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/graphs/js/notSoFast/notSoFast.js b/graphs/js/notSoFast/notSoFast.js new file mode 100644 index 0000000..113c8f6 --- /dev/null +++ b/graphs/js/notSoFast/notSoFast.js @@ -0,0 +1,33 @@ +const axios = require("axios"); + +async function notSoFast(host, port) { + let nbArticles = await axios.get(`http://${host}:${port}/articles`); + + nbArticles = nbArticles.data.message; + + const articles = []; + + if (0 + nbArticles === 0) { + return articles; + } + + let res = await axios.get(`http://${host}:${port}/articles/${0}`); + + articles.push(res.data); + for (let i = 1; i < 0 + nbArticles; i++) { + const delay = res.headers["x-ratelimit-reset"] * 1000 - Date.now(); + + if (res.headers["x-ratelimit-remaining"] == 0) { + await new Promise((oof) => setTimeout(oof, delay + 26)); + } + + res = await axios.get(`http://${host}:${port}/articles/${i}`); + articles.push(res.data); + } + + return articles; +} + +module.exports = { + notSoFast, +}; |
