forked from Outils-PeerTube/peertube-plugin-auto-import-ytb
Merge remote-tracking branch 'origin/testing' into testing
This commit is contained in:
commit
ce19792a28
208
src/main.ts
208
src/main.ts
|
@ -1,98 +1,110 @@
|
|||
import { ListenerRssAggregator } from "listener-rss-agregator";
|
||||
|
||||
type ListenerData = {
|
||||
ChannelId: number;
|
||||
};
|
||||
|
||||
let myManager: ListenerRssAggregator;
|
||||
let listenersDataBinding = new Map<string, ListenerData>();
|
||||
let logger: any;
|
||||
|
||||
import * as path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
async function register({
|
||||
registerSetting,
|
||||
settingsManager,
|
||||
peertubeHelpers,
|
||||
}: any) {
|
||||
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
||||
logger = peertubeHelpers.logger;
|
||||
|
||||
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"), "");
|
||||
|
||||
const configAggregator = await ListenerRssAggregator.instantiateAggregator(
|
||||
path.join(basePath, "/storage.bd")
|
||||
);
|
||||
myManager = new ListenerRssAggregator(configAggregator);
|
||||
|
||||
logger.warn("Aggregator created");
|
||||
|
||||
const inputs = await settingsManager.getSetting("ytb-urls");
|
||||
if (inputs) await addListeners(inputs);
|
||||
|
||||
logger.warn("Config loaded");
|
||||
|
||||
settingsManager.onSettingsChange(async (settings: any) => {
|
||||
await addListeners(settings["ytb-urls"]);
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
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;
|
||||
|
||||
if (logger) logger.warn("Configuration modifiée: " + listenerInput);
|
||||
|
||||
myManager.startAll();
|
||||
}
|
||||
|
||||
async function unregister() {
|
||||
myManager.stopAll();
|
||||
return;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
register,
|
||||
unregister,
|
||||
};
|
||||
import { ListenerRssAggregator } from "listener-rss-agregator";
|
||||
<<<<<<< HEAD
|
||||
|
||||
type ListenerData = {
|
||||
ChannelId: number;
|
||||
};
|
||||
=======
|
||||
import { ListenerRSSInfos } from "listener-rss";
|
||||
type ListenerData = {
|
||||
ChannelId: number;
|
||||
firstUpdate: boolean;
|
||||
} & ListenerRSSInfos;
|
||||
>>>>>>> origin/testing
|
||||
|
||||
let myManager: ListenerRssAggregator;
|
||||
let listenersDataBinding = new Map<string, ListenerData>();
|
||||
let logger: any;
|
||||
|
||||
import * as path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
async function register({
|
||||
registerSetting,
|
||||
settingsManager,
|
||||
peertubeHelpers,
|
||||
}: any) {
|
||||
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
||||
logger = peertubeHelpers.logger;
|
||||
|
||||
registerSetting({
|
||||
name: "ytb-urls",
|
||||
label: "liste des urls youtube a auto-importer",
|
||||
type: "input-textarea",
|
||||
});
|
||||
|
||||
logger.warn("setting register");
|
||||
<<<<<<< HEAD
|
||||
fs.appendFileSync(path.join(basePath, "/storage.bd"), "");
|
||||
=======
|
||||
fs.appendFileSync(path.join(basePath, "/storage.bd"), ""); // append
|
||||
>>>>>>> origin/testing
|
||||
|
||||
const configAggregator = await ListenerRssAggregator.instantiateAggregator(
|
||||
path.join(basePath, "/storage.bd")
|
||||
);
|
||||
myManager = new ListenerRssAggregator(configAggregator);
|
||||
|
||||
logger.warn("Aggregator created");
|
||||
|
||||
const inputs = await settingsManager.getSetting("ytb-urls");
|
||||
if (inputs) await addListeners(inputs);
|
||||
|
||||
logger.warn("Config loaded");
|
||||
|
||||
settingsManager.onSettingsChange(async (settings: any) => {
|
||||
await addListeners(settings["ytb-urls"]);
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
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;
|
||||
|
||||
if (logger) logger.warn("Configuration modifiée: " + listenerInput);
|
||||
|
||||
myManager.startAll();
|
||||
}
|
||||
|
||||
async function unregister() {
|
||||
myManager.stopAll();
|
||||
return;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
register,
|
||||
unregister,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user