mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 19:53:59 -05:00
b5574466cd
Signed-off-by: Adam Hoka <hoka.adam@nexogen.hu>
28 lines
773 B
JavaScript
28 lines
773 B
JavaScript
'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') {
|
|
logger.error('Callback has to be a function')
|
|
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)
|
|
})
|
|
}
|