mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
feat: move opengraph-image to next.js 13 implementation
This commit is contained in:
committed by
Mythie
parent
57ff77b920
commit
794e575ae9
@ -1,30 +1,38 @@
|
|||||||
import { ImageResponse, NextRequest } from 'next/server';
|
import { ImageResponse } from 'next/server';
|
||||||
|
|
||||||
export const config = {
|
export const runtime = 'edge';
|
||||||
runtime: 'edge',
|
|
||||||
};
|
|
||||||
|
|
||||||
const CARD_OFFSET_TOP = 152;
|
const CARD_OFFSET_TOP = 152;
|
||||||
const CARD_OFFSET_LEFT = 350;
|
const CARD_OFFSET_LEFT = 350;
|
||||||
const CARD_WIDTH = 500;
|
const CARD_WIDTH = 500;
|
||||||
const CARD_HEIGHT = 250;
|
const CARD_HEIGHT = 250;
|
||||||
|
|
||||||
export default async function handler(req: NextRequest) {
|
const size = {
|
||||||
const { searchParams } = new URL(req.url);
|
width: 1200,
|
||||||
|
height: 630,
|
||||||
|
};
|
||||||
|
|
||||||
const signature = searchParams.get('signature') || 'Timur';
|
type SharePageOpenGraphImageProps = {
|
||||||
|
params: { shareId: 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 });
|
||||||
|
|
||||||
|
const signature = shareId;
|
||||||
|
|
||||||
const [interSemiBold, interRegular, caveatRegular, shareFrameImage] = await Promise.all([
|
const [interSemiBold, interRegular, caveatRegular, shareFrameImage] = await Promise.all([
|
||||||
fetch(new URL('./../../../assets/inter-semibold.ttf', import.meta.url)).then(async (res) =>
|
fetch(new URL('./../../../../assets/inter-semibold.ttf', import.meta.url)).then(async (res) =>
|
||||||
res.arrayBuffer(),
|
res.arrayBuffer(),
|
||||||
),
|
),
|
||||||
fetch(new URL('./../../../assets/inter-regular.ttf', import.meta.url)).then(async (res) =>
|
fetch(new URL('./../../../../assets/inter-regular.ttf', import.meta.url)).then(async (res) =>
|
||||||
res.arrayBuffer(),
|
res.arrayBuffer(),
|
||||||
),
|
),
|
||||||
fetch(new URL('./../../../assets/caveat-regular.ttf', import.meta.url)).then(async (res) =>
|
fetch(new URL('./../../../../assets/caveat-regular.ttf', import.meta.url)).then(async (res) =>
|
||||||
res.arrayBuffer(),
|
res.arrayBuffer(),
|
||||||
),
|
),
|
||||||
fetch(new URL('./../../../assets/og-share-frame.png', import.meta.url)).then(async (res) =>
|
fetch(new URL('./../../../../assets/og-share-frame.png', import.meta.url)).then(async (res) =>
|
||||||
res.arrayBuffer(),
|
res.arrayBuffer(),
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
@ -68,8 +76,7 @@ export default async function handler(req: NextRequest) {
|
|||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
{
|
{
|
||||||
width: 1200,
|
...size,
|
||||||
height: 630,
|
|
||||||
fonts: [
|
fonts: [
|
||||||
{
|
{
|
||||||
name: 'Caveat',
|
name: 'Caveat',
|
||||||
@ -5,7 +5,7 @@ import { notFound } from 'next/navigation';
|
|||||||
|
|
||||||
import { getSharingId } from '@documenso/lib/server-only/share/get-share-id';
|
import { getSharingId } from '@documenso/lib/server-only/share/get-share-id';
|
||||||
|
|
||||||
import Redirect from './redirect';
|
// import Redirect from './redirect';
|
||||||
|
|
||||||
type MetadataProps = {
|
type MetadataProps = {
|
||||||
params: { shareId: string };
|
params: { shareId: string };
|
||||||
@ -18,9 +18,6 @@ export async function generateMetadata({ params }: MetadataProps): Promise<Metad
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
title: 'Documenso - Share',
|
title: 'Documenso - Share',
|
||||||
openGraph: {
|
|
||||||
images: [`/api/share-og?signature=${signature}`],
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +42,7 @@ export default async function SharePage({ params: { shareId } }: SharePageProps)
|
|||||||
<div className="flex h-screen flex-col items-center justify-center">
|
<div className="flex h-screen flex-col items-center justify-center">
|
||||||
<h1 className="my-2 text-4xl font-semibold">Share Page</h1>
|
<h1 className="my-2 text-4xl font-semibold">Share Page</h1>
|
||||||
<p className="my-2 text-xl">Redirecting...</p>
|
<p className="my-2 text-xl">Redirecting...</p>
|
||||||
<Redirect />
|
{/* <Redirect /> */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
import { TRPCError } from '@trpc/server';
|
import { TRPCError } from '@trpc/server';
|
||||||
|
|
||||||
import { createSharingId } from '@documenso/lib/server-only/share/create-share-id';
|
import { createSharingId } from '@documenso/lib/server-only/share/create-share-id';
|
||||||
|
import { getSharingId } from '@documenso/lib/server-only/share/get-share-id';
|
||||||
|
|
||||||
import { procedure, router } from '../trpc';
|
import { procedure, router } from '../trpc';
|
||||||
import { ZShareLinkSchema } from './schema';
|
import { ZShareLinkCreateSchema, ZShareLinkGetSchema } from './schema';
|
||||||
|
|
||||||
export const shareRouter = router({
|
export const shareRouter = router({
|
||||||
create: procedure.input(ZShareLinkSchema).mutation(async ({ input }) => {
|
create: procedure.input(ZShareLinkCreateSchema).mutation(async ({ input }) => {
|
||||||
try {
|
try {
|
||||||
const { documentId, recipientId } = input;
|
const { documentId, recipientId } = input;
|
||||||
|
|
||||||
@ -14,6 +15,20 @@ export const shareRouter = router({
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
||||||
|
throw new TRPCError({
|
||||||
|
code: 'BAD_REQUEST',
|
||||||
|
message: 'We were unable to create a sharing link.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
get: procedure.input(ZShareLinkGetSchema).query(async ({ input }) => {
|
||||||
|
try {
|
||||||
|
const { shareId } = input;
|
||||||
|
|
||||||
|
return await getSharingId({ shareId });
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: 'BAD_REQUEST',
|
code: 'BAD_REQUEST',
|
||||||
message: 'We were unable to create a sharing link.',
|
message: 'We were unable to create a sharing link.',
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const ZShareLinkSchema = z.object({
|
export const ZShareLinkCreateSchema = z.object({
|
||||||
documentId: z.number(),
|
documentId: z.number(),
|
||||||
recipientId: z.number(),
|
recipientId: z.number(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ZShareLinkSchema = z.infer<typeof ZShareLinkSchema>;
|
export const ZShareLinkGetSchema = z.object({
|
||||||
|
shareId: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ZShareLinkCreateSchema = z.infer<typeof ZShareLinkCreateSchema>;
|
||||||
|
export type ZShareLinkGetSchema = z.infer<typeof ZShareLinkGetSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user