mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-26 07:00:50 +00:00
41726949e8
Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: David Mehren <dmehren1@gmail.com>
30 lines
858 B
TypeScript
30 lines
858 B
TypeScript
import imgur from 'imgur'
|
|
|
|
import { config } from '../../config'
|
|
import { logger } from '../../logger'
|
|
import { UploadProvider } from './index'
|
|
|
|
const ImgurUploadProvider: UploadProvider = {
|
|
uploadImage: (imagePath, callback) => {
|
|
if (!callback || typeof callback !== 'function') {
|
|
logger.error('Callback has to be a function')
|
|
return
|
|
}
|
|
|
|
if (!imagePath) {
|
|
callback(new Error('Image path is missing or wrong'), undefined)
|
|
return
|
|
}
|
|
|
|
imgur.setClientId(config.imgur.clientID)
|
|
imgur.uploadFile(imagePath)
|
|
.then(function (json) {
|
|
logger.debug(`SERVER uploadimage success: ${JSON.stringify(json)}`)
|
|
callback(undefined, json.data.link.replace(/^http:\/\//i, 'https://'))
|
|
}).catch(function (err) {
|
|
callback(new Error(err), undefined)
|
|
})
|
|
}
|
|
}
|
|
|
|
export { ImgurUploadProvider }
|