forked from scalabel/scalabel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'scalabel:master' into master
- Loading branch information
Showing
42 changed files
with
739 additions
and
352 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { IncomingMessage } from "http" | ||
import { NextFunction, Request, Response } from "express" | ||
import formidable, { Fields, Files } from "formidable" | ||
|
||
const maxFileSize = 1000 * 1024 * 1024 // 1G | ||
|
||
/** | ||
* A middleware to parse multipart/form-data request, after which two | ||
* properties, `fields` and `files`, will be added to the request. | ||
* | ||
* @param req - | ||
* @param _ | ||
* @param next | ||
*/ | ||
export function multipartFormData( | ||
req: Request, | ||
_: Response, | ||
next: NextFunction | ||
): void { | ||
parseMultipartFormData(req) | ||
.then(({ fields, files }) => { | ||
Object.assign(req, { fields, files }) | ||
next() | ||
}) | ||
.catch(next) | ||
} | ||
|
||
/** | ||
* Parse an incoming multipart/form-data request. | ||
* | ||
* @param req | ||
*/ | ||
export async function parseMultipartFormData( | ||
req: IncomingMessage | ||
): Promise<{ fields: Fields; files: Files }> { | ||
return await new Promise((resolve, reject) => { | ||
const form = new formidable.IncomingForm({ maxFileSize: maxFileSize }) | ||
form.parse(req, (err, fields, files) => { | ||
// `err` is defined as `any` by formidable. | ||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve({ fields, files }) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.