From db856aa6e24518433ea21226bfa81c1514e2ea1a Mon Sep 17 00:00:00 2001 From: Florent Date: Tue, 6 Jul 2021 16:01:06 +0200 Subject: [PATCH] Prettier --- src/main.ts | 132 ++++++++++++++++++++++++++-------------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/src/main.ts b/src/main.ts index edcbdf8..5353e33 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ -import { ListenerRssAggregator } from 'listener-rss-agregator'; -import { ListenerRSSInfos } from 'listener-rss'; +import { ListenerRssAggregator } from "listener-rss-agregator"; +import { ListenerRSSInfos } from "listener-rss"; type ListenerData = { - ChannelId: number; - firstUpdate: boolean; + ChannelId: number; + firstUpdate: boolean; } & ListenerRSSInfos; let myManager: ListenerRssAggregator; @@ -10,91 +10,91 @@ let listenersDataBinding = new Map(); let logger: any; let firstUpdate = true; -import * as path from 'path'; -import fs from 'fs'; +import * as path from "path"; +import fs from "fs"; async function register({ - registerSetting, - settingsManager, - peertubeHelpers, + registerSetting, + settingsManager, + peertubeHelpers, }: any) { - const basePath = peertubeHelpers.plugin.getDataDirectoryPath(); - logger = peertubeHelpers.logger; + const basePath = peertubeHelpers.plugin.getDataDirectoryPath(); + logger = peertubeHelpers.logger; - registerSetting({ - name: 'ytb-urls', - label: 'liste des urls youtube a auto-importer', - type: 'input-textarea', - }); + registerSetting({ + name: "ytb-urls", + label: "liste des urls youtube a auto-importer", + type: "input-textarea", + }); - logger.warn('setting register'); - fs.appendFileSync(path.join(basePath, '/storage.bd'), ''); // append + logger.warn("setting register"); + fs.appendFileSync(path.join(basePath, "/storage.bd"), ""); // append - const configAggregator = await ListenerRssAggregator.instantiateAggregator( - path.join(basePath, '/storage.bd') - ); - myManager = new ListenerRssAggregator(configAggregator); + const configAggregator = await ListenerRssAggregator.instantiateAggregator( + path.join(basePath, "/storage.bd") + ); + myManager = new ListenerRssAggregator(configAggregator); - logger.warn('Aggregator created'); + logger.warn("Aggregator created"); - const inputs = await settingsManager.getSetting('ytb-urls'); - if (inputs) await addListeners(inputs); + const inputs = await settingsManager.getSetting("ytb-urls"); + if (inputs) await addListeners(inputs); - logger.warn('Config loaded'); + logger.warn("Config loaded"); - settingsManager.onSettingsChange(async (settings: any) => { - await addListeners(settings['ytb-urls']); - }); + settingsManager.onSettingsChange(async (settings: any) => { + await addListeners(settings["ytb-urls"]); + }); - myManager.on('newEntries', (entries: any) => { - const datas = listenersDataBinding.get(entries.addressListener); - if (!datas) return; + myManager.on("newEntries", (entries: any) => { + const datas = listenersDataBinding.get(entries.addressListener); + if (!datas) return; - logger.warn('Nouvelles entrées détéctées: ' + JSON.stringify(entries)); - }); + logger.warn("Nouvelles entrées détéctées: " + JSON.stringify(entries)); + }); } async function addListeners(listenerInput: string) { - let listeners: ListenerData[]; - try { - 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.address === url) - ); + let listeners: ListenerData[]; + try { + 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.address === url) + ); - for (const newItem of newListeners) { - listenersDataBinding.set(newItem.address, { - ChannelId: newItem.ChannelId, - firstUpdate: true, - address: newItem.address, - }); - } - for (const removedUrl of removedUrls) { - listenersDataBinding.delete(removedUrl); - } + for (const newItem of newListeners) { + listenersDataBinding.set(newItem.address, { + ChannelId: newItem.ChannelId, + firstUpdate: true, + address: newItem.address, + }); + } + for (const removedUrl of removedUrls) { + listenersDataBinding.delete(removedUrl); + } - myManager.stopAll(); - await myManager.saveOverride(listeners); - firstUpdate = true; + myManager.stopAll(); + await myManager.saveOverride(listeners); + firstUpdate = true; - if (logger) logger.warn('Configuration modifiée: ' + listenerInput); + if (logger) logger.warn("Configuration modifiée: " + listenerInput); - myManager.startAll(); + myManager.startAll(); } async function unregister() { - myManager.stopAll(); - return; + myManager.stopAll(); + return; } module.exports = { - register, - unregister, + register, + unregister, };