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');
// 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
let data = null;
@ -15,10 +15,11 @@ async function get() {
// 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 => {
data = res.text();
.then(res => res.json().then(json => {
// eslint-disable-next-line no-undef
data = Buffer.from(json.content, json.encoding).toString('utf8');
timestamp = now;
});
}));
}
return data;