2023-11-11 16:35:33 +01:00
|
|
|
|
2023-11-12 14:57:53 +01:00
|
|
|
import { Response } from 'express';
|
|
|
|
import { PdfFile } from '@stirling-pdf/shared-operations/wrappers/PdfFile'
|
2023-11-11 16:35:33 +01:00
|
|
|
|
2023-11-12 14:57:53 +01:00
|
|
|
export async function respondWithPdfFile(res: Response, file: PdfFile): Promise<void> {
|
|
|
|
const byteFile = await file.convertToByteArrayFile();
|
2023-11-11 16:35:33 +01:00
|
|
|
res.writeHead(200, {
|
|
|
|
'Content-Type': "application/pdf",
|
2023-11-12 14:57:53 +01:00
|
|
|
'Content-disposition': 'attachment;filename=' + byteFile.filename,
|
|
|
|
'Content-Length': byteFile.byteArray?.length
|
2023-11-11 16:35:33 +01:00
|
|
|
});
|
2023-11-12 14:57:53 +01:00
|
|
|
res.end(byteFile.byteArray)
|
2023-11-11 16:35:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function response_mustHaveExactlyOneFile(res: Response): void {
|
|
|
|
res.status(400).send([
|
|
|
|
{
|
|
|
|
"message": "file is required",
|
|
|
|
"path": [
|
|
|
|
"pdfFile"
|
|
|
|
],
|
|
|
|
"type": "file",
|
|
|
|
"context": {
|
|
|
|
"label": "pdfFile",
|
|
|
|
"key": "pdfFile"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
}
|