mirror of
https://github.com/documenso/documenso.git
synced 2025-11-25 06:01:35 +10:00
fix: tidy code and update endpoints
This commit is contained in:
@ -1,5 +1,9 @@
|
||||
import { ImageResponse } from 'next/server';
|
||||
|
||||
import { P, match } from 'ts-pattern';
|
||||
|
||||
import { getRecipientOrSenderByShareLinkSlug } from '@documenso/lib/server-only/share/get-recipient-or-sender-by-share-link-slug';
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
const CARD_OFFSET_TOP = 152;
|
||||
@ -13,14 +17,31 @@ const size = {
|
||||
};
|
||||
|
||||
type SharePageOpenGraphImageProps = {
|
||||
params: { shareId: string };
|
||||
params: { slug: string };
|
||||
};
|
||||
|
||||
export default async function Image({ params: { shareId } }: SharePageOpenGraphImageProps) {
|
||||
// Cannot use trpc here and prisma does not work in the browser so I cannot fetch the client
|
||||
// const { data } = trpc.share.get.useQuery({ shareId });
|
||||
export default async function Image({ params: { slug } }: SharePageOpenGraphImageProps) {
|
||||
const recipientOrSender = await getRecipientOrSenderByShareLinkSlug({ slug }).catch(() => null);
|
||||
|
||||
const signature = shareId;
|
||||
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;
|
||||
});
|
||||
|
||||
const signatureName = match(recipientOrSender)
|
||||
.with({ Signature: P.array(P._) }, (recipient) => {
|
||||
return recipient.name || recipient.email;
|
||||
})
|
||||
.otherwise((sender) => {
|
||||
return sender.name || sender.email;
|
||||
});
|
||||
|
||||
const [interSemiBold, interRegular, caveatRegular, shareFrameImage] = await Promise.all([
|
||||
fetch(new URL('./../../../../assets/inter-semibold.ttf', import.meta.url)).then(async (res) =>
|
||||
@ -43,19 +64,36 @@ export default async function Image({ params: { shareId } }: SharePageOpenGraphI
|
||||
{/* @ts-expect-error Lack of typing from ImageResponse */}
|
||||
<img src={shareFrameImage} alt="og-share-frame" tw="absolute inset-0 w-full h-full" />
|
||||
|
||||
<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) / signature.length, 80), 36)}px`,
|
||||
top: `${CARD_OFFSET_TOP}px`,
|
||||
left: `${CARD_OFFSET_LEFT}px`,
|
||||
width: `${CARD_WIDTH}px`,
|
||||
height: `${CARD_HEIGHT}px`,
|
||||
}}
|
||||
>
|
||||
{signature}
|
||||
</p>
|
||||
{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>
|
||||
)}
|
||||
|
||||
<div
|
||||
tw="absolute absolute flex flex-col items-center justify-center pt-2.5 w-full"
|
||||
@ -3,7 +3,7 @@ import React from 'react';
|
||||
import { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import { getSharingId } from '@documenso/lib/server-only/share/get-share-id';
|
||||
import { getShareLinkBySlug } from '@documenso/lib/server-only/share/get-share-link-by-slug';
|
||||
|
||||
import Redirect from './redirect';
|
||||
|
||||
@ -13,16 +13,16 @@ export const metadata: Metadata = {
|
||||
|
||||
export type SharePageProps = {
|
||||
params: {
|
||||
shareId?: string;
|
||||
slug?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export default async function SharePage({ params: { shareId } }: SharePageProps) {
|
||||
if (!shareId) {
|
||||
export default async function SharePage({ params: { slug } }: SharePageProps) {
|
||||
if (!slug) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const share = await getSharingId({ shareId });
|
||||
const share = await getShareLinkBySlug({ slug }).catch(() => null);
|
||||
|
||||
if (!share) {
|
||||
return notFound();
|
||||
@ -5,15 +5,15 @@ import { useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function Redirect() {
|
||||
const router = useRouter();
|
||||
const { push } = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
router.push('/');
|
||||
push('/');
|
||||
}, 3000);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, []);
|
||||
}, [push]);
|
||||
|
||||
return <div></div>;
|
||||
}
|
||||
Reference in New Issue
Block a user