Aggiunge 2 nuove variabili d'ambiente:
- SIGNALK_FILES, per specificare dove verranno salvati i file generati dal plugin - HOST_NAME, per specificare il nome del dispositivo che sta hostando il plugin. Inoltre, migliora il codice e lo adatta al nuovo path variabile SIGNALK_FILES
This commit is contained in:
@@ -1,11 +1,46 @@
|
||||
const dotenv = require("dotenv");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
// Carica il file .env dalla root del plugin
|
||||
dotenv.config({ path: path.resolve(__dirname, "..", ".env"), quiet: true });
|
||||
|
||||
const config = {
|
||||
telegramBotToken: process.env.TELEGRAM_BOT_TOKEN,
|
||||
// Base path per tutti i file generati dal server
|
||||
const SIGNALK_FILES = process.env.SIGNALK_FILES || path.resolve(__dirname, "..", "data");
|
||||
|
||||
// Crea le directory necessarie se non esistono
|
||||
function ensureDir(dirPath) {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
console.log(`[Config] Creata directory: ${dirPath}`);
|
||||
}
|
||||
return dirPath;
|
||||
}
|
||||
|
||||
// Paths per i vari tipi di file
|
||||
const paths = {
|
||||
// Base
|
||||
base: SIGNALK_FILES,
|
||||
|
||||
// Logs: hourly_archive.json, logs_references.json, saved_datas/
|
||||
logs: ensureDir(path.join(SIGNALK_FILES, "logs")),
|
||||
hourlyArchive: path.join(SIGNALK_FILES, "logs", "hourly_archive.json"),
|
||||
logsReferences: path.join(SIGNALK_FILES, "logs", "logs_references.json"),
|
||||
savedDatas: ensureDir(path.join(SIGNALK_FILES, "logs", "saved_datas")),
|
||||
|
||||
// Private: authorized_admins.txt, telegram_users.json
|
||||
private: ensureDir(path.join(SIGNALK_FILES, "private")),
|
||||
authorizedAdmins: path.join(SIGNALK_FILES, "private", "authorized_admins.txt"),
|
||||
telegramUsers: path.join(SIGNALK_FILES, "private", "telegram_users.json"),
|
||||
|
||||
// Sensors: sensors.references.json
|
||||
sensors: ensureDir(path.join(SIGNALK_FILES, "sensors")),
|
||||
sensorsReferences: path.join(SIGNALK_FILES, "sensors", "sensors.references.json")
|
||||
};
|
||||
|
||||
module.exports = { config };
|
||||
const config = {
|
||||
telegramBotToken: process.env.TELEGRAM_BOT_TOKEN,
|
||||
paths
|
||||
};
|
||||
|
||||
module.exports = { config, paths };
|
||||
Reference in New Issue
Block a user