Compare commits

..

No commits in common. "79e5331c3c3abe271cd5ee88e6cc0f5f30560258" and "e1256304103f4b7db425ccc5d1d824282952d695" have entirely different histories.

2 changed files with 28 additions and 16 deletions

View file

@ -7,10 +7,7 @@ const utils = require('../utils/utils');
// Home Page
router.get('/', (_, res) => {
readme.get()
.then(data => res.render('index', {
readme: marked.parse(data),
firstname_placeholder: utils.randomFirstname()
}));
.then(data => res.render('index', { readme: marked.parse(data), firstname_placeholder: utils.randomFirstname() }));
});
module.exports = router;

View file

@ -1,16 +1,31 @@
fs = require('fs');
const fetch = require('node-fetch');
// 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.');
// 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";
});
}
ok(data);
});
});
return data;
}
module.exports = {