Skip to content

Commit

Permalink
fix(core): fix upload file guard (#5810)
Browse files Browse the repository at this point in the history
fix: remove the plus sign in front of the phone number (#5801)

Co-authored-by: Kamto <[email protected]>
  • Loading branch information
wangsijie and kamto7 committed Apr 30, 2024
1 parent 2247234 commit 3486b12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .changeset/smart-melons-shop.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 4 additions & 2 deletions packages/core/src/routes/user-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ export default function userAssetsRoutes<T extends ManagementApiRouter>(
'/user-assets',
koaGuard({
files: object({
file: uploadFileGuard,
file: uploadFileGuard.array().min(1),
}),
response: userAssetsGuard,
}),
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(
allowUploadMimeTypes.map(String).includes(file.mimetype),
Expand Down

0 comments on commit 3486b12

Please sign in to comment.