Adding new Admin UI. Updating Fredy to V3.0.0 as it has been a large rewrite. Thanks for all contributions and help on the way!
This commit is contained in:
Christian Kellner
2021-01-21 16:09:23 +01:00
committed by GitHub
parent 8185bfe818
commit b2847f6834
124 changed files with 9768 additions and 1495 deletions

View File

@@ -1,36 +1,48 @@
const fs = require('fs');
const path = './lib/provider';
const provider = fs.readdirSync(path);
const provider = fs.readdirSync(path).filter((file) => file.endsWith('.js'));
const config = require('./conf/config.json');
const { setLastJobExecution, init: storeInit } = require('./lib/services/store');
const jobStorage = require('./lib/services/storage/jobStorage');
const { setLastJobExecution } = require('./lib/services/storage/listingsStorage');
const FredyRuntime = require('./lib/FredyRuntime');
//starting the api service
require('./lib/api/api');
storeInit().then(() => {
setInterval(
(function exec() {
Object.keys(config.jobs).forEach(jobKey => {
const jobConfig = config.jobs[jobKey];
//assuming interval is always in minutes
const INTERVAL = config.interval * 60 * 1000;
/* eslint-disable no-console */
console.log(`Started Fredy successfully. Ui can be accessed via http://localhost:${config.port}`);
/* eslint-enable no-console */
setInterval(
(function exec() {
jobStorage
.getJobs()
.filter((job) => job.enabled)
.forEach((job) => {
const providerIds = job.provider.map((provider) => provider.id);
provider
.map(pro => require(`${path}/${pro}`))
.forEach(pro => {
const providerId = pro.id();
.filter((provider) => provider.endsWith('.js'))
.map((pro) => require(`${path}/${pro}`))
.filter((provider) => providerIds.indexOf(provider.metaInformation.id) !== -1)
.forEach(async (pro) => {
const providerId = pro.metaInformation.id;
if (providerId == null || providerId.length === 0) {
throw new Error('Provider id must not be empty. => ' + pro);
}
const providerConfig = jobConfig.provider[providerId];
const providerConfig = job.provider.find((jobProvider) => jobProvider.id === providerId);
if (providerConfig == null) {
throw new Error(`Provider Config for provider with id ${providerId} not found.`);
}
pro.init(providerConfig, jobConfig.blacklist, jobConfig.blacklistedDistricts);
new FredyRuntime(pro.config, jobConfig.notification, providerId, jobKey).execute();
setLastJobExecution(jobKey);
pro.init(providerConfig, job.blacklist);
await new FredyRuntime(pro.config, job.notificationAdapter, providerId, job.id).execute();
setLastJobExecution(job.id);
});
});
return exec;
})(),
config.interval * 60 * 1000
);
});
return exec;
})(),
INTERVAL
);