From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/js/notSoFast/notSoFast.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 graphs/js/notSoFast/notSoFast.js (limited to 'graphs/js/notSoFast/notSoFast.js') 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, +}; -- cgit v1.2.3