From cf8cebf90b09ad0c2250614b29a0cb71f678d8c4 Mon Sep 17 00:00:00 2001 From: vvandenb Date: Sun, 12 Mar 2023 11:22:52 +0100 Subject: [PATCH] * Fixed error page on avater submit that is not image --- back/volume/src/users/users.controller.ts | 3 ++- front/volume/src/components/Profile.svelte | 13 ++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index c7da6de..a929e3b 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -97,7 +97,7 @@ export class UsersController { }), fileFilter: (request: Request, file: Express.Multer.File, callback) => { if (!file.mimetype.includes('image')) { - callback(new BadRequestException('Provide a valid image'), false) + callback(null, false) return } callback(null, true) @@ -113,6 +113,7 @@ export class UsersController { @FtUser() profile: Profile, @UploadedFile() file: Express.Multer.File ): Promise { + if (file === undefined) return await this.usersService.addAvatar(profile.id, file.filename) } diff --git a/front/volume/src/components/Profile.svelte b/front/volume/src/components/Profile.svelte index 9c46926..cc18c98 100644 --- a/front/volume/src/components/Profile.svelte +++ b/front/volume/src/components/Profile.svelte @@ -17,6 +17,8 @@ export let edit: number; export let user: any; + let avatarForm: HTMLFormElement; + const dispatch = createEventDispatcher(); async function handleSubmit() { let response = await fetch(API_URL, { @@ -35,13 +37,6 @@ event.preventDefault(); alert("Trying to " + (user.is2faEnabled ? "disable" : "enable") + " 2FA"); } - - function submitAvatar() { - let form: HTMLFormElement = ( - document.getElementById("upload_avatar") - ); - form.submit(); - }
@@ -55,14 +50,14 @@ action={`${API_URL}/avatar`} method="post" enctype="multipart/form-data" - id="upload_avatar" + bind:this={avatarForm} > avatarForm.submit()} />