1
0
Fork 0
mirror of https://github.com/hedgedoc/hedgedoc.git synced 2024-12-21 08:17:04 -05:00
hedgedoc/old_src/lib/web/imageRouter/imgur.ts

31 lines
886 B
TypeScript
Raw Normal View History

import imgur from 'old_src/lib/web/imageRouter/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 }