mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-06 14:58:27 +00:00
* feat: add user avatar * update: @nest/platform-express from 8.0.0 to 8.4.4 * add avatar_id in login response * add user avatar upload in frontend * align cross divider with layout icons' * generate nest model - extensions * cleanup * fix tests * reduce the avatar size on homepage * fix review comments * import Express * add blob to csp
36 lines
965 B
TypeScript
36 lines
965 B
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
UseInterceptors,
|
|
ClassSerializerInterceptor,
|
|
Res,
|
|
StreamableFile,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { Readable } from 'stream';
|
|
import { Response } from 'express';
|
|
import { FilesService } from '../services/files.service';
|
|
import { JwtAuthGuard } from 'src/modules/auth/jwt-auth.guard';
|
|
|
|
@Controller('files')
|
|
@UseInterceptors(ClassSerializerInterceptor)
|
|
export class FilesController {
|
|
constructor(private readonly filesService: FilesService) {}
|
|
|
|
@Get(':id')
|
|
@UseGuards(JwtAuthGuard)
|
|
async show(@Param('id') id: string, @Res({ passthrough: true }) response: Response) {
|
|
const file = await this.filesService.findOne(id);
|
|
|
|
const stream = Readable.from(file.data);
|
|
|
|
response.set({
|
|
'Content-Disposition': `inline; filename="${file.filename}"`,
|
|
'Content-Type': 'image',
|
|
});
|
|
|
|
// https://docs.nestjs.com/techniques/streaming-files
|
|
return new StreamableFile(stream);
|
|
}
|
|
}
|