mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 03:32:14 +10:00
42 lines
991 B
TypeScript
42 lines
991 B
TypeScript
import type { DocumentData } from '@documenso/prisma/client';
|
|
|
|
import { getFile } from '../universal/upload/get-file';
|
|
import { downloadFile } from './download-file';
|
|
|
|
type DownloadPDFProps = {
|
|
documentData: DocumentData;
|
|
fileName?: string;
|
|
includeCertificate?: boolean;
|
|
includeAuditLog?: boolean;
|
|
};
|
|
|
|
export const downloadPDF = async ({
|
|
documentData,
|
|
fileName,
|
|
includeCertificate,
|
|
includeAuditLog,
|
|
}: DownloadPDFProps) => {
|
|
const bytes = await getFile(documentData);
|
|
|
|
const blob = new Blob([bytes], {
|
|
type: 'application/pdf',
|
|
});
|
|
|
|
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}${suffix}.pdf`,
|
|
data: blob,
|
|
});
|
|
};
|