summaryrefslogtreecommitdiff
path: root/lib/web/imageRouter
diff options
context:
space:
mode:
Diffstat (limited to 'lib/web/imageRouter')
-rw-r--r--lib/web/imageRouter/azure.js8
-rw-r--r--lib/web/imageRouter/filesystem.js8
-rw-r--r--lib/web/imageRouter/imgur.js12
-rw-r--r--lib/web/imageRouter/index.js7
-rw-r--r--lib/web/imageRouter/lutim.js13
-rw-r--r--lib/web/imageRouter/s3.js1
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)