From 056a883ea1c20f8a073d502c17ee18636861ebc5 Mon Sep 17 00:00:00 2001 From: Rushi Desai Date: Sun, 5 Feb 2017 22:27:28 -0800 Subject: [PATCH 1/3] Make JSON parsing of responses optional --- lib/synology.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/synology.js b/lib/synology.js index 87673c0..a160f65 100644 --- a/lib/synology.js +++ b/lib/synology.js @@ -95,13 +95,11 @@ var Synology = function(options) { syno.emit('error', err); return callback && callback(err, data); } - - // Parse the JSON response + + // Try to parse the JSON response try { data = JSON.parse(data); } catch(e) { - syno.emit('error', err); - return callback && callback(err, data); } if (!data.success && data.error) { From fb59ef27f62eb9541fb9a283261afd5af93954e1 Mon Sep 17 00:00:00 2001 From: Rushi Desai Date: Sun, 5 Feb 2017 22:48:38 -0800 Subject: [PATCH 2/3] Add surveillanceStation.camera.getSnapshot API --- lib/surveillance-station.js | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/surveillance-station.js b/lib/surveillance-station.js index 3646dc6..998dbd4 100644 --- a/lib/surveillance-station.js +++ b/lib/surveillance-station.js @@ -1,4 +1,44 @@ +'use strict'; + +var util = require('util'); + + +function Camera(syno) { + this.syno = syno; + return this; +} + +Camera.prototype.getSnapshot = function() { + /*jshint validthis:true */ + var + userParams = + typeof arguments[0] === 'object' ? arguments[0] : + {}, + callback = + typeof arguments[1] === 'function' ? arguments[1] : + typeof arguments[0] === 'function' ? arguments[0] : + null + ; + var params = { + api : 'SYNO.SurveillanceStation.Camera', + version: 9, + method : 'GetSnapshot' + }; + util._extend(params, userParams); + + var query = this.syno.query({ + path: '/webapi/entry.cgi', + params: params, + headers: { + 'Accept': 'image/jpeg', + } + }, callback || null); + + return query; +} + module.exports = function(syno) { return { + camera: new Camera(syno), }; }; From 0b54e6ebebb094ccc8fe1eab4df5afcc9d6162f7 Mon Sep 17 00:00:00 2001 From: Rushi Desai Date: Tue, 17 Jul 2018 16:06:43 -0700 Subject: [PATCH 3/3] Unset encoding header of HTTP request --- lib/synology.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/synology.js b/lib/synology.js index a160f65..e703039 100644 --- a/lib/synology.js +++ b/lib/synology.js @@ -86,7 +86,8 @@ var Synology = function(options) { body : options.body, method : options.method, headers: options.headers, - timeout: 30 * 1e3 + timeout: 30 * 1e3, + encoding: null, }, callback ? _apiCallback : null); },