Translate labels and log messages
This commit is contained in:
parent
9597cddc80
commit
8f8f0c3cb0
224
src/main.ts
224
src/main.ts
|
@ -1,113 +1,111 @@
|
||||||
import { ListenerRssAggregator } from "listener-rss-agregator";
|
import { ListenerRssAggregator } from "listener-rss-agregator";
|
||||||
import { ListenerRss } from "listener-rss";
|
import { ListenerRss } from "listener-rss";
|
||||||
import { PeerTubeRequester } from "../lib/peertubeRequester";
|
import { PeerTubeRequester } from "../lib/peertubeRequester";
|
||||||
|
|
||||||
type ListenerData = ListenerRss.Config & {
|
type ListenerData = ListenerRss.Config & {
|
||||||
address: string;
|
address: string;
|
||||||
channelId: string;
|
channelId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
let myManager: ListenerRssAggregator;
|
let myManager: ListenerRssAggregator;
|
||||||
let listenersDataBinding = new Map<string, ListenerData>();
|
let listenersDataBinding = new Map<string, ListenerData>();
|
||||||
let logger: any;
|
let logger: any;
|
||||||
let peertube: PeerTubeRequester;
|
let peertube: PeerTubeRequester;
|
||||||
|
|
||||||
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,
|
||||||
settingsManager,
|
settingsManager,
|
||||||
peertubeHelpers,
|
peertubeHelpers,
|
||||||
}: any) {
|
}: any) {
|
||||||
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
||||||
logger = peertubeHelpers.logger;
|
logger = peertubeHelpers.logger;
|
||||||
|
|
||||||
registerSetting({
|
registerSetting({
|
||||||
name: "ytb-urls",
|
name: "ytb-urls",
|
||||||
label: "liste des urls youtube a auto-importer",
|
label: 'URL list of Youtube channel to synchronize',
|
||||||
type: "input-textarea",
|
type: "input-textarea",
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.warn("setting register");
|
logger.debug("setting register");
|
||||||
fs.appendFileSync(path.join(basePath, "/storage.bd"), "");
|
fs.appendFileSync(path.join(basePath, "/storage.bd"), "");
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
peertube = new PeerTubeRequester({
|
peertube = new PeerTubeRequester({
|
||||||
domain_name: "http://localhost:9000",
|
domain_name: "http://localhost:9000",
|
||||||
username: "root",
|
username: "root",
|
||||||
password: "test",
|
password: "test",
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.warn("Aggregator created");
|
logger.debug("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.debug("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(
|
logger.debug(
|
||||||
"Nouvelles entrées détéctées: " +
|
"New entries detected from channel #%i: %s",
|
||||||
JSON.stringify(entries) +
|
datas.channelId,
|
||||||
" de " +
|
JSON.stringify(entries)
|
||||||
datas.channelId
|
);
|
||||||
);
|
for (const item of entries.items)
|
||||||
for (const item of entries.items)
|
peertube.apiRequest({
|
||||||
peertube.apiRequest({
|
channelId: datas.channelId,
|
||||||
channelId: datas.channelId,
|
targetUrl: item.link,
|
||||||
targetUrl: item.link,
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
async function addListeners(listenerInput: string) {
|
||||||
async function addListeners(listenerInput: string) {
|
let listeners: ListenerData[];
|
||||||
let listeners: ListenerData[];
|
try {
|
||||||
try {
|
listeners = JSON.parse(listenerInput);
|
||||||
listeners = JSON.parse(listenerInput);
|
} catch {
|
||||||
} catch {
|
logger.error("Malformed URL");
|
||||||
logger.warn("Erreur: malformé");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
let newListeners = listeners.filter(
|
||||||
let newListeners = listeners.filter(
|
(item) => !listenersDataBinding.has(item.address)
|
||||||
(item) => !listenersDataBinding.has(item.address)
|
);
|
||||||
);
|
let removedUrls = Array.from(listenersDataBinding.keys()).filter(
|
||||||
let removedUrls = Array.from(listenersDataBinding.keys()).filter(
|
(url) => !listeners.some((listener) => listener.address === url)
|
||||||
(url) => !listeners.some((listener) => listener.address === url)
|
);
|
||||||
);
|
|
||||||
|
for (const newItem of newListeners) {
|
||||||
for (const newItem of newListeners) {
|
listenersDataBinding.set(newItem.address, newItem);
|
||||||
listenersDataBinding.set(newItem.address, newItem);
|
}
|
||||||
}
|
for (const removedUrl of removedUrls) {
|
||||||
for (const removedUrl of removedUrls) {
|
listenersDataBinding.delete(removedUrl);
|
||||||
listenersDataBinding.delete(removedUrl);
|
}
|
||||||
}
|
|
||||||
|
myManager.stopAll();
|
||||||
myManager.stopAll();
|
await myManager.saveOverride(listeners);
|
||||||
await myManager.saveOverride(listeners);
|
|
||||||
|
if (logger) logger.warn("Configuration changed: " + listenerInput);
|
||||||
if (logger) logger.warn("Configuration modifiée: " + listenerInput);
|
|
||||||
|
myManager.startAll();
|
||||||
myManager.startAll();
|
}
|
||||||
}
|
|
||||||
|
async function unregister() {
|
||||||
async function unregister() {
|
myManager.stopAll();
|
||||||
myManager.stopAll();
|
}
|
||||||
return;
|
|
||||||
}
|
module.exports = {
|
||||||
|
register,
|
||||||
module.exports = {
|
unregister,
|
||||||
register,
|
};
|
||||||
unregister,
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user