Add connection journal with service traffic details and interactive offline station map

This commit is contained in:
alberto committed 2026-10-15 23:17:44 +02:00
1 parent 78839f5bb4
commit 106b04d631
14 files changed
+168 -7

No files matched your search

+5 -1
View File
@@ -1,4 +1,5 @@
import http from 'node:http';
import {Journal} from './journal.mjs';
import {loadConfig,parseConfig,publicConfig,ownCall} from './config.mjs';
import {readFile, stat} from 'node:fs/promises';
import path from 'node:path';
@@ -16,6 +17,7 @@ import {parseAttachments,safeName,b2Body} from './attachments.mjs';
const dir=path.dirname(fileURLToPath(import.meta.url));
const config=await loadConfig();
const root=config.root;
const journal=new Journal(config,dir);
const upstream='http://127.0.0.1:'+config.httpPort;
const sessions=new Map(), attempts=new Map();
const port=config.port;
@@ -107,6 +109,8 @@ const server=http.createServer(async(req,res)=>{
if(url.pathname==='/api/chat/send'&&req.method==='POST'){const data=await body(req);chat.send(data.text,data.to);json(res,200,{ok:true});return;}
if(url.pathname==='/api/chat/topic'&&req.method==='POST'){chat.changeTopic((await body(req)).topic);json(res,200,{ok:true});return;}
if(url.pathname==='/api/logout'&&req.method==='POST'){const token=req.headers.cookie.match(/alnode=([a-f0-9]+)/)?.[1];sessions.delete(token);res.setHeader('Set-Cookie','alnode=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0');json(res,200,{ok:true});return;}
if(url.pathname==='/api/journal'&&req.method==='GET'){json(res,200,await journal.snapshot());return;}
if(url.pathname==='/api/stations/location'&&req.method==='POST'){const data=await body(req);json(res,200,await journal.saveLocation(String(data.call||''),String(data.locator||'')));return;}
if(url.pathname==='/api/dashboard'){json(res,200,await dashboard());return;}
if(url.pathname==='/api/telemetry'&&req.method==='GET'){json(res,200,telemetry);return;}
if(url.pathname==='/api/messages'&&req.method==='GET'){json(res,200,await messages());return;}
@@ -123,7 +127,7 @@ const server=http.createServer(async(req,res)=>{
}
if(req.method!=='GET'){json(res,405,{error:'Metodo non disponibile'});return;}
const vendor=url.pathname.match(/^\/vendor\/pdfjs\/(pdf\.min\.mjs|pdf\.worker\.min\.mjs|(?:standard_fonts|cmaps)\/[A-Za-z0-9_.-]+)$/);if(vendor&&!vendor[1].includes('..')){const bytes=await readFile(path.join(dir,'public','vendor','pdfjs',vendor[1]));res.writeHead(200,{'Content-Type':vendor[1].endsWith('.mjs')?'text/javascript':'application/octet-stream','Cache-Control':'public, max-age=86400'});res.end(bytes);return;}
const files={'/monitor.js':'monitor.js','/monitor.css':'monitor.css','/':'index.html','/app.js':'app.js','/enhancements.js':'enhancements.js','/notifications.js':'notifications.js','/winlink.js':'winlink.js','/mission.js':'mission.js','/attachments.js':'attachments.js','/mission.css':'mission.css','/style.css':'style.css','/dark.css':'dark.css'};const file=files[url.pathname];if(!file){json(res,404,{error:'Pagina non trovata'});return;}const bytes=await readFile(path.join(dir,'public',file));res.writeHead(200,{'Content-Type':file.endsWith('.css')?'text/css; charset=utf-8':file.endsWith('.js')?'text/javascript; charset=utf-8':'text/html; charset=utf-8','Cache-Control':'no-cache'});res.end(bytes);
const files={'/journal.js':'journal.js','/journal.css':'journal.css','/world-land.json':'world-land.json','/monitor.js':'monitor.js','/monitor.css':'monitor.css','/':'index.html','/app.js':'app.js','/enhancements.js':'enhancements.js','/notifications.js':'notifications.js','/winlink.js':'winlink.js','/mission.js':'mission.js','/attachments.js':'attachments.js','/mission.css':'mission.css','/style.css':'style.css','/dark.css':'dark.css'};const file=files[url.pathname];if(!file){json(res,404,{error:'Pagina non trovata'});return;}const bytes=await readFile(path.join(dir,'public',file));res.writeHead(200,{'Content-Type':file.endsWith('.json')?'application/json':file.endsWith('.css')?'text/css; charset=utf-8':file.endsWith('.js')?'text/javascript; charset=utf-8':'text/html; charset=utf-8','Cache-Control':'no-cache'});res.end(bytes);
}catch(e){json(res,502,{error:e.message||'BPQ temporaneamente non disponibile'});}
});
server.listen(port,'0.0.0.0',()=>console.log(`BPQ Console: http://127.0.0.1:${port}`));