0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

fix(core): fix upload file guard (#5810)

fix: remove the plus sign in front of the phone number (#5801)

Co-authored-by: Kamto <kam_to@outlook.com>
This commit is contained in:
wangsijie 2024-04-30 11:40:05 +08:00 committed by GitHub
parent 224723413a
commit 3486b12e86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -0,0 +1,10 @@
---
"@logto/phrases": patch
"@logto/core": patch
---
Fix file upload API.
The `koa-body` has been upgraded to the latest version, which caused the file upload API to break. This change fixes the issue.
The `ctx.request.files.file` in the new version is an array, so the code has been updated to pick the first one.

View file

@ -52,13 +52,15 @@ export default function userAssetsRoutes<T extends ManagementApiRouter>(
'/user-assets', '/user-assets',
koaGuard({ koaGuard({
files: object({ files: object({
file: uploadFileGuard, file: uploadFileGuard.array().min(1),
}), }),
response: userAssetsGuard, response: userAssetsGuard,
}), }),
async (ctx, next) => { async (ctx, next) => {
const { file } = ctx.guard.files; const { file: bodyFiles } = ctx.guard.files;
const file = bodyFiles[0];
assertThat(file, 'guard.invalid_input');
assertThat(file.size <= maxUploadFileSize, 'guard.file_size_exceeded'); assertThat(file.size <= maxUploadFileSize, 'guard.file_size_exceeded');
assertThat( assertThat(
allowUploadMimeTypes.map(String).includes(file.mimetype), allowUploadMimeTypes.map(String).includes(file.mimetype),