Various improvements #3

Merged
amaury.joly merged 16 commits from various-improvements into master 2021-07-27 18:39:49 +02:00
Showing only changes of commit 85d38f7939 - Show all commits

View File

@ -61,25 +61,29 @@ async function register({
}
async function addListeners(listenerInput: string) {
let objs: ListenerData[];
let listeners: ListenerData[];
try {
objs = JSON.parse(listenerInput);
listeners = JSON.parse(listenerInput);
} catch {
logger.warn('Erreur: malformé');
return;
}
let newListeners = listeners.filter(item => !listenersDataBinding.has(item.address));
let removedUrls = Array.from(listenersDataBinding.keys()).filter(url => !listeners.some(listener => listener.url === url));
for (const item of objs) {
if (listenersDataBinding.has(item.address)) break;
listenersDataBinding.set(item.address, {
ChannelId: item.ChannelId,
firstUpdate: item.firstUpdate,
address: item.address,
for (const newItem of newListeners) {
listenersDataBinding.set(newItem.address, {
ChannelId: newItem.ChannelId,
firstUpdate: newItem.firstUpdate,
address: newItem.address,
});
}
for (const removedUrl of removedUrls) {
listenersDataBinding.delete(removedUrl);
}
myManager.stopAll();
await myManager.saveOverride(objs);
await myManager.saveOverride(listeners);
firstUpdate = true;
if (logger) logger.warn('Configuration modifiée: ' + listenerInput);