chore(deps): bump koa-body from 4.2.0 to 6.0.1 (#4806)
* chore(deps): bump koa-body from 4.2.0 to 6.0.1 Bumps [koa-body](https://github.com/koajs/koa-body) from 4.2.0 to 6.0.1. - [Release notes](https://github.com/koajs/koa-body/releases) - [Changelog](https://github.com/koajs/koa-body/blob/master/CHANGELOG.md) - [Commits](https://github.com/koajs/koa-body/compare/v4.2.0...v6.0.1) --- updated-dependencies: - dependency-name: koa-body dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Update types * test --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
25
server/utils/koa.ts
Normal file
25
server/utils/koa.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import formidable from "formidable";
|
||||
import { Request } from "koa";
|
||||
import { isArray } from "lodash";
|
||||
|
||||
/**
|
||||
* Get the first file from an incoming koa request
|
||||
*
|
||||
* @param request The incoming request
|
||||
* @returns The first file or undefined
|
||||
*/
|
||||
export const getFileFromRequest = (
|
||||
request: Request
|
||||
): formidable.File | undefined => {
|
||||
const { files } = request;
|
||||
if (!files) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const file = Object.values(files)[0];
|
||||
if (!file) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return isArray(file) ? file[0] : file;
|
||||
};
|
||||
Reference in New Issue
Block a user