diff --git a/package-lock.json b/package-lock.json index b4243fb..94c3862 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,9 @@ "": { "version": "0.0.2", "dependencies": { - "listener-rss-agregator": "file:../../../../../../../../tmp/tmp.lX4jI4rkxi/listener-rss-agregator" + "form-data": "^4.0.0", + "listener-rss-agregator": "file:/tmp/tmp.lX4jI4rkxi/listener-rss-agregator", + "node-fetch": "^2.6.1" }, "devDependencies": { "ts-node": "^10.0.0", @@ -19,7 +21,7 @@ "license": "MIT", "dependencies": { "@databases/sqlite": "^3.0.0", - "listener-rss": "^0.0.1" + "listener-rss": "^0.0.3" }, "devDependencies": { "@types/chai": "^4.2.15", @@ -117,18 +119,42 @@ "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, "node_modules/buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", @@ -138,6 +164,19 @@ "node": ">=0.3.1" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/listener-rss-agregator": { "resolved": "../../../../../../../../tmp/tmp.lX4jI4rkxi/listener-rss-agregator", "link": true @@ -148,6 +187,33 @@ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true }, + "node_modules/mime-db": { + "version": "1.48.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.48.0.tgz", + "integrity": "sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.31", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.31.tgz", + "integrity": "sha512-XGZnNzm3QvgKxa8dpzyhFTHmpP3l5YNusmne07VUOXxou9CqUqYa/HBy124RqtVh/O2pECas/MOcsDgpilPOPg==", + "dependencies": { + "mime-db": "1.48.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -270,24 +336,52 @@ "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", "dev": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", "dev": true }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, "create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, "diff": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "listener-rss-agregator": { "version": "file:../../../../../../../../tmp/tmp.lX4jI4rkxi/listener-rss-agregator", "requires": { @@ -305,7 +399,7 @@ "eslint-plugin-import": "^2.22.1", "eslint-plugin-mocha": "8.0.0", "eslint-plugin-prettier": "3.3.1", - "listener-rss": "^0.0.1", + "listener-rss": "^0.0.3", "mocha": "^8.2.1", "nock": "^13.0.11", "prettier": "2.2.1", @@ -323,6 +417,24 @@ "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true }, + "mime-db": { + "version": "1.48.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.48.0.tgz", + "integrity": "sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ==" + }, + "mime-types": { + "version": "2.1.31", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.31.tgz", + "integrity": "sha512-XGZnNzm3QvgKxa8dpzyhFTHmpP3l5YNusmne07VUOXxou9CqUqYa/HBy124RqtVh/O2pECas/MOcsDgpilPOPg==", + "requires": { + "mime-db": "1.48.0" + } + }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", diff --git a/package.json b/package.json index 156259d..b479dc1 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,8 @@ "staticDirs": {}, "translations": {}, "dependencies": { - "listener-rss-agregator": "file:/tmp/tmp.lX4jI4rkxi/listener-rss-agregator" + "form-data": "^4.0.0", + "listener-rss-agregator": "file:/tmp/tmp.lX4jI4rkxi/listener-rss-agregator", + "node-fetch": "^2.6.1" } } diff --git a/src/main.ts b/src/main.ts index edcbdf8..3057f39 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,100 +1,98 @@ -import { ListenerRssAggregator } from 'listener-rss-agregator'; -import { ListenerRSSInfos } from 'listener-rss'; +import { ListenerRssAggregator } from "listener-rss-agregator"; + type ListenerData = { - ChannelId: number; - firstUpdate: boolean; -} & ListenerRSSInfos; + ChannelId: number; +}; let myManager: ListenerRssAggregator; let listenersDataBinding = new Map(); let logger: any; -let firstUpdate = true; -import * as path from 'path'; -import fs from 'fs'; +import * as path from "path"; +import fs from "fs"; async function register({ - registerSetting, - settingsManager, - peertubeHelpers, + registerSetting, + settingsManager, + peertubeHelpers, }: any) { - const basePath = peertubeHelpers.plugin.getDataDirectoryPath(); - logger = peertubeHelpers.logger; + const basePath = peertubeHelpers.plugin.getDataDirectoryPath(); + logger = peertubeHelpers.logger; - registerSetting({ - name: 'ytb-urls', - label: 'liste des urls youtube a auto-importer', - type: 'input-textarea', - }); + 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'), ''); // append + 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); + const configAggregator = await ListenerRssAggregator.instantiateAggregator( + path.join(basePath, "/storage.bd") + ); + myManager = new ListenerRssAggregator(configAggregator); - logger.warn('Aggregator created'); + logger.warn("Aggregator created"); - const inputs = await settingsManager.getSetting('ytb-urls'); - if (inputs) await addListeners(inputs); + const inputs = await settingsManager.getSetting("ytb-urls"); + if (inputs) await addListeners(inputs); - logger.warn('Config loaded'); + logger.warn("Config loaded"); - settingsManager.onSettingsChange(async (settings: any) => { - await addListeners(settings['ytb-urls']); - }); + settingsManager.onSettingsChange(async (settings: any) => { + await addListeners(settings["ytb-urls"]); + }); - myManager.on('newEntries', (entries: any) => { - const datas = listenersDataBinding.get(entries.addressListener); - if (!datas) return; + 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)); - }); + 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) - ); + 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); - } + 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; + myManager.stopAll(); + await myManager.saveOverride(listeners); + firstUpdate = true; - if (logger) logger.warn('Configuration modifiée: ' + listenerInput); + if (logger) logger.warn("Configuration modifiée: " + listenerInput); - myManager.startAll(); + myManager.startAll(); } async function unregister() { - myManager.stopAll(); - return; + myManager.stopAll(); + return; } module.exports = { - register, - unregister, + register, + unregister, };