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