refactor
This commit is contained in:
parent
afdd320056
commit
ea6adfc1fc
118
package-lock.json
generated
118
package-lock.json
generated
|
@ -7,7 +7,9 @@
|
||||||
"": {
|
"": {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
"dependencies": {
|
"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": {
|
"devDependencies": {
|
||||||
"ts-node": "^10.0.0",
|
"ts-node": "^10.0.0",
|
||||||
|
@ -19,7 +21,7 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@databases/sqlite": "^3.0.0",
|
"@databases/sqlite": "^3.0.0",
|
||||||
"listener-rss": "^0.0.1"
|
"listener-rss": "^0.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.2.15",
|
"@types/chai": "^4.2.15",
|
||||||
|
@ -117,18 +119,42 @@
|
||||||
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
|
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/buffer-from": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/create-require": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||||
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
|
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/diff": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||||
|
@ -138,6 +164,19 @@
|
||||||
"node": ">=0.3.1"
|
"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": {
|
"node_modules/listener-rss-agregator": {
|
||||||
"resolved": "../../../../../../../../tmp/tmp.lX4jI4rkxi/listener-rss-agregator",
|
"resolved": "../../../../../../../../tmp/tmp.lX4jI4rkxi/listener-rss-agregator",
|
||||||
"link": true
|
"link": true
|
||||||
|
@ -148,6 +187,33 @@
|
||||||
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/source-map": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
|
@ -270,24 +336,52 @@
|
||||||
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
|
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"asynckit": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
|
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||||
|
},
|
||||||
"buffer-from": {
|
"buffer-from": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
|
||||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||||
"dev": true
|
"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": {
|
"create-require": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||||
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
|
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
|
||||||
"dev": true
|
"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": {
|
"diff": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||||
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||||
"dev": true
|
"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": {
|
"listener-rss-agregator": {
|
||||||
"version": "file:../../../../../../../../tmp/tmp.lX4jI4rkxi/listener-rss-agregator",
|
"version": "file:../../../../../../../../tmp/tmp.lX4jI4rkxi/listener-rss-agregator",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -305,7 +399,7 @@
|
||||||
"eslint-plugin-import": "^2.22.1",
|
"eslint-plugin-import": "^2.22.1",
|
||||||
"eslint-plugin-mocha": "8.0.0",
|
"eslint-plugin-mocha": "8.0.0",
|
||||||
"eslint-plugin-prettier": "3.3.1",
|
"eslint-plugin-prettier": "3.3.1",
|
||||||
"listener-rss": "^0.0.1",
|
"listener-rss": "^0.0.3",
|
||||||
"mocha": "^8.2.1",
|
"mocha": "^8.2.1",
|
||||||
"nock": "^13.0.11",
|
"nock": "^13.0.11",
|
||||||
"prettier": "2.2.1",
|
"prettier": "2.2.1",
|
||||||
|
@ -323,6 +417,24 @@
|
||||||
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
||||||
"dev": true
|
"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": {
|
"source-map": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
"staticDirs": {},
|
"staticDirs": {},
|
||||||
"translations": {},
|
"translations": {},
|
||||||
"dependencies": {
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
src/main.ts
40
src/main.ts
|
@ -1,17 +1,15 @@
|
||||||
import { ListenerRssAggregator } from 'listener-rss-agregator';
|
import { ListenerRssAggregator } from "listener-rss-agregator";
|
||||||
import { ListenerRSSInfos } from 'listener-rss';
|
|
||||||
type ListenerData = {
|
type ListenerData = {
|
||||||
ChannelId: number;
|
ChannelId: number;
|
||||||
firstUpdate: boolean;
|
};
|
||||||
} & ListenerRSSInfos;
|
|
||||||
|
|
||||||
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 firstUpdate = true;
|
|
||||||
|
|
||||||
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,
|
||||||
|
@ -22,35 +20,35 @@ async function register({
|
||||||
logger = peertubeHelpers.logger;
|
logger = peertubeHelpers.logger;
|
||||||
|
|
||||||
registerSetting({
|
registerSetting({
|
||||||
name: 'ytb-urls',
|
name: "ytb-urls",
|
||||||
label: 'liste des urls youtube a auto-importer',
|
label: "liste des urls youtube a auto-importer",
|
||||||
type: 'input-textarea',
|
type: "input-textarea",
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.warn('setting register');
|
logger.warn("setting register");
|
||||||
fs.appendFileSync(path.join(basePath, '/storage.bd'), ''); // append
|
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);
|
||||||
|
|
||||||
logger.warn('Aggregator created');
|
logger.warn("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.warn("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('Nouvelles entrées détéctées: ' + JSON.stringify(entries));
|
logger.warn("Nouvelles entrées détéctées: " + JSON.stringify(entries));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +57,7 @@ async function addListeners(listenerInput: string) {
|
||||||
try {
|
try {
|
||||||
listeners = JSON.parse(listenerInput);
|
listeners = JSON.parse(listenerInput);
|
||||||
} catch {
|
} catch {
|
||||||
logger.warn('Erreur: malformé');
|
logger.warn("Erreur: malformé");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let newListeners = listeners.filter(
|
let newListeners = listeners.filter(
|
||||||
|
@ -84,7 +82,7 @@ async function addListeners(listenerInput: string) {
|
||||||
await myManager.saveOverride(listeners);
|
await myManager.saveOverride(listeners);
|
||||||
firstUpdate = true;
|
firstUpdate = true;
|
||||||
|
|
||||||
if (logger) logger.warn('Configuration modifiée: ' + listenerInput);
|
if (logger) logger.warn("Configuration modifiée: " + listenerInput);
|
||||||
|
|
||||||
myManager.startAll();
|
myManager.startAll();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user