mirror of
https://github.com/documenso/documenso.git
synced 2026-06-22 04:12:06 +10:00
6faa01d384
## Description Replace the PDF renderer with an custom image renderer. This allows us to remove the "react-pdf" dependency and allows us to use a virtual list to improve performance.
82 lines
2.0 KiB
TypeScript
82 lines
2.0 KiB
TypeScript
import { sValidator } from '@hono/standard-validator';
|
|
import type { Prisma } from '@prisma/client';
|
|
import { Hono } from 'hono';
|
|
import { z } from 'zod';
|
|
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import type { HonoEnv } from '../../../router';
|
|
import { handleEnvelopeItemPdfRequest } from './get-envelope-item-pdf';
|
|
|
|
const route = new Hono<HonoEnv>();
|
|
|
|
const ZGetEnvelopeItemByTokenParamsSchema = z.object({
|
|
token: z.string().min(1),
|
|
envelopeId: z.string().min(1),
|
|
envelopeItemId: z.string().min(1),
|
|
documentDataId: z.string().min(1),
|
|
version: z.enum(['initial', 'current']),
|
|
});
|
|
|
|
/**
|
|
* Returns a PDF file for an envelope item using a token.
|
|
*/
|
|
route.get(
|
|
'/token/:token/envelope/:envelopeId/envelopeItem/:envelopeItemId/dataId/:documentDataId/:version/item.pdf',
|
|
sValidator('param', ZGetEnvelopeItemByTokenParamsSchema),
|
|
async (c) => {
|
|
const { token, envelopeId, envelopeItemId, documentDataId, version } = c.req.valid('param');
|
|
|
|
if (!token) {
|
|
return c.json({ error: 'Not found' }, 404);
|
|
}
|
|
|
|
// Recipient token based query.
|
|
let envelopeItemWhereQuery: Prisma.EnvelopeItemWhereInput = {
|
|
id: envelopeItemId,
|
|
documentDataId,
|
|
envelope: {
|
|
id: envelopeId,
|
|
recipients: {
|
|
some: {
|
|
token,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
// QR token based query.
|
|
if (token.startsWith('qr_')) {
|
|
envelopeItemWhereQuery = {
|
|
id: envelopeItemId,
|
|
documentDataId,
|
|
envelope: {
|
|
id: envelopeId,
|
|
qrToken: token,
|
|
},
|
|
};
|
|
}
|
|
|
|
// Validate envelope access.
|
|
const envelopeItem = await prisma.envelopeItem.findFirst({
|
|
where: envelopeItemWhereQuery,
|
|
include: {
|
|
documentData: true,
|
|
},
|
|
});
|
|
|
|
if (!envelopeItem) {
|
|
return c.json({ error: 'Not found' }, 404);
|
|
}
|
|
|
|
return await handleEnvelopeItemPdfRequest({
|
|
c,
|
|
envelopeItem,
|
|
version,
|
|
cacheStrategy: 'private',
|
|
});
|
|
},
|
|
);
|
|
|
|
export default route;
|