mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* chore: Upgrade koa-helmet to v9 and koa-body to v8 * fix: Keep decimal parsing for pagination limit and offset
23 lines
678 B
TypeScript
23 lines
678 B
TypeScript
import type { Request } from "koa";
|
|
|
|
/**
|
|
* Helper class for reading values from incoming Koa requests.
|
|
*/
|
|
export class RequestHelper {
|
|
/**
|
|
* Get the parsed body of a request when it is a JSON object, form, or
|
|
* multipart fields.
|
|
*
|
|
* @param request The incoming request.
|
|
* @returns the body, or an empty object if the body is missing or is not an
|
|
* object.
|
|
*/
|
|
public static getBodyObject(request: Request): Record<string, unknown> {
|
|
const { body } = request;
|
|
return isRecord(body) ? body : {};
|
|
}
|
|
}
|
|
|
|
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
typeof value === "object" && value !== null && !Array.isArray(value);
|