mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
90c5ab0833
This commit adds a `useUnless` helper method which can be used as a middleware for express. It receives an express-middleware and an array of paths. When a request matches one of the given paths, this middleware does nothing. Otherwise the given middleware is called. For the express-session middleware this helper middleware is used to avoid session creation on purely status routes. See #1446 Signed-off-by: Erik Michelson <github@erik.michelson.eu>
36 lines
797 B
JavaScript
36 lines
797 B
JavaScript
'use strict'
|
|
|
|
exports.isSQLite = function isSQLite (sequelize) {
|
|
return sequelize.options.dialect === 'sqlite'
|
|
}
|
|
|
|
exports.getImageMimeType = function getImageMimeType (imagePath) {
|
|
const fileExtension = /[^.]+$/.exec(imagePath)
|
|
|
|
switch (fileExtension[0].toLowerCase()) {
|
|
case 'bmp':
|
|
return 'image/bmp'
|
|
case 'gif':
|
|
return 'image/gif'
|
|
case 'jpg':
|
|
case 'jpeg':
|
|
return 'image/jpeg'
|
|
case 'png':
|
|
return 'image/png'
|
|
case 'tiff':
|
|
return 'image/tiff'
|
|
case 'svg':
|
|
return 'image/svg+xml'
|
|
default:
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
exports.useUnless = function excludeRoute (paths, middleware) {
|
|
return function (req, res, next) {
|
|
if (paths.includes(req.path)) {
|
|
return next()
|
|
}
|
|
return middleware(req, res, next)
|
|
}
|
|
}
|