diff options
author | Christoph (Sheogorath) Kern | 2018-03-21 14:13:32 +0100 |
---|---|---|
committer | GitHub | 2018-03-21 14:13:32 +0100 |
commit | 6485f9665976adfc3dc17233c1922efb89e5d43a (patch) | |
tree | 9b5356ada5cda0e1a5cf0a1eb7e81398622e139b /lib/web/imageRouter/imgur.js | |
parent | 6e6a98b392f78567e98a9b49ff0dd193f885e242 (diff) | |
parent | 1756e76dc31495d03c8792fa672ae6bb94d24ea8 (diff) |
Merge pull request #771 from SISheogorath/refactor/imageRouter
Refactoring imageRouter to modularity
Diffstat (limited to '')
-rw-r--r-- | lib/web/imageRouter/imgur.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/web/imageRouter/imgur.js b/lib/web/imageRouter/imgur.js new file mode 100644 index 00000000..31d5f55c --- /dev/null +++ b/lib/web/imageRouter/imgur.js @@ -0,0 +1,28 @@ +'use strict' +const config = require('../../config') +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) + return + } + + if (!callback || typeof callback !== 'function') { + callback(new Error('Callback has to be a function'), 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) + }) +} |