2019-02-01 11:33:27 +00:00
|
|
|
'use strict'
|
|
|
|
const config = require('../../config')
|
|
|
|
const logger = require('../../logger')
|
|
|
|
|
|
|
|
const lutim = require('lutim')
|
|
|
|
|
|
|
|
exports.uploadImage = function (imagePath, callback) {
|
2019-06-08 18:51:24 +00:00
|
|
|
if (!callback || typeof callback !== 'function') {
|
|
|
|
logger.error('Callback has to be a function')
|
2019-02-01 11:33:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-06-08 18:51:24 +00:00
|
|
|
if (!imagePath || typeof imagePath !== 'string') {
|
|
|
|
callback(new Error('Image path is missing or wrong'), null)
|
2019-02-01 11:33:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.lutim && config.lutim.url) {
|
|
|
|
lutim.setAPIUrl(config.lutim.url)
|
2019-06-08 18:51:24 +00:00
|
|
|
logger.debug(`Set lutim URL to ${lutim.getApiUrl()}`)
|
2019-02-01 11:33:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lutim.uploadImage(imagePath)
|
|
|
|
.then(function (json) {
|
2019-06-08 18:51:24 +00:00
|
|
|
logger.debug(`SERVER uploadimage success: ${JSON.stringify(json)}`)
|
2019-02-01 11:33:27 +00:00
|
|
|
callback(null, lutim.getAPIUrl() + json.msg.short)
|
|
|
|
}).catch(function (err) {
|
|
|
|
callback(new Error(err), null)
|
|
|
|
})
|
|
|
|
}
|