Add official Winlink gateway selector and guarded radio mail sync
This commit is contained in:
1 parent
75a6d52e3b
commit
29b4064e82
10 files changed
+161
-4
No files matched your search
+2
-1
@@ -38,7 +38,7 @@ export function forwardingHistory(text,peer,now=Date.now()){
|
||||
return parseBbsLog(filtered).map(s=>({startedAt:s.startedAt,endedAt:s.endedAt,connectedAt:s.connectedAt,sent:Math.max(s.sentMessages,confirmed.get(s.startedAt)||0),received:s.receivedMessages,status:s.endedAt?s.status:now-Date.parse(s.startedAt)>30*60000?'unknown':s.connectedAt?'connected':'calling',direction:s.direction,error:s.error||null,complete:s.exchangeComplete||false})).sort((a,b)=>Date.parse(b.startedAt)-Date.parse(a.startedAt)).slice(0,8);
|
||||
}
|
||||
export class Forwarding{
|
||||
constructor(config,bpq,radio){this.config=config;this.bpq=bpq;this.radio=radio;this.chain=Promise.resolve();this.requested=new Map();this.cached=null;this.cachedAt=0;}
|
||||
constructor(config,bpq,radio){this.config=config;this.bpq=bpq;this.radio=radio;this.chain=Promise.resolve();this.requested=new Map();this.lockedPeers=new Map();this.cached=null;this.cachedAt=0;}
|
||||
exclusive(fn){const result=this.chain.then(fn);this.chain=result.catch(()=>{});return result;}
|
||||
async profiles(){return parseForwarding(await readFile(path.join(this.config.root,'BPQMailChat','BPQMail.cfg'),'utf8'),this.config.ports);}
|
||||
async context(){const status=await this.bpq('/Mail/Status');const link=status.match(/href=(\/Mail\/FWD\?[^\s>]+)/)?.[1];if(!link)throw new Error('Forwarding BPQ non disponibile');const page=await this.bpq(link);const key=page.match(/var Key\s*=\s*"([^"]+)"/)?.[1];if(!key)throw new Error('Sessione forwarding non disponibile');return key;}
|
||||
@@ -52,6 +52,7 @@ export class Forwarding{
|
||||
this.cached={profiles:out,updatedAt:new Date().toISOString(),scheduleTimezone:profiles.some(p=>p.timesLocal)?'Locale server BPQ':'UTC',radio:this.radio(),errors};this.cachedAt=Date.now();return this.cached;
|
||||
});}
|
||||
start(peer){return this.exclusive(async()=>{
|
||||
if(this.lockedPeers.has(peer))throw new Error(this.lockedPeers.get(peer));
|
||||
const p=(await this.profiles()).find(p=>p.call===peer);if(!p?.configured)throw new Error('Profilo di forwarding non configurato');
|
||||
if(Date.now()-(this.requested.get(peer)||0)<30000)throw new Error('Sincronizzazione già richiesta: attendi 30 secondi');
|
||||
const last=forwardingHistory(await this.logs().catch(()=>''),peer)[0];if(last&&!last.endedAt&&['calling','connected'].includes(last.status))throw new Error('Forwarding già in corso per questo partner');
|
||||
|
||||
Reference in new issue
Block a user