🚀 Hotfixes: inline PDF preview and instant profile update in UI

This commit is contained in:
Hamza-Ayed
2026-04-22 17:15:43 +03:00
parent 4c2fd7bba5
commit 7e0e271be2
3 changed files with 31 additions and 1 deletions

View File

@@ -18,7 +18,9 @@ import {
UploadedFile,
UseInterceptors,
ParseUUIDPipe,
Res,
} from '@nestjs/common';
import { Response } from 'express';
import { FileInterceptor } from '@nestjs/platform-express';
import { InvoicesService } from './invoice.service';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
@@ -111,7 +113,25 @@ export class InvoicesController {
async getFile(
@CurrentUser() user: any,
@Param('id', ParseUUIDPipe) id: string,
@Res({ passthrough: true }) res: Response,
) {
return this.invoicesService.getFile(user.tenantId, id);
const streamableFile = await this.invoicesService.getFile(user.tenantId, id);
// We need to determine the content type to ensure it opens inline in the browser (iframe)
// We can fetch the invoice details first to get the extension.
const invoice = await this.invoicesService.findOne(user.tenantId, id);
let mimeType = 'application/pdf'; // Default fallback
if (invoice.original_file_path) {
const ext = invoice.original_file_path.split('.').pop()?.toLowerCase();
if (ext === 'jpg' || ext === 'jpeg') mimeType = 'image/jpeg';
else if (ext === 'png') mimeType = 'image/png';
}
res.set({
'Content-Type': mimeType,
'Content-Disposition': 'inline', // This forces the browser to display it instead of downloading
});
return streamableFile;
}
}