use api endpoint

This commit is contained in:
Mylloon 2022-06-23 12:06:13 +02:00
parent 750a918599
commit cf17e628b3
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,7 +1,7 @@
const fetch = require('node-fetch'); const fetch = require('node-fetch');
// URL of the repo // URL of the repo
const repoURL = 'https://git.kennel.ml/Anri/Constnium/raw/branch/main/README.md'; const repoURL = 'https://git.kennel.ml/api/v1/repos/Anri/Constnium/contents/README.md';
// Store the data from the repo // Store the data from the repo
let data = null; let data = null;
@ -15,10 +15,11 @@ async function get() {
// If data is older than one day, refresh it // If data is older than one day, refresh it
if (Math.ceil(Math.abs(now - timestamp) / (1000 * 3600 * 24)) > 2 || data === null) { if (Math.ceil(Math.abs(now - timestamp) / (1000 * 3600 * 24)) > 2 || data === null) {
await fetch(repoURL) await fetch(repoURL)
.then(res => { .then(res => res.json().then(json => {
data = res.text(); // eslint-disable-next-line no-undef
data = Buffer.from(json.content, json.encoding).toString('utf8');
timestamp = now; timestamp = now;
}); }));
} }
return data; return data;