mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 11:41:44 +10:00
feat: download options for document
This commit is contained in:
@ -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,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user