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:
David Mehren 2021-12-02 17:19:24 +01:00
parent f6a61c4ea7
commit 7c5c2f7981
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -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)