mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 01:01:49 +10:00
fix: prefill arcoforms with formdata endpoints
This commit is contained in:
@ -7,6 +7,7 @@ import { putPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.s
|
|||||||
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
||||||
import { prisma } from '@documenso/prisma';
|
import { prisma } from '@documenso/prisma';
|
||||||
|
|
||||||
|
import { insertFormValuesInPdf } from '../../../lib/server-only/pdf/insert-form-values-in-pdf';
|
||||||
import { authenticatedProcedure } from '../trpc';
|
import { authenticatedProcedure } from '../trpc';
|
||||||
import {
|
import {
|
||||||
ZCreateDocumentFormDataRequestSchema,
|
ZCreateDocumentFormDataRequestSchema,
|
||||||
@ -38,6 +39,7 @@ export const createDocumentFormDataRoute = authenticatedProcedure
|
|||||||
meta,
|
meta,
|
||||||
folderId,
|
folderId,
|
||||||
attachments,
|
attachments,
|
||||||
|
formValues,
|
||||||
} = payload;
|
} = payload;
|
||||||
|
|
||||||
const { remaining } = await getServerLimits({ userId: user.id, teamId });
|
const { remaining } = await getServerLimits({ userId: user.id, teamId });
|
||||||
@ -49,7 +51,21 @@ export const createDocumentFormDataRoute = authenticatedProcedure
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const documentData = await putPdfFileServerSide(file);
|
let pdf = Buffer.from(await file.arrayBuffer());
|
||||||
|
|
||||||
|
if (formValues) {
|
||||||
|
// eslint-disable-next-line require-atomic-updates
|
||||||
|
pdf = await insertFormValuesInPdf({
|
||||||
|
pdf,
|
||||||
|
formValues,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const documentData = await putPdfFileServerSide({
|
||||||
|
name: file.name,
|
||||||
|
type: 'application/pdf',
|
||||||
|
arrayBuffer: async () => Promise.resolve(pdf),
|
||||||
|
});
|
||||||
|
|
||||||
const createdEnvelope = await createEnvelope({
|
const createdEnvelope = await createEnvelope({
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|||||||
import { createEnvelope } from '@documenso/lib/server-only/envelope/create-envelope';
|
import { createEnvelope } from '@documenso/lib/server-only/envelope/create-envelope';
|
||||||
import { putNormalizedPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
import { putNormalizedPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
||||||
|
|
||||||
|
import { insertFormValuesInPdf } from '../../../lib/server-only/pdf/insert-form-values-in-pdf';
|
||||||
import { authenticatedProcedure } from '../trpc';
|
import { authenticatedProcedure } from '../trpc';
|
||||||
import {
|
import {
|
||||||
ZCreateEnvelopeRequestSchema,
|
ZCreateEnvelopeRequestSchema,
|
||||||
@ -58,10 +59,31 @@ export const createEnvelopeRoute = authenticatedProcedure
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (files.some((file) => !file.type.startsWith('application/pdf'))) {
|
||||||
|
throw new AppError('INVALID_DOCUMENT_FILE', {
|
||||||
|
message: 'You cannot upload non-PDF files',
|
||||||
|
statusCode: 400,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// For each file, stream to s3 and create the document data.
|
// For each file, stream to s3 and create the document data.
|
||||||
const envelopeItems = await Promise.all(
|
const envelopeItems = await Promise.all(
|
||||||
files.map(async (file) => {
|
files.map(async (file) => {
|
||||||
const { id: documentDataId } = await putNormalizedPdfFileServerSide(file);
|
let pdf = Buffer.from(await file.arrayBuffer());
|
||||||
|
|
||||||
|
if (formValues) {
|
||||||
|
// eslint-disable-next-line require-atomic-updates
|
||||||
|
pdf = await insertFormValuesInPdf({
|
||||||
|
pdf,
|
||||||
|
formValues,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id: documentDataId } = await putNormalizedPdfFileServerSide({
|
||||||
|
name: file.name,
|
||||||
|
type: 'application/pdf',
|
||||||
|
arrayBuffer: async () => Promise.resolve(pdf),
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: file.name,
|
title: file.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user