From f0f43c852acea523d454c54dcc6daddc164e4664 Mon Sep 17 00:00:00 2001 From: Moe Alam Date: Sun, 1 Nov 2020 17:44:21 -0800 Subject: [PATCH] Add Monitor Configuration Migrator Tool --- libs/monitor/utils.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libs/monitor/utils.js b/libs/monitor/utils.js index 96c33ac4..664d96c4 100644 --- a/libs/monitor/utils.js +++ b/libs/monitor/utils.js @@ -144,9 +144,41 @@ module.exports = (s,config,lang) => { urlParts[0] = 'http' return ['rtsp','://',`${username}:${password}@`,urlParts[1]].join('') } + const monitorConfigurationMigrator = (monitor) => { + // converts the old style to the new style. + const updatedFields = require('./updatedFields.js')() + const fieldKeys = Object.keys(updatedFields) + fieldKeys.forEach((oldKey) => { + if(oldKey === 'details'){ + const detailKeys = Object.keys(updatedFields.details) + detailKeys.forEach((oldKey) => { + if(oldKey === 'stream_channels'){ + const channelUpdates = updatedFields.details.stream_channels + const channelKeys = Object.keys(channelUpdates) + monitor.details.stream_channels.forEach(function(channel,number){ + channelKeys.forEach((oldKey) => { + const newKey = channelUpdates[oldKey] + monitor.details.stream_channels[number][newKey] = monitor.details.stream_channels[number][oldKey] + // delete(e.details.stream_channels[number][oldKey]) + }) + }) + }else{ + const newKey = updatedFields.details[oldKey] + monitor.details[newKey] = monitor.details[oldKey] + // delete(monitor.details[oldKey]) + } + }) + }else{ + const newKey = updatedFields[oldKey] + monitor[newKey] = monitor[oldKey] + // delete(monitor[oldKey]) + } + }) + } return { cameraDestroy: cameraDestroy, createSnapshot: createSnapshot, addCredentialsToStreamLink: addCredentialsToStreamLink, + monitorConfigurationMigrator: monitorConfigurationMigrator, } }