Browse Source

* Fixed error page on avater submit that is not image

master
vvandenb 2 years ago
parent
commit
cf8cebf90b
  1. 3
      back/volume/src/users/users.controller.ts
  2. 13
      front/volume/src/components/Profile.svelte

3
back/volume/src/users/users.controller.ts

@ -97,7 +97,7 @@ export class UsersController {
}), }),
fileFilter: (request: Request, file: Express.Multer.File, callback) => { fileFilter: (request: Request, file: Express.Multer.File, callback) => {
if (!file.mimetype.includes('image')) { if (!file.mimetype.includes('image')) {
callback(new BadRequestException('Provide a valid image'), false) callback(null, false)
return return
} }
callback(null, true) callback(null, true)
@ -113,6 +113,7 @@ export class UsersController {
@FtUser() profile: Profile, @FtUser() profile: Profile,
@UploadedFile() file: Express.Multer.File @UploadedFile() file: Express.Multer.File
): Promise<void> { ): Promise<void> {
if (file === undefined) return
await this.usersService.addAvatar(profile.id, file.filename) await this.usersService.addAvatar(profile.id, file.filename)
} }

13
front/volume/src/components/Profile.svelte

@ -17,6 +17,8 @@
export let edit: number; export let edit: number;
export let user: any; export let user: any;
let avatarForm: HTMLFormElement;
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
async function handleSubmit() { async function handleSubmit() {
let response = await fetch(API_URL, { let response = await fetch(API_URL, {
@ -35,13 +37,6 @@
event.preventDefault(); event.preventDefault();
alert("Trying to " + (user.is2faEnabled ? "disable" : "enable") + " 2FA"); alert("Trying to " + (user.is2faEnabled ? "disable" : "enable") + " 2FA");
} }
function submitAvatar() {
let form: HTMLFormElement = <HTMLFormElement>(
document.getElementById("upload_avatar")
);
form.submit();
}
</script> </script>
<div class="overlay"> <div class="overlay">
@ -55,14 +50,14 @@
action={`${API_URL}/avatar`} action={`${API_URL}/avatar`}
method="post" method="post"
enctype="multipart/form-data" enctype="multipart/form-data"
id="upload_avatar" bind:this={avatarForm}
> >
<input <input
type="file" type="file"
id="avatar-input" id="avatar-input"
name="avatar" name="avatar"
accept="image/png, image/gif, image/jpeg" accept="image/png, image/gif, image/jpeg"
on:change={submitAvatar} on:change={() => avatarForm.submit()}
/> />
</form> </form>
<label class="img-class" for="avatar-input"> <label class="img-class" for="avatar-input">

Loading…
Cancel
Save