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.js22
-rw-r--r--lib/web/imageRouter/index.js7
-rw-r--r--lib/web/imageRouter/lutim.js30
-rw-r--r--lib/web/imageRouter/minio.js6
-rw-r--r--lib/web/imageRouter/s3.js3
7 files changed, 58 insertions, 26 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 2a20002c..dcb03a7a 100644
--- a/lib/web/imageRouter/imgur.js
+++ b/lib/web/imageRouter/imgur.js
@@ -5,24 +5,22 @@ 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))
- }
- callback(null, json.data.link.replace(/^http:\/\//i, 'https://'))
- }).catch(function (err) {
- callback(new Error(err), null)
- })
+ .then(function (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
new file mode 100644
index 00000000..61930ad6
--- /dev/null
+++ b/lib/web/imageRouter/lutim.js
@@ -0,0 +1,30 @@
+'use strict'
+const config = require('../../config')
+const logger = require('../../logger')
+
+const lutim = require('lutim')
+
+exports.uploadImage = function (imagePath, callback) {
+ if (!callback || typeof callback !== 'function') {
+ logger.error('Callback has to be a function')
+ return
+ }
+
+ 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) {
+ 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/minio.js b/lib/web/imageRouter/minio.js
index b921c2d2..fe43f76f 100644
--- a/lib/web/imageRouter/minio.js
+++ b/lib/web/imageRouter/minio.js
@@ -3,7 +3,7 @@ const fs = require('fs')
const path = require('path')
const config = require('../../config')
-const {getImageMimeType} = require('../../utils')
+const { getImageMimeType } = require('../../utils')
const logger = require('../../logger')
const Minio = require('minio')
@@ -40,7 +40,9 @@ exports.uploadImage = function (imagePath, callback) {
callback(new Error(err), null)
return
}
- callback(null, `${protocol}://${config.minio.endPoint}:${config.minio.port}/${config.s3bucket}/${key}`)
+ let hidePort = [80, 443].includes(config.minio.port)
+ let urlPort = hidePort ? '' : `:${config.minio.port}`
+ callback(null, `${protocol}://${config.minio.endPoint}${urlPort}/${config.s3bucket}/${key}`)
})
})
}
diff --git a/lib/web/imageRouter/s3.js b/lib/web/imageRouter/s3.js
index f2a5a5df..2bf08cc7 100644
--- a/lib/web/imageRouter/s3.js
+++ b/lib/web/imageRouter/s3.js
@@ -3,7 +3,7 @@ const fs = require('fs')
const path = require('path')
const config = require('../../config')
-const {getImageMimeType} = require('../../utils')
+const { getImageMimeType } = require('../../utils')
const logger = require('../../logger')
const AWS = require('aws-sdk')
@@ -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)