Compare commits
No commits in common. "79e5331c3c3abe271cd5ee88e6cc0f5f30560258" and "e1256304103f4b7db425ccc5d1d824282952d695" have entirely different histories.
79e5331c3c
...
e125630410
2 changed files with 28 additions and 16 deletions
|
@ -7,10 +7,7 @@ const utils = require('../utils/utils');
|
||||||
// Home Page
|
// Home Page
|
||||||
router.get('/', (_, res) => {
|
router.get('/', (_, res) => {
|
||||||
readme.get()
|
readme.get()
|
||||||
.then(data => res.render('index', {
|
.then(data => res.render('index', { readme: marked.parse(data), firstname_placeholder: utils.randomFirstname() }));
|
||||||
readme: marked.parse(data),
|
|
||||||
firstname_placeholder: utils.randomFirstname()
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
|
@ -1,16 +1,31 @@
|
||||||
fs = require('fs');
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
// Retrieve the FAQ file
|
// URL of the repo
|
||||||
const get = () => {
|
const repoURL = 'https://git.kennel.ml/api/v1/repos/Anri/Constnium/contents/FAQ.md';
|
||||||
return new Promise(function(ok) {
|
|
||||||
fs.readFile('./FAQ.md', 'utf8', (err, data) => {
|
// Store the data from the repo
|
||||||
if (err) {
|
let data = null;
|
||||||
console.log(err);
|
|
||||||
ok('# Erreur 404\nImpossible de trouver la FAQ.');
|
// Store last time data as been pulled from the repo
|
||||||
}
|
let timestamp = 0;
|
||||||
ok(data);
|
|
||||||
});
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in a new issue