fix: add resilient github and changelog API fallbacks

This commit is contained in:
svemagie
2026-03-08 03:03:09 +01:00
parent 79011c8cf8
commit d7bb8f0c52
4 changed files with 260 additions and 42 deletions

View File

@@ -158,11 +158,37 @@ function changelogApp() {
await this.fetchChangelog(30);
},
async fetchJson(paths) {
for (const path of paths) {
try {
const response = await fetch(path);
if (response.ok) {
return {
ok: true,
data: await response.json(),
};
}
} catch {
// Try next candidate path.
}
}
return {
ok: false,
data: null,
};
},
async fetchChangelog(days) {
try {
const response = await fetch('/githubapi/api/changelog?days=' + days);
if (!response.ok) throw new Error('Failed to fetch');
const data = await response.json();
const result = await this.fetchJson([
'/githubapi/api/changelog?days=' + days,
'/github/api/changelog?days=' + days,
]);
if (!result.ok) throw new Error('Failed to fetch');
const data = result.data || {};
this.commits = data.commits || [];
this.categories = data.categories || {};
this.currentDays = data.days;