Files
outline/server/utils/koa.ts
dependabot[bot] 05c5d0637e 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>
2023-02-24 05:11:49 -08:00

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;
};