From 93069806f6f824e4b1ac42c15bc6cd05433141e6 Mon Sep 17 00:00:00 2001 From: baldo Date: Mon, 22 Feb 2021 22:26:19 +0100 Subject: [PATCH] Fix: Parsing node files did not prefill missing fields correctly. * This lead to a HTTP 500 on dashboard as some nodes were missing monitoring fields. * Removed a problematic cast and added sane defaults. --- server/services/nodeService.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/server/services/nodeService.ts b/server/services/nodeService.ts index 3d58d2d..2f8255d 100644 --- a/server/services/nodeService.ts +++ b/server/services/nodeService.ts @@ -10,7 +10,7 @@ import Logger from "../logger"; import * as MailService from "../services/mailService"; import {normalizeString} from "../utils/strings"; import {monitoringConfirmUrl, monitoringDisableUrl} from "../utils/urlBuilder"; -import {MonitoringState, MonitoringToken, Node, NodeSecrets, NodeStatistics, Token} from "../types"; +import {FastdKey, MonitoringState, MonitoringToken, Node, NodeSecrets, NodeStatistics, Token} from "../types"; import util from "util"; const pglob = util.promisify(glob); @@ -283,8 +283,21 @@ async function parseNodeFile(file: string): Promise<{node: Node, nodeSecrets: No }); return { - node: node as Node, - nodeSecrets: nodeSecrets as NodeSecrets, + node: { + token: node.token as Token || '', + nickname: node.nickname as string || '', + email: node.email as string || '', + hostname: node.hostname as string || '', + coords: node.coords as string || undefined, + key: node.coords as FastdKey || undefined, + mac: node.mac as string || '', + monitoring: !!node.monitoring, + monitoringConfirmed: !!node.monitoringConfirmed, + monitoringState: node.monitoringState as MonitoringState || MonitoringState.DISABLED, + }, + nodeSecrets: { + monitoringToken: nodeSecrets.monitoringToken as MonitoringToken || undefined, + }, }; }