mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
Fix imageRouter after upgrade to formidable 2
file.path is now file.filepath, and we need to use the proper constructor See https://github.com/node-formidable/formidable/blob/master/CHANGELOG.md#200 Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
f6a61c4ea7
commit
7c5c2f7981
1 changed files with 8 additions and 7 deletions
|
@ -67,21 +67,22 @@ imageRouter.post('/uploadimage', function (req, res) {
|
|||
return errors.errorForbidden(res)
|
||||
}
|
||||
|
||||
const form = new formidable.IncomingForm()
|
||||
form.keepExtensions = true
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hedgedoc-'))
|
||||
form.uploadDir = tmpDir
|
||||
const form = formidable({
|
||||
keepExtensions: true,
|
||||
uploadDir: tmpDir
|
||||
})
|
||||
|
||||
form.parse(req, async function (err, fields, files) {
|
||||
if (err) {
|
||||
logger.error(`Image upload error: formidable error: ${err}`)
|
||||
rimraf(tmpDir)
|
||||
return errors.errorForbidden(res)
|
||||
} else if (!files.image || !files.image.path) {
|
||||
} else if (!files.image || !files.image.filepath) {
|
||||
logger.error("Image upload error: Upload didn't contain file)")
|
||||
rimraf.sync(tmpDir)
|
||||
return errors.errorBadRequest(res)
|
||||
} else if (!(await checkUploadType(files.image.path))) {
|
||||
} else if (!(await checkUploadType(files.image.filepath))) {
|
||||
rimraf.sync(tmpDir)
|
||||
return errors.errorBadRequest(res)
|
||||
} else {
|
||||
|
@ -91,9 +92,9 @@ imageRouter.post('/uploadimage', function (req, res) {
|
|||
|
||||
const uploadProvider = require('./' + config.imageUploadType)
|
||||
logger.debug(
|
||||
`imageRouter: Uploading ${files.image.path} using ${config.imageUploadType}`
|
||||
`imageRouter: Uploading ${files.image.filepath} using ${config.imageUploadType}`
|
||||
)
|
||||
uploadProvider.uploadImage(files.image.path, function (err, url) {
|
||||
uploadProvider.uploadImage(files.image.filepath, function (err, url) {
|
||||
rimraf.sync(tmpDir)
|
||||
if (err !== null) {
|
||||
logger.error(err)
|
||||
|
|
Loading…
Reference in a new issue