mirror of
https://github.com/status-im/codimd.git
synced 2025-01-13 05:34:36 +00:00
e97c2821fa
Signed-off-by: Raccoon <raccoon@hackmd.io>
29 lines
786 B
TypeScript
29 lines
786 B
TypeScript
'use strict'
|
|
import * as imgur from "@hackmd/imgur";
|
|
|
|
import * as config from "../config";
|
|
import * as logger from "../logger";
|
|
|
|
export function uploadImage(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)
|
|
})
|
|
}
|