Files
signalk-plugin/plugin/telegram/callbacks/logfile.js
Giuseppe Raffa bb8d267cd4 Aggiunta stili CSS per Kiosk, struttura HTML per la Mappa e Riferimenti ai Sensori
• Creato un nuovo file CSS per gli stili del chiosco (kiosk) con variabili, stili per le schede (card) e animazioni.
• Aggiunto un file HTML per l'interfaccia della mappa utilizzando Mapbox, inclusi gli stili e il JavaScript per le funzionalità della mappa.
• Introdotto un file JSON per i riferimenti ai sensori, definendo percorsi ed elementi per i dati di temperatura, vento, onde, posizione, batteria, motore e sistema.

Co-authored-by: Copilot <copilot@github.com>
2026-04-23 16:19:11 +02:00

70 lines
2.3 KiB
JavaScript

const recorder = require('../../cores/logs.local');
module.exports = {
prefix: 'logfile:',
handler: async (bot, query) => {
const chatId = query.message.chat.id;
const listMessageId = query.message.message_id;
// callback_data = logfile:<name>:<userMessageId>
const parts = query.data.split(':');
const logName = parts[1];
const userMessageId = parts[2];
// Elimina il messaggio con la lista dei file
try {
await bot.deleteMessage(chatId, listMessageId);
} catch (e) {}
// Ottieni il file e le sue informazioni
const filePath = recorder.getLogFile(logName);
if (!filePath) {
bot.answerCallbackQuery(query.id, { text: 'File non trovato' });
return;
}
// Controllo aggiuntivo: se il file è quello in registrazione attiva
const session = recorder.getSession();
if (session && session.name === logName) {
bot.answerCallbackQuery(query.id, {
text: `Il file "${logName}" è attualmente in uso per la registrazione attiva. Fermala per scaricarlo.`,
show_alert: true
});
return;
}
// Ottieni info del file
const fs = require('fs');
const stat = fs.statSync(filePath);
const sizeMB = (stat.size / (1024 * 1024)).toFixed(2);
const created = new Date(stat.birthtime).toLocaleDateString('it-IT', {
day: '2-digit', month: '2-digit', year: 'numeric',
hour: '2-digit', minute: '2-digit'
});
const caption = `*CSV\nCreato: ${created}\ ${sizeMB} MB`;
// Invia il file
const docMessage = await bot.sendDocument(chatId, filePath, {
caption: caption,
parse_mode: 'Markdown'
});
// Elimina il messaggio dell'utente (il comando /logs)
try {
if (userMessageId) {
await bot.deleteMessage(chatId, parseInt(userMessageId));
}
} catch (e) {}
// Dopo 5 secondi, elimina il messaggio con il documento
setTimeout(async () => {
try {
await bot.deleteMessage(chatId, docMessage.message_id);
} catch (e) {}
}, 10000); //dopo 10 secondi
bot.answerCallbackQuery(query.id);
}
};