2023-09-05 11:37:21 +00:00
|
|
|
import { ImageResponse } from 'next/server';
|
2023-08-29 14:39:49 +00:00
|
|
|
|
2023-09-21 00:51:02 +00:00
|
|
|
import { P, match } from 'ts-pattern';
|
|
|
|
|
|
|
|
|
|
import { getRecipientOrSenderByShareLinkSlug } from '@documenso/lib/server-only/share/get-recipient-or-sender-by-share-link-slug';
|
|
|
|
|
|
2023-09-05 11:37:21 +00:00
|
|
|
export const runtime = 'edge';
|
2023-08-29 14:39:49 +00:00
|
|
|
|
2023-08-31 15:36:09 +10:00
|
|
|
const CARD_OFFSET_TOP = 152;
|
|
|
|
|
const CARD_OFFSET_LEFT = 350;
|
|
|
|
|
const CARD_WIDTH = 500;
|
|
|
|
|
const CARD_HEIGHT = 250;
|
|
|
|
|
|
2023-09-05 11:37:21 +00:00
|
|
|
const size = {
|
|
|
|
|
width: 1200,
|
|
|
|
|
height: 630,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type SharePageOpenGraphImageProps = {
|
2023-09-21 00:51:02 +00:00
|
|
|
params: { slug: string };
|
2023-09-05 11:37:21 +00:00
|
|
|
};
|
|
|
|
|
|
2023-09-21 00:51:02 +00:00
|
|
|
export default async function Image({ params: { slug } }: SharePageOpenGraphImageProps) {
|
|
|
|
|
const recipientOrSender = await getRecipientOrSenderByShareLinkSlug({ slug }).catch(() => null);
|
|
|
|
|
|
|
|
|
|
if (!recipientOrSender) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const signatureImage = match(recipientOrSender)
|
|
|
|
|
.with({ Signature: P.array(P._) }, (recipient) => {
|
|
|
|
|
return recipient.Signature?.[0]?.signatureImageAsBase64 || null;
|
|
|
|
|
})
|
|
|
|
|
.otherwise((sender) => {
|
|
|
|
|
return sender.signature || null;
|
|
|
|
|
});
|
2023-08-31 15:36:09 +10:00
|
|
|
|
2023-09-21 00:51:02 +00:00
|
|
|
const signatureName = match(recipientOrSender)
|
|
|
|
|
.with({ Signature: P.array(P._) }, (recipient) => {
|
|
|
|
|
return recipient.name || recipient.email;
|
|
|
|
|
})
|
|
|
|
|
.otherwise((sender) => {
|
|
|
|
|
return sender.name || sender.email;
|
|
|
|
|
});
|
2023-08-29 18:46:15 +00:00
|
|
|
|
2023-08-31 15:36:09 +10:00
|
|
|
const [interSemiBold, interRegular, caveatRegular, shareFrameImage] = await Promise.all([
|
2023-09-05 11:37:21 +00:00
|
|
|
fetch(new URL('./../../../../assets/inter-semibold.ttf', import.meta.url)).then(async (res) =>
|
2023-08-29 14:39:49 +00:00
|
|
|
res.arrayBuffer(),
|
|
|
|
|
),
|
2023-09-05 11:37:21 +00:00
|
|
|
fetch(new URL('./../../../../assets/inter-regular.ttf', import.meta.url)).then(async (res) =>
|
2023-08-29 14:39:49 +00:00
|
|
|
res.arrayBuffer(),
|
|
|
|
|
),
|
2023-09-05 11:37:21 +00:00
|
|
|
fetch(new URL('./../../../../assets/caveat-regular.ttf', import.meta.url)).then(async (res) =>
|
2023-08-31 15:36:09 +10:00
|
|
|
res.arrayBuffer(),
|
|
|
|
|
),
|
2023-09-05 11:37:21 +00:00
|
|
|
fetch(new URL('./../../../../assets/og-share-frame.png', import.meta.url)).then(async (res) =>
|
2023-08-29 14:39:49 +00:00
|
|
|
res.arrayBuffer(),
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return new ImageResponse(
|
|
|
|
|
(
|
2023-08-31 15:36:09 +10:00
|
|
|
<div tw="relative flex h-full w-full">
|
|
|
|
|
{/* @ts-expect-error Lack of typing from ImageResponse */}
|
|
|
|
|
<img src={shareFrameImage} alt="og-share-frame" tw="absolute inset-0 w-full h-full" />
|
|
|
|
|
|
2023-09-21 00:51:02 +00:00
|
|
|
{signatureImage ? (
|
|
|
|
|
<div
|
|
|
|
|
tw="absolute py-6 px-12 -mt-2 flex items-center justify-center text-center"
|
|
|
|
|
style={{
|
|
|
|
|
top: `${CARD_OFFSET_TOP}px`,
|
|
|
|
|
left: `${CARD_OFFSET_LEFT}px`,
|
|
|
|
|
width: `${CARD_WIDTH}px`,
|
|
|
|
|
height: `${CARD_HEIGHT}px`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<img src={signatureImage} alt="signature" tw="w-full h-full" />
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<p
|
|
|
|
|
tw="absolute py-6 px-12 -mt-2 flex items-center justify-center text-center"
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: 'Caveat',
|
|
|
|
|
fontSize: `${Math.max(
|
|
|
|
|
Math.min((CARD_WIDTH * 1.5) / signatureName.length, 80),
|
|
|
|
|
36,
|
|
|
|
|
)}px`,
|
|
|
|
|
top: `${CARD_OFFSET_TOP}px`,
|
|
|
|
|
left: `${CARD_OFFSET_LEFT}px`,
|
|
|
|
|
width: `${CARD_WIDTH}px`,
|
|
|
|
|
height: `${CARD_HEIGHT}px`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{signatureName}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
2023-08-31 15:36:09 +10:00
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
tw="absolute absolute flex flex-col items-center justify-center pt-2.5 w-full"
|
|
|
|
|
style={{
|
|
|
|
|
top: `${CARD_OFFSET_TOP + CARD_HEIGHT}px`,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<h2
|
|
|
|
|
tw="text-2xl text-slate-900/60"
|
|
|
|
|
style={{
|
|
|
|
|
fontFamily: 'Inter',
|
|
|
|
|
fontWeight: 600,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
I just signed with Documenso
|
|
|
|
|
</h2>
|
2023-08-29 14:39:49 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
{
|
2023-09-05 11:37:21 +00:00
|
|
|
...size,
|
2023-08-29 14:39:49 +00:00
|
|
|
fonts: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Caveat',
|
2023-08-31 15:36:09 +10:00
|
|
|
data: caveatRegular,
|
2023-08-29 14:39:49 +00:00
|
|
|
style: 'italic',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Inter',
|
2023-08-31 15:36:09 +10:00
|
|
|
data: interRegular,
|
|
|
|
|
style: 'normal',
|
|
|
|
|
weight: 400,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Inter',
|
|
|
|
|
data: interSemiBold,
|
2023-08-29 14:39:49 +00:00
|
|
|
style: 'normal',
|
2023-08-31 15:36:09 +10:00
|
|
|
weight: 600,
|
2023-08-29 14:39:49 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|