Use shared auth and proxy Home Assistant webhooks

This commit is contained in:
seo
2026-06-12 15:10:20 +09:00
parent a2a89998b6
commit 72aedf47e5
3 changed files with 128 additions and 121 deletions
+44 -34
View File
@@ -410,36 +410,36 @@ document.getElementById('wakeLockSwitch').addEventListener('change', async funct
document.getElementById('autoUpdateSwitch').addEventListener('change', () => {
syncUpdateBtn();
const isChecked = document.getElementById('autoUpdateSwitch')?.checked;
if (isChecked) {
fetch('https://ha.chaegeon.com/api/webhook/5P1HgWiDpaAK8E0B', { method: 'POST' });
} else {
fetch('https://ha.chaegeon.com/api/webhook/z2nHt75jRxWKo2zF', { method: 'POST' });
}
});
const isChecked = document.getElementById('autoUpdateSwitch')?.checked;
if (isChecked) {
callDeviceWebhook('auto_on');
} else {
callDeviceWebhook('auto_off');
}
});
['pagehide', 'visibilitychange', 'blur', 'beforeunload'].forEach(eventType => {
window.addEventListener(eventType, function (e) {
const switchEl = document.getElementById('autoUpdateSwitch');
const isAutoUpdateOn = switchEl?.checked;
if (isAutoUpdateOn) {
navigator.sendBeacon('https://ha.chaegeon.com/api/webhook/z2nHt75jRxWKo2zF');
// 스위치 UI 강제 끔
switchEl.checked = false;
const isAutoUpdateOn = switchEl?.checked;
if (isAutoUpdateOn) {
callDeviceWebhook('auto_off', true);
// 스위치 UI 강제 끔
switchEl.checked = false;
syncUpdateBtn();
}
});
});
setInterval(() => {
if (document.getElementById('autoUpdateSwitch')?.checked) {
fetch('https://ha.chaegeon.com/api/webhook/870ZNzB20WRkzjnh', { method: 'POST' });
}
}, 10000);
setInterval(() => {
if (document.getElementById('autoUpdateSwitch')?.checked) {
callDeviceWebhook('auto_tick');
}
}, 10000);
setInterval(() => {
if (lastUpdateISOTime) {
@@ -979,17 +979,17 @@ function fetchDeviceData(includeLang = true, range = null) {
if (s) params.set('startTime', s);
if (e) params.set('endTime', e);
const url = `https://chaegeon.com/custom/findmydevice/php/api.php?${params.toString()}`;
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'REDACTED_HA_TOKEN'
},
body: JSON.stringify({})
}).then(res => res.json());
}
const url = `https://chaegeon.com/custom/findmydevice/php/api.php?${params.toString()}`;
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: 'same-origin',
body: JSON.stringify({})
}).then(res => res.json());
}
function isIosSafari() {
const ua = window.navigator.userAgent;
@@ -1019,8 +1019,8 @@ function resetDisplayValues() {
});
}
function triggerForceUpdate() {
fetch('https://ha.chaegeon.com/api/webhook/g1M4dZrsiLTt1woqgDXL6wtBSNCp6HGsRSzRLnNV4Up2Tpy8kre0q33EGvB70H9ftw48oENbUngHhVEBRlBFLNA7x7MbcmwZnVSHU71BG83ROMy4MOqIDWGxpKvI1YPX', { method: 'POST' });
function triggerForceUpdate() {
callDeviceWebhook('force_update');
const el = document.getElementById('updateBtn');
if (!el) return;
@@ -1071,4 +1071,14 @@ function renderTrackFromDisplayedMarkers() {
} else {
mapState.trackLine.setPath(points);
}
}
}
function callDeviceWebhook(name, keepalive = false) {
return fetch('https://chaegeon.com/custom/findmydevice/php/api.php?action=webhook', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'same-origin',
keepalive,
body: JSON.stringify({ name })
}).catch(() => null);
}