update data purging, re-enable channel selection

This commit is contained in:
Will Bradley
2025-10-11 22:04:03 -07:00
parent d19c071814
commit 18d5114f6f
6 changed files with 59 additions and 28 deletions
+18 -8
View File
@@ -173,17 +173,17 @@ const api = {
return this.request(`/api/messages?limit=${limit}`);
},
async sendMessage(from, text) {
async sendMessage(from, text, channel) {
return this.request('/api/messages/send', {
method: 'POST',
body: JSON.stringify({ text, from })
body: JSON.stringify({ from, text, channel })
});
},
async purgeData(days) {
async purgeData(hours) {
return this.request('/api/purge', {
method: 'POST',
body: JSON.stringify({ days })
body: JSON.stringify({ hours })
});
},
@@ -547,9 +547,10 @@ document.getElementById('send-message-form')?.addEventListener('submit', async (
const text = document.getElementById('message-text').value;
const from = parseInt(document.getElementById('message-from').value);
const channel = parseInt(document.getElementById('message-channel').value);
try {
await api.sendMessage(text, from);
await api.sendMessage(from, text, channel);
document.getElementById('message-text').value = '';
// Reload messages after a short delay
@@ -1045,14 +1046,23 @@ document.getElementById('refresh-map-btn')?.addEventListener('click', loadMap);
document.getElementById('purge-form')?.addEventListener('submit', async (e) => {
e.preventDefault();
const days = parseInt(document.getElementById('purge-days').value);
const hours = parseInt(document.getElementById('purge-hours').value);
if (!confirm(`Are you sure you want to delete data older than ${days} days? This cannot be undone.`)) {
// Format time period for display
let timePeriod;
if (hours < 24) {
timePeriod = `${hours} hour${hours !== 1 ? 's' : ''}`;
} else {
const days = hours / 24;
timePeriod = `${days} day${days !== 1 ? 's' : ''}`;
}
if (!confirm(`Are you sure you want to delete data older than ${timePeriod}? This cannot be undone.`)) {
return;
}
try {
const result = await api.purgeData(days);
const result = await api.purgeData(hours);
alert(`Successfully purged:\n${result.deleted.messages} messages\n${result.deleted.positions} positions\n${result.deleted.telemetry} telemetry records`);
// Reload stats