forked from Outils-PeerTube/peertube-plugin-auto-import-ytb
Fix addListeners
This commit is contained in:
parent
f21f752cbb
commit
85d38f7939
22
src/main.ts
22
src/main.ts
|
@ -61,25 +61,29 @@ async function register({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addListeners(listenerInput: string) {
|
async function addListeners(listenerInput: string) {
|
||||||
let objs: ListenerData[];
|
let listeners: ListenerData[];
|
||||||
try {
|
try {
|
||||||
objs = JSON.parse(listenerInput);
|
listeners = JSON.parse(listenerInput);
|
||||||
} catch {
|
} catch {
|
||||||
logger.warn('Erreur: malformé');
|
logger.warn('Erreur: malformé');
|
||||||
return;
|
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) {
|
for (const newItem of newListeners) {
|
||||||
if (listenersDataBinding.has(item.address)) break;
|
listenersDataBinding.set(newItem.address, {
|
||||||
listenersDataBinding.set(item.address, {
|
ChannelId: newItem.ChannelId,
|
||||||
ChannelId: item.ChannelId,
|
firstUpdate: newItem.firstUpdate,
|
||||||
firstUpdate: item.firstUpdate,
|
address: newItem.address,
|
||||||
address: item.address,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
for (const removedUrl of removedUrls) {
|
||||||
|
listenersDataBinding.delete(removedUrl);
|
||||||
|
}
|
||||||
|
|
||||||
myManager.stopAll();
|
myManager.stopAll();
|
||||||
await myManager.saveOverride(objs);
|
await myManager.saveOverride(listeners);
|
||||||
firstUpdate = true;
|
firstUpdate = true;
|
||||||
|
|
||||||
if (logger) logger.warn('Configuration modifiée: ' + listenerInput);
|
if (logger) logger.warn('Configuration modifiée: ' + listenerInput);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user