1
0
forked from sent/waves
This commit is contained in:
𓍼 2025-06-06 19:06:46 -05:00
parent 6fd71fa6fa
commit c2a6cb8639

View File

@ -456,19 +456,44 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
(async () => { (async () => {
try { const commitElement = document.getElementById('lastest-commit');
const res = await fetch('/api/latest-commit');
console.log('Fetching latest commit from API:', res); try {
if (!res.ok) { const res = await fetch('/api/latest-commit');
throw new Error(`HTTP error! status: ${res.status}`);
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}`);
}
} }
const { updates } = await res.json();
const u = updates[0]; if (res.status === 403) {
const commitUrl = `https://github.com/xojw/waves/commit/${u.sha}`; throw new Error('403 Forbidden — possibly rate limited or blocked.');
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 { throw new Error(`HTTP error! status: ${res.status}`);
document.getElementById('lastest-commit').textContent =
'Failed to load lastest commit';
} }
const { updates } = await res.json();
const u = updates[0];
const commitUrl = `https://github.com/xojw/waves/commit/${u.sha}`;
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';
}
})(); })();