mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-26 09:31:22 +00:00
0621d7a72d
Due to the deprecation of the old `url`-API provided by NodeJS we replaced `url.resolve` with `url.URL.resolve`, which doesn't exist. This patch fixes the local filesystem upload of CodiMD by using the new API correctly. Creating an URL object and using its href. Some more background: https://nodejs.org/api/url.html#url_url_href https://nodejs.org/api/url.html#url_url_resolve_from_to Fixes https://github.com/hackmdio/codimd/issues/1102 Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
20 lines
553 B
JavaScript
20 lines
553 B
JavaScript
'use strict'
|
|
const URL = require('url').URL
|
|
const path = require('path')
|
|
|
|
const config = require('../../config')
|
|
const logger = require('../../logger')
|
|
|
|
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
|
|
}
|
|
|
|
callback(null, (new URL(path.basename(imagePath), config.serverURL + '/uploads/')).href)
|
|
}
|