diff options
author | Sheogorath | 2019-06-09 13:47:32 +0200 |
---|---|---|
committer | GitHub | 2019-06-09 13:47:32 +0200 |
commit | 02929cd4bf6da3596dde33ebfd8369e0914929a5 (patch) | |
tree | d221b850be9f961f357b7592636cd35868675383 /lib/web/imageRouter | |
parent | 6462968e84e8d92292dd23764a9e558d7800147d (diff) | |
parent | b5fc6db75db61d9765da38e0f085dd737380f9f4 (diff) |
Merge pull request #103 from SISheogorath/feature/improve-logging
Rework debug logging
Diffstat (limited to 'lib/web/imageRouter')
-rw-r--r-- | lib/web/imageRouter/azure.js | 8 | ||||
-rw-r--r-- | lib/web/imageRouter/filesystem.js | 8 | ||||
-rw-r--r-- | lib/web/imageRouter/imgur.js | 12 | ||||
-rw-r--r-- | lib/web/imageRouter/index.js | 7 | ||||
-rw-r--r-- | lib/web/imageRouter/lutim.js | 13 | ||||
-rw-r--r-- | lib/web/imageRouter/s3.js | 1 |
6 files changed, 24 insertions, 25 deletions
diff --git a/lib/web/imageRouter/azure.js b/lib/web/imageRouter/azure.js index cc98e5fc..22ee5585 100644 --- a/lib/web/imageRouter/azure.js +++ b/lib/web/imageRouter/azure.js @@ -7,13 +7,13 @@ const logger = require('../../logger') const azure = require('azure-storage') exports.uploadImage = function (imagePath, callback) { - if (!imagePath || typeof imagePath !== 'string') { - callback(new Error('Image path is missing or wrong'), null) + if (!callback || typeof callback !== 'function') { + logger.error('Callback has to be a function') return } - if (!callback || typeof callback !== 'function') { - logger.error('Callback has to be a function') + if (!imagePath || typeof imagePath !== 'string') { + callback(new Error('Image path is missing or wrong'), null) return } diff --git a/lib/web/imageRouter/filesystem.js b/lib/web/imageRouter/filesystem.js index 7c876d66..3ba09e88 100644 --- a/lib/web/imageRouter/filesystem.js +++ b/lib/web/imageRouter/filesystem.js @@ -6,13 +6,13 @@ const config = require('../../config') const logger = require('../../logger') exports.uploadImage = function (imagePath, callback) { - if (!imagePath || typeof imagePath !== 'string') { - callback(new Error('Image path is missing or wrong'), null) + if (!callback || typeof callback !== 'function') { + logger.error('Callback has to be a function') return } - if (!callback || typeof callback !== 'function') { - logger.error('Callback has to be a function') + if (!imagePath || typeof imagePath !== 'string') { + callback(new Error('Image path is missing or wrong'), null) return } diff --git a/lib/web/imageRouter/imgur.js b/lib/web/imageRouter/imgur.js index eee349f9..dcb03a7a 100644 --- a/lib/web/imageRouter/imgur.js +++ b/lib/web/imageRouter/imgur.js @@ -5,22 +5,20 @@ const logger = require('../../logger') const imgur = require('imgur') exports.uploadImage = function (imagePath, callback) { - if (!imagePath || typeof imagePath !== 'string') { - callback(new Error('Image path is missing or wrong'), null) + if (!callback || typeof callback !== 'function') { + logger.error('Callback has to be a function') return } - if (!callback || typeof callback !== 'function') { - logger.error('Callback has to be a function') + if (!imagePath || typeof imagePath !== 'string') { + callback(new Error('Image path is missing or wrong'), null) return } imgur.setClientId(config.imgur.clientID) imgur.uploadFile(imagePath) .then(function (json) { - if (config.debug) { - logger.info('SERVER uploadimage success: ' + JSON.stringify(json)) - } + logger.debug(`SERVER uploadimage success: ${JSON.stringify(json)}`) callback(null, json.data.link.replace(/^http:\/\//i, 'https://')) }).catch(function (err) { callback(new Error(err), null) diff --git a/lib/web/imageRouter/index.js b/lib/web/imageRouter/index.js index f3c2decf..0b59218b 100644 --- a/lib/web/imageRouter/index.js +++ b/lib/web/imageRouter/index.js @@ -21,18 +21,19 @@ imageRouter.post('/uploadimage', function (req, res) { form.parse(req, function (err, fields, files) { if (err || !files.image || !files.image.path) { + logger.error(`formidable error: ${err}`) response.errorForbidden(res) } else { - if (config.debug) { - logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image)) - } + logger.debug(`SERVER received uploadimage: ${JSON.stringify(files.image)}`) const uploadProvider = require('./' + config.imageUploadType) + logger.debug(`imageRouter: Uploading ${files.image.path} using ${config.imageUploadType}`) uploadProvider.uploadImage(files.image.path, function (err, url) { if (err !== null) { logger.error(err) return res.status(500).end('upload image error') } + logger.debug(`SERVER sending ${url} to client`) res.send({ link: url }) diff --git a/lib/web/imageRouter/lutim.js b/lib/web/imageRouter/lutim.js index 78b856c9..61930ad6 100644 --- a/lib/web/imageRouter/lutim.js +++ b/lib/web/imageRouter/lutim.js @@ -5,25 +5,24 @@ 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) + if (!callback || typeof callback !== 'function') { + logger.error('Callback has to be a function') return } - if (!callback || typeof callback !== 'function') { - logger.error('Callback has to be a function') + if (!imagePath || typeof imagePath !== 'string') { + callback(new Error('Image path is missing or wrong'), null) return } if (config.lutim && config.lutim.url) { lutim.setAPIUrl(config.lutim.url) + logger.debug(`Set lutim URL to ${lutim.getApiUrl()}`) } lutim.uploadImage(imagePath) .then(function (json) { - if (config.debug) { - logger.info('SERVER uploadimage success: ' + JSON.stringify(json)) - } + logger.debug(`SERVER uploadimage success: ${JSON.stringify(json)}`) callback(null, lutim.getAPIUrl() + json.msg.short) }).catch(function (err) { callback(new Error(err), null) diff --git a/lib/web/imageRouter/s3.js b/lib/web/imageRouter/s3.js index b0eca7b5..4effea04 100644 --- a/lib/web/imageRouter/s3.js +++ b/lib/web/imageRouter/s3.js @@ -35,6 +35,7 @@ exports.uploadImage = function (imagePath, callback) { const mimeType = getImageMimeType(imagePath) if (mimeType) { params.ContentType = mimeType } + logger.debug(`S3 object parameters: ${JSON.stringify(params)}`) s3.putObject(params, function (err, data) { if (err) { callback(new Error(err), null) |