Browse Source

fix avatars

master
nicolas-arnaud 2 years ago
parent
commit
4dea52dfc2
  1. 12
      back/volume/src/users/users.controller.ts
  2. 2
      back/volume/src/users/users.service.ts

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

@ -80,7 +80,7 @@ export class UsersController {
@FtUser() profile: Profile, @FtUser() profile: Profile,
@UploadedFile() file: Express.Multer.File @UploadedFile() file: Express.Multer.File
) { ) {
return await this.usersService.addAvatar(profile.id, file.filename) await this.usersService.addAvatar(profile.id, file.filename)
} }
@Get('avatar') @Get('avatar')
@ -89,15 +89,7 @@ export class UsersController {
@FtUser() profile: Profile, @FtUser() profile: Profile,
@Res({ passthrough: true }) response: Response @Res({ passthrough: true }) response: Response
){ ){
const user = await this.usersService.findUser(profile.id) return await this.getAvatarById(profile.id, response);
if (!user) return
const filename = user.avatar
const stream = createReadStream(join(process.cwd(), 'avatars/' + filename))
response.set({
'Content-Diposition': `inline; filename="${filename}"`,
'Content-Type': 'image/jpg'
})
return new StreamableFile(stream)
} }
@Get('avatar/:id') @Get('avatar/:id')

2
back/volume/src/users/users.service.ts

@ -52,7 +52,7 @@ export class UsersService {
} }
async addAvatar (ftId: number, filename: string) { async addAvatar (ftId: number, filename: string) {
return await this.usersRepository.update(ftId, { return await this.usersRepository.update({ftId}, {
avatar: filename avatar: filename
}) })
} }

Loading…
Cancel
Save