From 6fd16e2bf00475db5f514b19f42a6dba6ac9f8f1 Mon Sep 17 00:00:00 2001 From: pfans Date: Thu, 16 Nov 2023 14:26:08 +0800 Subject: [PATCH] Update iot-gateway js file. (#94) --- iot-gateway/pjs/rest.js | 4 ++-- iot-gateway/pjs/worker.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iot-gateway/pjs/rest.js b/iot-gateway/pjs/rest.js index cf89a2f..067c0ce 100644 --- a/iot-gateway/pjs/rest.js +++ b/iot-gateway/pjs/rest.js @@ -201,7 +201,7 @@ pipy() msg => ( ( /// debug = console.log('query config:', msg?.body?.toString?.()), - resp = JSON.decode(msg?.body), + resp = (msg?.body?.toString?.().charAt(0) === '{') && JSON.decode(msg?.body), ) => ( (msg?.head?.status === 401) ? ( deviceConfig.strapiJwt = null, @@ -240,7 +240,7 @@ pipy() .replaceMessage( msg => ( ( - resp = JSON.decode(msg?.body), + resp = (msg?.body?.toString?.().charAt(0) === '{') && JSON.decode(msg?.body), ) => ( (msg?.head?.status === 200 && resp?.data?.id > 0) ? ( [new Message('OK'), new StreamEnd] diff --git a/iot-gateway/pjs/worker.js b/iot-gateway/pjs/worker.js index e6309c6..29c0809 100644 --- a/iot-gateway/pjs/worker.js +++ b/iot-gateway/pjs/worker.js @@ -56,7 +56,7 @@ pipy({ .replaceMessage( msg => ( msg?.body && ( - _dataJson = JSON.decode(msg?.body), + _dataJson = (msg?.body?.toString?.().charAt(0) === '{') && JSON.decode(msg?.body), (_dataJson?.ts > 0) && ( delete _dataJson.id, _dataJson.created_at = new Date(_dataJson.ts * 1000).toISOString(),