diff --git a/.changeset/fix-file-size.md b/.changeset/fix-file-size.md new file mode 100644 index 00000000000..7faa7a2d347 --- /dev/null +++ b/.changeset/fix-file-size.md @@ -0,0 +1,5 @@ +--- +"@keystone-6/core": patch +--- + +Fixes `serxer.maxFileSize` parameter being ignored diff --git a/examples/assets-local/keystone.ts b/examples/assets-local/keystone.ts index b23e6ef3915..de4cfc66bac 100644 --- a/examples/assets-local/keystone.ts +++ b/examples/assets-local/keystone.ts @@ -1,5 +1,6 @@ import { config } from '@keystone-6/core' import { lists } from './schema' +import bytes from 'bytes' export default config({ db: { @@ -10,6 +11,9 @@ export default config({ prismaClientPath: 'node_modules/myprisma', }, lists, + server: { + maxFileSize: bytes('40Mb') + }, storage: { my_images: { kind: 'local', diff --git a/examples/assets-local/package.json b/examples/assets-local/package.json index 7cec9e5c6b9..c16353c3f0b 100644 --- a/examples/assets-local/package.json +++ b/examples/assets-local/package.json @@ -11,9 +11,11 @@ }, "dependencies": { "@keystone-6/core": "^6.3.0", - "@prisma/client": "5.19.0" + "@prisma/client": "5.19.0", + "bytes": "^3.1.1" }, "devDependencies": { + "@types/bytes": "^3.1.1", "prisma": "5.19.0", "typescript": "^5.5.0" } diff --git a/examples/assets-s3/keystone.ts b/examples/assets-s3/keystone.ts index 08cacb24914..c317b20e4e5 100644 --- a/examples/assets-s3/keystone.ts +++ b/examples/assets-s3/keystone.ts @@ -1,6 +1,7 @@ import 'dotenv/config' import { config } from '@keystone-6/core' import { lists } from './schema' +import bytes from 'bytes' const { S3_BUCKET_NAME: bucketName = 'keystone-test', @@ -18,6 +19,9 @@ export default config({ prismaClientPath: 'node_modules/myprisma', }, lists, + server: { + maxFileSize: bytes('8Mb') + }, storage: { my_images: { kind: 's3', diff --git a/examples/assets-s3/package.json b/examples/assets-s3/package.json index 1ac5de3e87f..1f416c994d6 100644 --- a/examples/assets-s3/package.json +++ b/examples/assets-s3/package.json @@ -12,9 +12,11 @@ "dependencies": { "@keystone-6/core": "^6.3.0", "@prisma/client": "5.19.0", + "bytes": "^3.1.1", "dotenv": "^16.0.0" }, "devDependencies": { + "@types/bytes": "^3.1.1", "prisma": "5.19.0", "typescript": "^5.5.0" } diff --git a/packages/core/src/lib/defaults.ts b/packages/core/src/lib/defaults.ts index 9cdea00b6a3..84c123b356b 100644 --- a/packages/core/src/lib/defaults.ts +++ b/packages/core/src/lib/defaults.ts @@ -130,7 +130,8 @@ export function resolveDefaults (config: }, lists: injectDefaults(config, defaultIdField), server: { - maxFileSize: 200 * 1024 * 1024, // 200 MiB + ...config.server, + maxFileSize: config.server?.maxFileSize ?? (200 * 1024 * 1024), // 200 MiB extendExpressApp: config.server?.extendExpressApp ?? noop, extendHttpServer: config.server?.extendHttpServer ?? noop, cors, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 66744925e68..4ca794775ca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -602,7 +602,13 @@ importers: '@prisma/client': specifier: 5.19.0 version: 5.19.0(prisma@5.19.0) + bytes: + specifier: ^3.1.1 + version: 3.1.2 devDependencies: + '@types/bytes': + specifier: ^3.1.1 + version: 3.1.4 prisma: specifier: 5.19.0 version: 5.19.0 @@ -618,10 +624,16 @@ importers: '@prisma/client': specifier: 5.19.0 version: 5.19.0(prisma@5.19.0) + bytes: + specifier: ^3.1.1 + version: 3.1.2 dotenv: specifier: ^16.0.0 version: 16.4.5 devDependencies: + '@types/bytes': + specifier: ^3.1.1 + version: 3.1.4 prisma: specifier: 5.19.0 version: 5.19.0