From 413f08589be2906afeebb22b14a4dc85ca9f9463 Mon Sep 17 00:00:00 2001 From: Udo Walter Date: Sun, 1 Dec 2019 18:40:00 +0000 Subject: [configloader] eslint fixes --- server/api/configloader.js | 2 -- server/lib/confighelper.js | 26 +++++++++----------------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/server/api/configloader.js b/server/api/configloader.js index 699f16b..f32bfa2 100644 --- a/server/api/configloader.js +++ b/server/api/configloader.js @@ -4,8 +4,6 @@ var db = require(path.join(__appdir, 'lib', 'sequelize')) var express = require('express') const { decorateApp } = require('@awaitjs/express') var noAuthRouter = decorateApp(express.Router()) -const config = require(path.join(__appdir, 'config', 'config')) -const url = config.https.host + ':' + config.https.port const configHelper = require(path.join(__appdir, 'lib', 'confighelper')) const log = require(path.join(__appdir, 'lib', 'log')) diff --git a/server/lib/confighelper.js b/server/lib/confighelper.js index bb43b6a..e2535c8 100644 --- a/server/lib/confighelper.js +++ b/server/lib/confighelper.js @@ -6,7 +6,6 @@ const eventHelper = require(path.join(__appdir, 'lib', 'eventhelper')) const serverConfig = require(path.join(__appdir, 'config', 'config')) const url = serverConfig.https.host + ':' + serverConfig.https.port - async function getConfig (client, list) { let configPath = [] @@ -25,7 +24,7 @@ async function getConfig (client, list) { if (client.registrationState !== null) { // client is in registration state, load scripts var hook = await db.registrationhook.findOne({ where: { id: client.registrationState } }) - let config = { id: 'HOOK' + hook.id, name: hook.name, source: { type: hook.type + '_HOOK', id: hook.id, name: hook.name, } } + let config = { id: 'HOOK' + hook.id, name: hook.name, source: { type: hook.type + '_HOOK', id: hook.id, name: hook.name } } if (!list) { if (hook.type === 'IPXE') { config.script = hook.script @@ -57,7 +56,6 @@ async function getConfig (client, list) { return configPath } - async function getGroupConfig (group, list) { if (!group) return let configPath = [] @@ -81,7 +79,6 @@ async function getGroupConfig (group, list) { return configPath } - async function _checkParentConfigs (id, breakOnImportant, isClient = true) { const importantList = [] const eventList = [] @@ -91,7 +88,6 @@ async function _checkParentConfigs (id, breakOnImportant, isClient = true) { let parents = isClient ? [] : [id] do { - let events = [] let configs = [] @@ -114,8 +110,8 @@ async function _checkParentConfigs (id, breakOnImportant, isClient = true) { let eventTimes = JSON.parse(event.times) if (!eventHelper.isActive(eventTimes)) return - if ((event.groups && event.groups.some(group => group.group_x_event.blacklist)) - || (event.clients && event.clients.length && event.clients[0].client_x_event.blacklist)) { + if ((event.groups && event.groups.some(group => group.group_x_event.blacklist)) || + (event.clients && event.clients.length && event.clients[0].client_x_event.blacklist)) { return blackList.push(event.id) } @@ -147,7 +143,6 @@ async function _checkParentConfigs (id, breakOnImportant, isClient = true) { if (configs.length > 1) configList.push(await _createDynamicMenu(configs)) else if (configs.length === 1) configList.push(await _prepareConfig(configs[0])) - if (isClient) { parents = (await db.group.findAll({ where: { '$clients.id$': id }, include: ['clients'] })).map(x => x.id) isClient = false @@ -160,13 +155,11 @@ async function _checkParentConfigs (id, breakOnImportant, isClient = true) { } seenGroupsList.push(...parents) - } while (parents.length) return [...importantList, ...eventList, ...configList] } - // create the config script from database async function _prepareConfig (configInfo, noScript) { let id = configInfo.id @@ -217,7 +210,6 @@ async function _prepareConfig (configInfo, noScript) { return result } - // create dynamic menu to load the different given configs for a client async function _createDynamicMenu (configInfos, noScript) { const ids = [] @@ -234,10 +226,12 @@ async function _createDynamicMenu (configInfos, noScript) { else idSourceMap[id] = [idSourceMap[id], source] } - if (ids.length === 1) return await _prepareConfig({ - id: ids[0], - source: idSourceMap[ids[0]] - }) + if (ids.length === 1) { + return _prepareConfig({ + id: ids[0], + source: idSourceMap[ids[0]] + }) + } const configs = await db.config.findAll({ where: { id: ids } }) @@ -276,7 +270,6 @@ async function _createDynamicMenu (configInfos, noScript) { return result } - // Creates a default overview config, when there is no default config in the frontend. function getDefaultConfig (client) { let script = '#!ipxe\r\n\r\n' @@ -308,5 +301,4 @@ function getDefaultConfig (client) { return script } - module.exports = { getConfig, getGroupConfig, getDefaultConfig } -- cgit v1.2.3-55-g7522