summaryrefslogtreecommitdiff
path: root/lib/web/imageRouter
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/web/imageRouter/azure.js2
-rw-r--r--lib/web/imageRouter/index.js40
-rw-r--r--lib/web/imageRouter/minio.js8
-rw-r--r--lib/web/imageRouter/s3.js2
4 files changed, 35 insertions, 17 deletions
diff --git a/lib/web/imageRouter/azure.js b/lib/web/imageRouter/azure.js
index 22ee5585..c56ac860 100644
--- a/lib/web/imageRouter/azure.js
+++ b/lib/web/imageRouter/azure.js
@@ -17,7 +17,7 @@ exports.uploadImage = function (imagePath, callback) {
return
}
- var azureBlobService = azure.createBlobService(config.azure.connectionString)
+ const azureBlobService = azure.createBlobService(config.azure.connectionString)
azureBlobService.createContainerIfNotExists(config.azure.container, { publicAccessLevel: 'blob' }, function (err, result, response) {
if (err) {
diff --git a/lib/web/imageRouter/index.js b/lib/web/imageRouter/index.js
index afa9bbf6..0a72c65c 100644
--- a/lib/web/imageRouter/index.js
+++ b/lib/web/imageRouter/index.js
@@ -12,20 +12,28 @@ const config = require('../../config')
const logger = require('../../logger')
const errors = require('../../errors')
-const imageRouter = module.exports = Router()
+const imageRouter = (module.exports = Router())
async function checkUploadType (filePath) {
const typeFromMagic = await FileType.fromFile(filePath)
if (typeFromMagic === undefined) {
- logger.error(`Image upload error: Could not determine MIME-type`)
+ logger.error('Image upload error: Could not determine MIME-type')
return false
}
if (path.extname(filePath) !== '.' + typeFromMagic.ext) {
- logger.error(`Image upload error: Provided file extension does not match MIME-type`)
+ logger.error(
+ 'Image upload error: Provided file extension does not match MIME-type'
+ )
return false
}
if (!config.allowedUploadMimeTypes.includes(typeFromMagic.mime)) {
- logger.error(`Image upload error: MIME-type "${typeFromMagic.mime}" of uploaded file not allowed, only "${config.allowedUploadMimeTypes.join(', ')}" are allowed`)
+ logger.error(
+ `Image upload error: MIME-type "${
+ typeFromMagic.mime
+ }" of uploaded file not allowed, only "${config.allowedUploadMimeTypes.join(
+ ', '
+ )}" are allowed`
+ )
return false
}
return true
@@ -33,12 +41,18 @@ async function checkUploadType (filePath) {
// upload image
imageRouter.post('/uploadimage', function (req, res) {
- if (!req.isAuthenticated() && !config.allowAnonymous && !config.allowAnonymousEdits) {
- logger.error(`Image upload error: Anonymous edits and therefore uploads are not allowed)`)
+ if (
+ !req.isAuthenticated() &&
+ !config.allowAnonymous &&
+ !config.allowAnonymousEdits
+ ) {
+ logger.error(
+ 'Image upload error: Anonymous edits and therefore uploads are not allowed'
+ )
return errors.errorForbidden(res)
}
- var form = new formidable.IncomingForm()
+ const form = new formidable.IncomingForm()
form.keepExtensions = true
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hedgedoc-'))
form.uploadDir = tmpDir
@@ -49,17 +63,21 @@ imageRouter.post('/uploadimage', function (req, res) {
rimraf(tmpDir)
return errors.errorForbidden(res)
} else if (!files.image || !files.image.path) {
- logger.error(`Image upload error: Upload didn't contain file)`)
+ 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.path))) {
rimraf.sync(tmpDir)
return errors.errorBadRequest(res)
} else {
- logger.debug(`SERVER received uploadimage: ${JSON.stringify(files.image)}`)
+ logger.debug(
+ `SERVER received uploadimage: ${JSON.stringify(files.image)}`
+ )
const uploadProvider = require('./' + config.imageUploadType)
- logger.debug(`imageRouter: Uploading ${files.image.path} using ${config.imageUploadType}`)
+ logger.debug(
+ `imageRouter: Uploading ${files.image.path} using ${config.imageUploadType}`
+ )
uploadProvider.uploadImage(files.image.path, function (err, url) {
rimraf.sync(tmpDir)
if (err !== null) {
diff --git a/lib/web/imageRouter/minio.js b/lib/web/imageRouter/minio.js
index 91de5ff1..3ced94e2 100644
--- a/lib/web/imageRouter/minio.js
+++ b/lib/web/imageRouter/minio.js
@@ -32,16 +32,16 @@ exports.uploadImage = function (imagePath, callback) {
return
}
- let key = path.join('uploads', path.basename(imagePath))
- let protocol = config.minio.secure ? 'https' : 'http'
+ const key = path.join('uploads', path.basename(imagePath))
+ const protocol = config.minio.secure ? 'https' : 'http'
minioClient.putObject(config.s3bucket, key, buffer, buffer.size, getImageMimeType(imagePath), function (err, data) {
if (err) {
callback(new Error(err), null)
return
}
- let hidePort = [80, 443].includes(config.minio.port)
- let urlPort = hidePort ? '' : `:${config.minio.port}`
+ const hidePort = [80, 443].includes(config.minio.port)
+ const urlPort = hidePort ? '' : `:${config.minio.port}`
callback(null, `${protocol}://${config.minio.endPoint}${urlPort}/${config.s3bucket}/${key}`)
})
})
diff --git a/lib/web/imageRouter/s3.js b/lib/web/imageRouter/s3.js
index 2bf08cc7..5bb8e160 100644
--- a/lib/web/imageRouter/s3.js
+++ b/lib/web/imageRouter/s3.js
@@ -26,7 +26,7 @@ exports.uploadImage = function (imagePath, callback) {
callback(new Error(err), null)
return
}
- let params = {
+ const params = {
Bucket: config.s3bucket,
Key: path.join('uploads', path.basename(imagePath)),
Body: buffer