From e43c9052dd1f9d84c9d79341ee2e546b0e7b66d2 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Mon, 29 Jan 2018 16:00:09 -0800 Subject: [PATCH] Improve backwards-compatible response of GET /v1/device Signed-off-by: Pablo Carranza Velez --- src/device-state.coffee | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/device-state.coffee b/src/device-state.coffee index 5a3efe17..e80006ee 100644 --- a/src/device-state.coffee +++ b/src/device-state.coffee @@ -148,16 +148,23 @@ class DeviceStateRouter .then (state) -> stateToSend = _.pick(state.local, [ 'api_port' - 'commit' 'ip_address' - 'status' - 'download_progress' 'os_version' 'supervisor_version' 'update_pending' 'update_failed' 'update_downloaded' ]) + if state.local.is_on__commit? + stateToSend.commit = state.local.is_on__commit + # Will produce nonsensical results for multicontainer apps... + service = _.toPairs(_.toPairs(state.local.apps)[0]?[1]?.services)[0]?[1] + if service? + stateToSend.status = service.status + # For backwards compatibility, we adapt Running to the old "Idle" + if stateToSend.status == 'Running' + stateToSend.status = 'Idle' + stateToSend.download_progress = service.download_progress res.json(stateToSend) .catch (err) -> res.status(500).json({ Data: '', Error: err?.message or err or 'Unknown error' })