Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,15 @@ document.addEventListener('DOMContentLoaded', function () {
};

const lang = isCzech ? 'czech' : 'english';
// Note on how to obtain the following JSON file, CURL example:
// curl -k -H https://ha.base48.cz/api/spaceapi -o api/base_status.json
// nginx proxies /api/spaceapi to Home Assistant, so this is same-origin.
// curl https://base48.cz/api/spaceapi

// Try to fetch the base status (with cache busting)
const cacheBuster = Date.now();
fetch(`https://ha.base48.cz/api/spaceapi?t=${cacheBuster}`, {
cache: 'no-cache',
headers: {
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache'
}
// No custom headers: they would trigger a CORS preflight, which HA
// answers with 403. The ?t= above is enough to bust the cache.
fetch(`/api/spaceapi?t=${cacheBuster}`, {
cache: 'no-cache'
})
.then(response => {
if (!response.ok) {
Expand All @@ -503,8 +501,8 @@ document.addEventListener('DOMContentLoaded', function () {
})
.then(data => {
// Check if the base is open based on the state field
// New API format: true/false
const isOpen = data.state;
// SpaceAPI 0.13: state is {"open": bool, "lastchange": ts}
const isOpen = data.state.open;

statusElement.textContent = isOpen ? texts[lang].open : texts[lang].closed;
statusElement.className = `base-status ${isOpen ? 'open' : 'closed'}`;
Expand Down