Migrated more functions to use PdfFile

This commit is contained in:
Saud Fatayerji
2023-11-12 16:57:53 +03:00
parent 0d915fcc33
commit 8018947353
10 changed files with 153 additions and 94 deletions

View File

@@ -1,13 +1,15 @@
import express, { Request, Response } from 'express';
import { Response } from 'express';
import { PdfFile } from '@stirling-pdf/shared-operations/wrappers/PdfFile'
export function respondWithBinaryPdf(res: Response, buffer: Uint8Array, filename: string) {
export async function respondWithPdfFile(res: Response, file: PdfFile): Promise<void> {
const byteFile = await file.convertToByteArrayFile();
res.writeHead(200, {
'Content-Type': "application/pdf",
'Content-disposition': 'attachment;filename=' + filename,
'Content-Length': buffer.length
'Content-disposition': 'attachment;filename=' + byteFile.filename,
'Content-Length': byteFile.byteArray?.length
});
res.end(buffer)
res.end(byteFile.byteArray)
}
export function response_mustHaveExactlyOneFile(res: Response): void {