Merge remote-tracking branch 'origin/testing' into testing

This commit is contained in:
Amaury 2021-07-09 12:17:50 +02:00
commit ce19792a28

View File

@ -1,98 +1,110 @@
import { ListenerRssAggregator } from "listener-rss-agregator"; import { ListenerRssAggregator } from "listener-rss-agregator";
<<<<<<< HEAD
type ListenerData = {
ChannelId: number; type ListenerData = {
}; ChannelId: number;
};
let myManager: ListenerRssAggregator; =======
let listenersDataBinding = new Map<string, ListenerData>(); import { ListenerRSSInfos } from "listener-rss";
let logger: any; type ListenerData = {
ChannelId: number;
import * as path from "path"; firstUpdate: boolean;
import fs from "fs"; } & ListenerRSSInfos;
>>>>>>> origin/testing
async function register({
registerSetting, let myManager: ListenerRssAggregator;
settingsManager, let listenersDataBinding = new Map<string, ListenerData>();
peertubeHelpers, let logger: any;
}: any) {
const basePath = peertubeHelpers.plugin.getDataDirectoryPath(); import * as path from "path";
logger = peertubeHelpers.logger; import fs from "fs";
registerSetting({ async function register({
name: "ytb-urls", registerSetting,
label: "liste des urls youtube a auto-importer", settingsManager,
type: "input-textarea", peertubeHelpers,
}); }: any) {
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
logger.warn("setting register"); logger = peertubeHelpers.logger;
fs.appendFileSync(path.join(basePath, "/storage.bd"), "");
registerSetting({
const configAggregator = await ListenerRssAggregator.instantiateAggregator( name: "ytb-urls",
path.join(basePath, "/storage.bd") label: "liste des urls youtube a auto-importer",
); type: "input-textarea",
myManager = new ListenerRssAggregator(configAggregator); });
logger.warn("Aggregator created"); logger.warn("setting register");
<<<<<<< HEAD
const inputs = await settingsManager.getSetting("ytb-urls"); fs.appendFileSync(path.join(basePath, "/storage.bd"), "");
if (inputs) await addListeners(inputs); =======
fs.appendFileSync(path.join(basePath, "/storage.bd"), ""); // append
logger.warn("Config loaded"); >>>>>>> origin/testing
settingsManager.onSettingsChange(async (settings: any) => { const configAggregator = await ListenerRssAggregator.instantiateAggregator(
await addListeners(settings["ytb-urls"]); path.join(basePath, "/storage.bd")
}); );
myManager = new ListenerRssAggregator(configAggregator);
myManager.on("newEntries", (entries: any) => {
const datas = listenersDataBinding.get(entries.addressListener); logger.warn("Aggregator created");
if (!datas) return;
const inputs = await settingsManager.getSetting("ytb-urls");
logger.warn("Nouvelles entrées détéctées: " + JSON.stringify(entries)); if (inputs) await addListeners(inputs);
});
} logger.warn("Config loaded");
async function addListeners(listenerInput: string) { settingsManager.onSettingsChange(async (settings: any) => {
let listeners: ListenerData[]; await addListeners(settings["ytb-urls"]);
try { });
listeners = JSON.parse(listenerInput);
} catch { myManager.on("newEntries", (entries: any) => {
logger.warn("Erreur: malformé"); const datas = listenersDataBinding.get(entries.addressListener);
return; if (!datas) return;
}
let newListeners = listeners.filter( logger.warn("Nouvelles entrées détéctées: " + JSON.stringify(entries));
(item) => !listenersDataBinding.has(item.address) });
); }
let removedUrls = Array.from(listenersDataBinding.keys()).filter(
(url) => !listeners.some((listener) => listener.address === url) async function addListeners(listenerInput: string) {
); let listeners: ListenerData[];
try {
for (const newItem of newListeners) { listeners = JSON.parse(listenerInput);
listenersDataBinding.set(newItem.address, { } catch {
ChannelId: newItem.ChannelId, logger.warn("Erreur: malformé");
firstUpdate: true, return;
address: newItem.address, }
}); let newListeners = listeners.filter(
} (item) => !listenersDataBinding.has(item.address)
for (const removedUrl of removedUrls) { );
listenersDataBinding.delete(removedUrl); let removedUrls = Array.from(listenersDataBinding.keys()).filter(
} (url) => !listeners.some((listener) => listener.address === url)
);
myManager.stopAll();
await myManager.saveOverride(listeners); for (const newItem of newListeners) {
firstUpdate = true; listenersDataBinding.set(newItem.address, {
ChannelId: newItem.ChannelId,
if (logger) logger.warn("Configuration modifiée: " + listenerInput); firstUpdate: true,
address: newItem.address,
myManager.startAll(); });
} }
for (const removedUrl of removedUrls) {
async function unregister() { listenersDataBinding.delete(removedUrl);
myManager.stopAll(); }
return;
} myManager.stopAll();
await myManager.saveOverride(listeners);
module.exports = { firstUpdate = true;
register,
unregister, if (logger) logger.warn("Configuration modifiée: " + listenerInput);
};
myManager.startAll();
}
async function unregister() {
myManager.stopAll();
return;
}
module.exports = {
register,
unregister,
};