Spaces:
Sleeping
Sleeping
Codex commited on
Commit ·
982f9e2
1
Parent(s): 720f106
Add manual Status SMS button and endpoint
Browse files
server.js
CHANGED
|
@@ -580,6 +580,29 @@ app.post('/api/status-email', async (req, res) => {
|
|
| 580 |
}
|
| 581 |
});
|
| 582 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
async function start() {
|
| 584 |
try {
|
| 585 |
if (storageMode === 'db') {
|
|
@@ -879,6 +902,7 @@ app.get('/', (req, res) => {
|
|
| 879 |
<button class="btn-add" onclick="addWebsite()">Dodaj</button>
|
| 880 |
</div>
|
| 881 |
<button class="btn-status" onclick="sendStatusEmail()">Wyślij status mailem</button>
|
|
|
|
| 882 |
</div>
|
| 883 |
|
| 884 |
<div class="monitor-list" id="monitorList">
|
|
@@ -1063,6 +1087,21 @@ app.get('/', (req, res) => {
|
|
| 1063 |
}
|
| 1064 |
clearTimeout(timer);
|
| 1065 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1066 |
</script>
|
| 1067 |
</body>
|
| 1068 |
</html>
|
|
|
|
| 580 |
}
|
| 581 |
});
|
| 582 |
|
| 583 |
+
// Manual status report SMS
|
| 584 |
+
app.post('/api/status-sms', async (req, res) => {
|
| 585 |
+
console.log('Incoming status SMS request');
|
| 586 |
+
try {
|
| 587 |
+
let upCount = 0;
|
| 588 |
+
let issueCount = 0;
|
| 589 |
+
|
| 590 |
+
websites.forEach(site => {
|
| 591 |
+
const st = statuses[site.url];
|
| 592 |
+
if (st && st.status === 'UP') upCount++;
|
| 593 |
+
else issueCount++;
|
| 594 |
+
});
|
| 595 |
+
|
| 596 |
+
const msg = `Raport: Razem ${websites.length}, UP: ${upCount}, Błędy: ${issueCount}.`;
|
| 597 |
+
|
| 598 |
+
await sendViaBrevoSms(msg);
|
| 599 |
+
res.json({ success: true });
|
| 600 |
+
} catch (err) {
|
| 601 |
+
console.error('Error sending status SMS:', err.message);
|
| 602 |
+
res.status(500).json({ error: 'Failed to send status SMS' });
|
| 603 |
+
}
|
| 604 |
+
});
|
| 605 |
+
|
| 606 |
async function start() {
|
| 607 |
try {
|
| 608 |
if (storageMode === 'db') {
|
|
|
|
| 902 |
<button class="btn-add" onclick="addWebsite()">Dodaj</button>
|
| 903 |
</div>
|
| 904 |
<button class="btn-status" onclick="sendStatusEmail()">Wyślij status mailem</button>
|
| 905 |
+
<button class="btn-status" style="background-color: #8e44ad;" onclick="sendStatusSms()">Wyślij status SMS</button>
|
| 906 |
</div>
|
| 907 |
|
| 908 |
<div class="monitor-list" id="monitorList">
|
|
|
|
| 1087 |
}
|
| 1088 |
clearTimeout(timer);
|
| 1089 |
}
|
| 1090 |
+
|
| 1091 |
+
async function sendStatusSms() {
|
| 1092 |
+
if(!confirm('Czy na pewno wysłać płatny SMS?')) return;
|
| 1093 |
+
try {
|
| 1094 |
+
const resp = await fetch('/api/status-sms', { method: 'POST' });
|
| 1095 |
+
if (resp.ok) {
|
| 1096 |
+
alert('SMS wysłany (sprawdź telefon).');
|
| 1097 |
+
} else {
|
| 1098 |
+
alert('Błąd wysyłania SMS.');
|
| 1099 |
+
}
|
| 1100 |
+
} catch (error) {
|
| 1101 |
+
console.error('Error:', error);
|
| 1102 |
+
alert('Błąd komunikacji.');
|
| 1103 |
+
}
|
| 1104 |
+
}
|
| 1105 |
</script>
|
| 1106 |
</body>
|
| 1107 |
</html>
|