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) => {
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<void> {
if (file === undefined) return
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 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 = <HTMLFormElement>(
document.getElementById("upload_avatar")
);
form.submit();
}
</script>
<div class="overlay">
@ -55,14 +50,14 @@
action={`${API_URL}/avatar`}
method="post"
enctype="multipart/form-data"
id="upload_avatar"
bind:this={avatarForm}
>
<input
type="file"
id="avatar-input"
name="avatar"
accept="image/png, image/gif, image/jpeg"
on:change={submitAvatar}
on:change={() => avatarForm.submit()}
/>
</form>
<label class="img-class" for="avatar-input">

Loading…
Cancel
Save