maintenant seul les jpg et png sont cceptés pour l'avatar
This commit is contained in:
@@ -24,5 +24,13 @@ export const storageForAvatar = {
|
||||
const extension : string = MIME_TYPES[file.mimetype];
|
||||
cb(null, `${filename}${extension}`);
|
||||
}
|
||||
})
|
||||
}),
|
||||
fileFilter: (req, file, cb) => {
|
||||
if (file.mimetype === 'image/png' || file.mimetype === 'image/jpg' || file.mimetype === 'image/jpeg') {
|
||||
cb(null, true);
|
||||
}
|
||||
else {
|
||||
cb(null, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
Body, Controller, Delete, Get, NotFoundException, Param, Patch, Post, Query, Redirect, Req, Res, UploadedFile, UseGuards, UseInterceptors
|
||||
Body, Controller, Delete, Get, NotFoundException,HttpStatus, Param, Patch, Post, Query, Redirect, Req, Res, UploadedFile, UseGuards, UseInterceptors
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { Response } from 'express';
|
||||
@@ -31,19 +31,6 @@ export class UsersController {
|
||||
///////////////////////// RUD //////////////////////////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* On ne fait de création via une route
|
||||
* car un utilisateur est crée à la première connexion avec l'Oauth de 42.
|
||||
*/
|
||||
|
||||
// @UseGuards(AuthenticateGuard)
|
||||
// @UseGuards(TwoFactorGuard)
|
||||
// @Get()
|
||||
// findOne(@Req() req) {
|
||||
// console.log("Backend Getting current user");
|
||||
// return this.usersService.findOne(req.user.id);
|
||||
// }
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get()
|
||||
@@ -100,9 +87,14 @@ export class UsersController {
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('avatar')
|
||||
@UseInterceptors(FileInterceptor('file', storageForAvatar))
|
||||
uploadAvatar(@UploadedFile() file, @Req() request){
|
||||
uploadAvatar(@UploadedFile() file, @Req() request, @Res() res){
|
||||
const user : User = request.user;
|
||||
this.usersService.updateAvatar(user.id, file.filename);
|
||||
if (file)
|
||||
{
|
||||
this.usersService.updateAvatar(user.id, file.filename);
|
||||
return res.status(HttpStatus.OK).json({message : "Avatar updated"});
|
||||
}
|
||||
return res.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE).json({message : "Unsupported media type. Please use a valid image file."});
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
|
||||
Reference in New Issue
Block a user