This commit is contained in:
Florent 2021-07-06 16:01:06 +02:00 committed by Florent F
parent afdd320056
commit db856aa6e2

View File

@ -1,5 +1,5 @@
import { ListenerRssAggregator } from 'listener-rss-agregator'; import { ListenerRssAggregator } from "listener-rss-agregator";
import { ListenerRSSInfos } from 'listener-rss'; import { ListenerRSSInfos } from "listener-rss";
type ListenerData = { type ListenerData = {
ChannelId: number; ChannelId: number;
firstUpdate: boolean; firstUpdate: boolean;
@ -10,8 +10,8 @@ let listenersDataBinding = new Map<string, ListenerData>();
let logger: any; let logger: any;
let firstUpdate = true; let firstUpdate = true;
import * as path from 'path'; import * as path from "path";
import fs from 'fs'; import fs from "fs";
async function register({ async function register({
registerSetting, registerSetting,
@ -22,35 +22,35 @@ async function register({
logger = peertubeHelpers.logger; logger = peertubeHelpers.logger;
registerSetting({ registerSetting({
name: 'ytb-urls', name: "ytb-urls",
label: 'liste des urls youtube a auto-importer', label: "liste des urls youtube a auto-importer",
type: 'input-textarea', type: "input-textarea",
}); });
logger.warn('setting register'); logger.warn("setting register");
fs.appendFileSync(path.join(basePath, '/storage.bd'), ''); // append fs.appendFileSync(path.join(basePath, "/storage.bd"), ""); // append
const configAggregator = await ListenerRssAggregator.instantiateAggregator( const configAggregator = await ListenerRssAggregator.instantiateAggregator(
path.join(basePath, '/storage.bd') path.join(basePath, "/storage.bd")
); );
myManager = new ListenerRssAggregator(configAggregator); myManager = new ListenerRssAggregator(configAggregator);
logger.warn('Aggregator created'); logger.warn("Aggregator created");
const inputs = await settingsManager.getSetting('ytb-urls'); const inputs = await settingsManager.getSetting("ytb-urls");
if (inputs) await addListeners(inputs); if (inputs) await addListeners(inputs);
logger.warn('Config loaded'); logger.warn("Config loaded");
settingsManager.onSettingsChange(async (settings: any) => { settingsManager.onSettingsChange(async (settings: any) => {
await addListeners(settings['ytb-urls']); await addListeners(settings["ytb-urls"]);
}); });
myManager.on('newEntries', (entries: any) => { myManager.on("newEntries", (entries: any) => {
const datas = listenersDataBinding.get(entries.addressListener); const datas = listenersDataBinding.get(entries.addressListener);
if (!datas) return; 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));
}); });
} }
@ -59,7 +59,7 @@ async function addListeners(listenerInput: string) {
try { try {
listeners = JSON.parse(listenerInput); listeners = JSON.parse(listenerInput);
} catch { } catch {
logger.warn('Erreur: malformé'); logger.warn("Erreur: malformé");
return; return;
} }
let newListeners = listeners.filter( let newListeners = listeners.filter(
@ -84,7 +84,7 @@ async function addListeners(listenerInput: string) {
await myManager.saveOverride(listeners); await myManager.saveOverride(listeners);
firstUpdate = true; firstUpdate = true;
if (logger) logger.warn('Configuration modifiée: ' + listenerInput); if (logger) logger.warn("Configuration modifiée: " + listenerInput);
myManager.startAll(); myManager.startAll();
} }