summaryrefslogtreecommitdiff
path: root/graphs/js/notSoFast/notSoFast.js
diff options
context:
space:
mode:
Diffstat (limited to 'graphs/js/notSoFast/notSoFast.js')
-rw-r--r--graphs/js/notSoFast/notSoFast.js33
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,
+};