diff options
author | Christoph (Sheogorath) Kern | 2019-04-10 11:39:11 +0200 |
---|---|---|
committer | GitHub | 2019-04-10 11:39:11 +0200 |
commit | ef348fc49b01711aaea3c0b68cdd9fa77876c596 (patch) | |
tree | 496225cc71133387b3c6e51b899d9a91d204f420 /lib/web | |
parent | f541c00bad561672c91bb0249acd8e6ce2f58a9e (diff) | |
parent | 208070d2e776c437154e6ead552364b3956adf1c (diff) |
Merge pull request #33 from codimd/lutim-support
Add support for image hosting with lutim
Diffstat (limited to 'lib/web')
-rw-r--r-- | lib/web/imageRouter/lutim.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/web/imageRouter/lutim.js b/lib/web/imageRouter/lutim.js new file mode 100644 index 00000000..78b856c9 --- /dev/null +++ b/lib/web/imageRouter/lutim.js @@ -0,0 +1,31 @@ +'use strict' +const config = require('../../config') +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) + return + } + + if (!callback || typeof callback !== 'function') { + logger.error('Callback has to be a function') + return + } + + if (config.lutim && config.lutim.url) { + lutim.setAPIUrl(config.lutim.url) + } + + lutim.uploadImage(imagePath) + .then(function (json) { + if (config.debug) { + logger.info('SERVER uploadimage success: ' + JSON.stringify(json)) + } + callback(null, lutim.getAPIUrl() + json.msg.short) + }).catch(function (err) { + callback(new Error(err), null) + }) +} |