uh
This commit is contained in:
parent
6fd71fa6fa
commit
c2a6cb8639
|
@ -456,19 +456,44 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
});
|
||||
|
||||
(async () => {
|
||||
const commitElement = document.getElementById('lastest-commit');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/latest-commit');
|
||||
|
||||
console.log('Fetching latest commit from API:', res);
|
||||
|
||||
if (!res.ok) {
|
||||
const remaining = res.headers.get('X-RateLimit-Remaining');
|
||||
const reset = res.headers.get('X-RateLimit-Reset');
|
||||
|
||||
console.warn(`Status: ${res.status}`);
|
||||
if (remaining !== null) {
|
||||
console.warn(`Rate limit remaining: ${remaining}`);
|
||||
if (Number(remaining) === 0) {
|
||||
const resetDate = reset ? new Date(Number(reset) * 1000) : 'unknown';
|
||||
throw new Error(`Rate limit exceeded. Try again at ${resetDate}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (res.status === 403) {
|
||||
throw new Error('403 Forbidden — possibly rate limited or blocked.');
|
||||
}
|
||||
|
||||
throw new Error(`HTTP error! status: ${res.status}`);
|
||||
}
|
||||
|
||||
const { updates } = await res.json();
|
||||
const u = updates[0];
|
||||
const commitUrl = `https://github.com/xojw/waves/commit/${u.sha}`;
|
||||
document.getElementById('lastest-commit').innerHTML =
|
||||
`<a href="${commitUrl}" class="hover-link" target="_blank" rel="noopener noreferrer"><i class="fa-solid fa-code-commit"></i> ${u.sha}</a>`;
|
||||
} catch {
|
||||
document.getElementById('lastest-commit').textContent =
|
||||
'Failed to load lastest commit';
|
||||
|
||||
commitElement.innerHTML = `
|
||||
<a href="${commitUrl}" class="hover-link" target="_blank" rel="noopener noreferrer">
|
||||
<i class="fa-solid fa-code-commit"></i> ${u.sha}
|
||||
</a>`;
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch latest commit:', err.message || err);
|
||||
|
||||
commitElement.textContent = 'Failed to load latest commit';
|
||||
}
|
||||
})();
|
Loading…
Reference in New Issue
Block a user