mirror of
https://github.com/documenso/documenso.git
synced 2026-07-27 02:15:05 +10:00
fix: refactors
This commit is contained in:
@@ -51,10 +51,6 @@ route.get(
|
||||
return c.json({ error: 'Not found' }, 404);
|
||||
}
|
||||
|
||||
// We can hard cache this since since it's a unique URL for a given recipient.
|
||||
// Might be dicey if the handler returns a cacheable error code.
|
||||
c.header('Cache-Control', 'public, max-age=31536000, immutable');
|
||||
|
||||
return await handleEnvelopeItemPageRequest({
|
||||
c,
|
||||
envelopeItem,
|
||||
|
||||
@@ -133,16 +133,17 @@ export const handleEnvelopeItemPageRequest = async ({
|
||||
const documentDataToUse =
|
||||
version === 'current' ? envelopeItem.documentData.data : envelopeItem.documentData.initialData;
|
||||
|
||||
c.header('Content-Type', 'image/jpeg');
|
||||
c.header('Cache-Control', `${cacheStrategy}, max-age=31536000, immutable`);
|
||||
|
||||
// Return the image if it already exists in S3.
|
||||
if (envelopeItem.documentData.type === 'S3_PATH') {
|
||||
const s3Key = getEnvelopeItemPageImageS3Key(documentDataToUse, pageIndex);
|
||||
|
||||
const image = await UNSAFE_getS3File(s3Key);
|
||||
const image = await UNSAFE_getS3File(s3Key).catch(() => null);
|
||||
|
||||
if (image) {
|
||||
// Note: Only set these headers on success.
|
||||
c.header('Content-Type', 'image/jpeg');
|
||||
c.header('Cache-Control', `${cacheStrategy}, max-age=31536000, immutable`);
|
||||
|
||||
return c.body(image);
|
||||
}
|
||||
}
|
||||
@@ -169,6 +170,10 @@ export const handleEnvelopeItemPageRequest = async ({
|
||||
return c.json({ error: 'Failed to render page to image' }, 500);
|
||||
}
|
||||
|
||||
// Note: Only set these headers on success.
|
||||
c.header('Content-Type', 'image/jpeg');
|
||||
c.header('Cache-Control', `${cacheStrategy}, max-age=31536000, immutable`);
|
||||
|
||||
return c.body(image);
|
||||
};
|
||||
|
||||
|
||||
@@ -110,12 +110,10 @@ export const handleEnvelopeItemsMetaRequest = async ({
|
||||
const pdfPageMetadata: TDocumentDataMeta['pages'] = await extractAndStorePdfImages(
|
||||
new Uint8Array(pdfBytes).buffer,
|
||||
item.documentData.id,
|
||||
item.documentData.type,
|
||||
);
|
||||
|
||||
pageMetadata = {
|
||||
pages: pdfPageMetadata,
|
||||
documentDataType: item.documentData.type,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user