Skip to content

Commit 8557133

Browse files
committed
Add imageRouter handler for lutim
Signed-off-by: Dylan Dervaux <dylanderv05@gmail.com>
1 parent d389311 commit 8557133

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/web/imageRouter/lutim.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict'
2+
const config = require('../../config')
3+
const logger = require('../../logger')
4+
5+
const lutim = require('lutim')
6+
7+
exports.uploadImage = function (imagePath, callback) {
8+
if (!imagePath || typeof imagePath !== 'string') {
9+
callback(new Error('Image path is missing or wrong'), null)
10+
return
11+
}
12+
13+
if (!callback || typeof callback !== 'function') {
14+
logger.error('Callback has to be a function')
15+
return
16+
}
17+
18+
if (config.lutim && config.lutim.url) {
19+
lutim.setAPIUrl(config.lutim.url)
20+
}
21+
22+
lutim.uploadImage(imagePath)
23+
.then(function (json) {
24+
if (config.debug) {
25+
logger.info('SERVER uploadimage success: ' + JSON.stringify(json))
26+
}
27+
callback(null, lutim.getAPIUrl() + json.msg.short)
28+
}).catch(function (err) {
29+
callback(new Error(err), null)
30+
})
31+
}

0 commit comments

Comments
 (0)