From e1e7f1b97d6bb70e88283c50716d6df1369a80c0 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 14 Sep 2022 09:20:17 +0100 Subject: [PATCH] fix: Include the maximum document import size in the error message --- server/routes/api/documents.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/routes/api/documents.ts b/server/routes/api/documents.ts index 5c7bc1385..6aea0b7a2 100644 --- a/server/routes/api/documents.ts +++ b/server/routes/api/documents.ts @@ -4,6 +4,7 @@ import Router from "koa-router"; import mime from "mime-types"; import { Op, ScopeOptions, WhereOptions } from "sequelize"; import { subtractDate } from "@shared/utils/date"; +import { bytesToHumanReadable } from "@shared/utils/files"; import documentCreator from "@server/commands/documentCreator"; import documentImporter from "@server/commands/documentImporter"; import documentLoader from "@server/commands/documentLoader"; @@ -1068,11 +1069,15 @@ router.post("documents.import", auth(), async (ctx) => { } // @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call. - const file: any = Object.values(ctx.request.files)[0]; + const file = Object.values(ctx.request.files)[0]; assertPresent(file, "file is required"); if (env.MAXIMUM_IMPORT_SIZE && file.size > env.MAXIMUM_IMPORT_SIZE) { - throw InvalidRequestError("The selected file was too large to import"); + throw InvalidRequestError( + `The selected file was larger than the ${bytesToHumanReadable( + env.MAXIMUM_IMPORT_SIZE + )} maximum size` + ); } assertUuid(collectionId, "collectionId must be an uuid");