use api endpoint
This commit is contained in:
parent
750a918599
commit
cf17e628b3
1 changed files with 5 additions and 4 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue