From 208070d2e776c437154e6ead552364b3956adf1c Mon Sep 17 00:00:00 2001 From: Dylan Dervaux Date: Fri, 1 Feb 2019 12:33:27 +0100 Subject: Add lutim support Signed-off-by: Dylan Dervaux --- lib/web/imageRouter/lutim.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/web/imageRouter/lutim.js (limited to 'lib/web/imageRouter') diff --git a/lib/web/imageRouter/lutim.js b/lib/web/imageRouter/lutim.js new file mode 100644 index 00000000..78b856c9 --- /dev/null +++ b/lib/web/imageRouter/lutim.js @@ -0,0 +1,31 @@ +'use strict' +const config = require('../../config') +const logger = require('../../logger') + +const lutim = require('lutim') + +exports.uploadImage = function (imagePath, callback) { + if (!imagePath || typeof imagePath !== 'string') { + callback(new Error('Image path is missing or wrong'), null) + return + } + + if (!callback || typeof callback !== 'function') { + logger.error('Callback has to be a function') + return + } + + if (config.lutim && config.lutim.url) { + lutim.setAPIUrl(config.lutim.url) + } + + lutim.uploadImage(imagePath) + .then(function (json) { + if (config.debug) { + logger.info('SERVER uploadimage success: ' + JSON.stringify(json)) + } + callback(null, lutim.getAPIUrl() + json.msg.short) + }).catch(function (err) { + callback(new Error(err), null) + }) +} -- cgit v1.2.3