Adding LibreOffice conversion support (WIP)

This commit is contained in:
Saud Fatayerji
2023-11-13 02:46:50 +03:00
parent c7dd18695d
commit e625a415fd
18 changed files with 659 additions and 104 deletions

View File

@@ -2,14 +2,18 @@
import { Response } from 'express';
import { PdfFile } from '@stirling-pdf/shared-operations/wrappers/PdfFile'
export async function respondWithFile(res: Response, bytes: Uint8Array, name: string, mimeType: string): Promise<void> {
res.writeHead(200, {
'Content-Type': mimeType,
'Content-disposition': 'attachment;filename=' + name,
'Content-Length': bytes.length
});
res.end(bytes);
}
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=' + byteFile.filename,
'Content-Length': byteFile.byteArray?.length
});
res.end(byteFile.byteArray)
respondWithFile(res, byteFile.byteArray!, byteFile.filename, "application/pdf");
}
export function response_mustHaveExactlyOneFile(res: Response): void {
@@ -27,3 +31,12 @@ export function response_mustHaveExactlyOneFile(res: Response): void {
}
]);
}
export function response_dependencyNotConfigured(res: Response, dependencyName: string): void {
res.status(400).send([
{
"message": `${dependencyName} is not configured correctly on the server.`,
"type": "dependency_error",
}
]);
}