feat: download options for document

This commit is contained in:
Catalin Pit
2025-02-14 16:25:15 +02:00
parent 080bb405f0
commit f6a24224fe
4 changed files with 155 additions and 10 deletions

View File

@ -6,9 +6,16 @@ import { downloadFile } from './download-file';
type DownloadPDFProps = {
documentData: DocumentData;
fileName?: string;
includeCertificate?: boolean;
includeAuditLog?: boolean;
};
export const downloadPDF = async ({ documentData, fileName }: DownloadPDFProps) => {
export const downloadPDF = async ({
documentData,
fileName,
includeCertificate,
includeAuditLog,
}: DownloadPDFProps) => {
const bytes = await getFile(documentData);
const blob = new Blob([bytes], {
@ -17,8 +24,18 @@ export const downloadPDF = async ({ documentData, fileName }: DownloadPDFProps)
const baseTitle = (fileName ?? 'document').replace(/\.pdf$/, '');
let suffix = '_signed';
if (includeCertificate && includeAuditLog) {
suffix = suffix + '_with_certificate_and_audit';
} else if (includeCertificate) {
suffix = suffix + '_with_certificate';
} else if (includeAuditLog) {
suffix = suffix + '_with_audit';
}
downloadFile({
filename: `${baseTitle}_signed.pdf`,
filename: `${baseTitle}${suffix}.pdf`,
data: blob,
});
};