mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-22 20:04:38 +02:00
Remove dependency express-fileupload
This commit is contained in:
parent
1dbfb5637a
commit
7aa7e662b2
20 changed files with 2782 additions and 23 deletions
34
server/libs/expressFileupload/isEligibleRequest.js
Normal file
34
server/libs/expressFileupload/isEligibleRequest.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const ACCEPTABLE_CONTENT_TYPE = /^(multipart\/.+);(.*)$/i;
|
||||
const UNACCEPTABLE_METHODS = ['GET', 'HEAD'];
|
||||
|
||||
/**
|
||||
* Ensures the request contains a content body
|
||||
* @param {Object} req Express req object
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
const hasBody = (req) => {
|
||||
return ('transfer-encoding' in req.headers) ||
|
||||
('content-length' in req.headers && req.headers['content-length'] !== '0');
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensures the request is not using a non-compliant multipart method
|
||||
* such as GET or HEAD
|
||||
* @param {Object} req Express req object
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
const hasAcceptableMethod = req => !UNACCEPTABLE_METHODS.includes(req.method);
|
||||
|
||||
/**
|
||||
* Ensures that only multipart requests are processed by express-fileupload
|
||||
* @param {Object} req Express req object
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
const hasAcceptableContentType = req => ACCEPTABLE_CONTENT_TYPE.test(req.headers['content-type']);
|
||||
|
||||
/**
|
||||
* Ensures that the request in question is eligible for file uploads
|
||||
* @param {Object} req Express req object
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
module.exports = req => hasBody(req) && hasAcceptableMethod(req) && hasAcceptableContentType(req);
|
Loading…
Add table
Add a link
Reference in a new issue