From 79e5331c3c3abe271cd5ee88e6cc0f5f30560258 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 23 Jun 2022 20:52:17 +0200 Subject: [PATCH] don't retrieve data from internet --- src/utils/readme.js | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/utils/readme.js b/src/utils/readme.js index 199a733..86af387 100644 --- a/src/utils/readme.js +++ b/src/utils/readme.js @@ -1,31 +1,16 @@ -const fetch = require('node-fetch'); +fs = require('fs'); -// URL of the repo -const repoURL = 'https://git.kennel.ml/api/v1/repos/Anri/Constnium/contents/FAQ.md'; - -// Store the data from the repo -let data = null; - -// Store last time data as been pulled from the repo -let timestamp = 0; - -// Retrieve the data from the repo -async function get() { - const now = Date.now(); - // If data is older than one day, refresh it - if (Math.ceil(Math.abs(now - timestamp) / (1000 * 3600 * 24)) > 2 || data === null) { - await fetch(repoURL) - .then(res => res.json().then(json => { - // eslint-disable-next-line no-undef - data = Buffer.from(json.content, json.encoding).toString('utf8'); - timestamp = now; - })) - .catch(() => { - data = "# Constnium"; - }); - } - - return data; +// Retrieve the FAQ file +const get = () => { + return new Promise(function(ok) { + fs.readFile('./FAQ.md', 'utf8', (err, data) => { + if (err) { + console.log(err); + ok('# Erreur 404\nImpossible de trouver la FAQ.'); + } + ok(data); + }); + }); } module.exports = {