mirror of
https://github.com/outline/outline.git
synced 2026-01-08 03:59:58 -06:00
* 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>
26 lines
533 B
TypeScript
26 lines
533 B
TypeScript
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;
|
|
};
|