.
This commit is contained in:
parent
8558c555e5
commit
f21f752cbb
1353
package-lock.json
generated
1353
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -31,6 +31,6 @@
|
|||
"staticDirs": {},
|
||||
"translations": {},
|
||||
"dependencies": {
|
||||
"listener-rss-agregator": "0.0.2"
|
||||
"listener-rss-agregator": "file:/tmp/tmp.lX4jI4rkxi/listener-rss-agregator"
|
||||
}
|
||||
}
|
||||
|
|
101
src/main.ts
101
src/main.ts
|
@ -1,63 +1,98 @@
|
|||
import { ManageListener } from 'listener-rss-agregator';
|
||||
import { ListenerRssAggregator } from 'listener-rss-agregator';
|
||||
import { ListenerRSSInfos } from 'listener-rss';
|
||||
type ListenerData = {
|
||||
ChannelId: number;
|
||||
firstUpdate: boolean;
|
||||
} & ListenerRSSInfos;
|
||||
|
||||
let myManager : ManageListener;
|
||||
let bindistenerChannelId: {[key: string] : string} = {};
|
||||
let myManager: ListenerRssAggregator;
|
||||
let listenersDataBinding = new Map<string, ListenerData>();
|
||||
let logger: any;
|
||||
let firstUpdate = true;
|
||||
|
||||
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'
|
||||
})
|
||||
type: 'input-textarea',
|
||||
});
|
||||
|
||||
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
||||
myManager = new ManageListener(path.join(basePath, '/data/storage.bd'));
|
||||
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);
|
||||
|
||||
logger.warn('Aggregator created');
|
||||
|
||||
const inputs = await settingsManager.getSetting('ytb-urls');
|
||||
if (inputs) await addListeners(inputs);
|
||||
|
||||
addListeners(inputs);
|
||||
logger.warn('Config loaded');
|
||||
|
||||
settingsManager.onSettingsChange((settings: any) => {
|
||||
myManager.stopAll();
|
||||
myManager.save();
|
||||
settingsManager.onSettingsChange(async (settings: any) => {
|
||||
await addListeners(settings['ytb-urls']);
|
||||
});
|
||||
|
||||
addListeners(settings['ytb-urls']);
|
||||
})
|
||||
myManager.on('newEntries', (entries: any) => {
|
||||
if (firstUpdate) {
|
||||
logger.warn('Premiere update');
|
||||
|
||||
myManager.on('update', (entries: any) => {
|
||||
// for (const item in entries.items)
|
||||
// console.info(item.)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function addListeners(listenerInput: any) {
|
||||
for (const line in listenerInput.split('\n'))
|
||||
if (!myManager.listenerArray.map((it: any) => it.address).includes(line)) // si ligne non présente
|
||||
{
|
||||
let splitted = line.split(':');
|
||||
bindistenerChannelId[splitted[1]] = splitted[0];
|
||||
myManager.registerListener({ address: splitted[0] });
|
||||
firstUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
myManager.save();
|
||||
logger.warn(
|
||||
'Nouvelles baba entrées détéctées: ' + JSON.stringify(entries)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function addListeners(listenerInput: string) {
|
||||
let objs: ListenerData[];
|
||||
try {
|
||||
objs = JSON.parse(listenerInput);
|
||||
} catch {
|
||||
logger.warn('Erreur: malformé');
|
||||
return;
|
||||
}
|
||||
|
||||
for (const item of objs) {
|
||||
if (listenersDataBinding.has(item.address)) break;
|
||||
listenersDataBinding.set(item.address, {
|
||||
ChannelId: item.ChannelId,
|
||||
firstUpdate: item.firstUpdate,
|
||||
address: item.address,
|
||||
});
|
||||
}
|
||||
|
||||
myManager.stopAll();
|
||||
await myManager.saveOverride(objs);
|
||||
firstUpdate = true;
|
||||
|
||||
if (logger) logger.warn('Configuration modifiée: ' + listenerInput);
|
||||
|
||||
myManager.startAll();
|
||||
}
|
||||
|
||||
async function unregister() {
|
||||
myManager.stopAll();
|
||||
myManager.save();
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
register,
|
||||
unregister
|
||||
}
|
||||
unregister,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user