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()} />