hedgeagent/1.12.0 #1
@@ -1,12 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
import isSvg from 'is-svg'
|
||||
import formidable from 'formidable'
|
||||
|
||||
import { createRequire } from 'module'
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
const Router = require('express').Router
|
||||
const formidable = require('formidable')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const { v4: uuidv4 } = require('uuid')
|
||||
@@ -125,21 +125,22 @@ imageRouter.post('/uploadimage', function (req, res) {
|
||||
}
|
||||
})
|
||||
|
||||
form.parse(req, async function (err, fields, files) {
|
||||
form.parse(req, async function (err, _fields, files) {
|
||||
if (err) {
|
||||
logger.error(`Image upload error: formidable error: ${err}`)
|
||||
rimraf.sync(tmpDir)
|
||||
return errors.errorForbidden(res)
|
||||
} else if (!files.image || !files.image.filepath) {
|
||||
} else if (!files.image || !files.image.length < 1 || !files.image[0].filepath) {
|
||||
logger.debug(`${JSON.stringify(files)}`)
|
||||
logger.error('Image upload error: Upload didn\'t contain file)')
|
||||
rimraf.sync(tmpDir)
|
||||
return errors.errorBadRequest(res)
|
||||
} else if (!(await checkUploadType(files.image.filepath))) {
|
||||
} else if (!(await checkUploadType(files.image[0].filepath))) {
|
||||
rimraf.sync(tmpDir)
|
||||
return errors.errorBadRequest(res)
|
||||
} else {
|
||||
const extension = path.extname(files.image.filepath).toLowerCase()
|
||||
if (extension === '.svg' && !sanitizeSvg(files.image.filepath)) {
|
||||
const extension = path.extname(files.image[0].filepath).toLowerCase()
|
||||
if (extension === '.svg' && !sanitizeSvg(files.image[0].filepath)) {
|
||||
logger.error('Image upload error: SVG sanitization failed')
|
||||
rimraf.sync(tmpDir)
|
||||
return errors.errorBadRequest(res)
|
||||
@@ -151,9 +152,9 @@ imageRouter.post('/uploadimage', function (req, res) {
|
||||
|
||||
const uploadProvider = require('./' + config.imageUploadType)
|
||||
logger.debug(
|
||||
`imageRouter: Uploading ${files.image.filepath} using ${config.imageUploadType}`
|
||||
`imageRouter: Uploading ${files.image[0].filepath} using ${config.imageUploadType}`
|
||||
)
|
||||
uploadProvider.uploadImage(files.image.filepath, function (err, url) {
|
||||
uploadProvider.uploadImage(files.image[0].filepath, function (err, url) {
|
||||
rimraf.sync(tmpDir)
|
||||
if (err !== null) {
|
||||
logger.error(err)
|
||||
|
||||
Reference in New Issue
Block a user