mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
feat: certificate qrcode (#1755)
Adds document access tokens and QR code functionality to enable secure document sharing via URLs. It includes a new document access page that allows viewing and downloading documents through tokenized links.
This commit is contained in:
@ -0,0 +1,61 @@
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { procedure } from '../trpc';
|
||||
import {
|
||||
ZGetDocumentInternalUrlForQRCodeInput,
|
||||
ZGetDocumentInternalUrlForQRCodeOutput,
|
||||
} from './get-document-internal-url-for-qr-code.types';
|
||||
|
||||
export const getDocumentInternalUrlForQRCodeRoute = procedure
|
||||
.input(ZGetDocumentInternalUrlForQRCodeInput)
|
||||
.output(ZGetDocumentInternalUrlForQRCodeOutput)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { documentId } = input;
|
||||
|
||||
if (!ctx.user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const document = await prisma.document.findFirst({
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
id: documentId,
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
{
|
||||
id: documentId,
|
||||
team: {
|
||||
members: {
|
||||
some: {
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
include: {
|
||||
team: {
|
||||
where: {
|
||||
members: {
|
||||
some: {
|
||||
userId: ctx.user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (document.team) {
|
||||
return `${NEXT_PUBLIC_WEBAPP_URL()}/t/${document.team.url}/documents/${document.id}`;
|
||||
}
|
||||
|
||||
return `${NEXT_PUBLIC_WEBAPP_URL()}/documents/${document.id}`;
|
||||
});
|
||||
@ -0,0 +1,15 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZGetDocumentInternalUrlForQRCodeInput = z.object({
|
||||
documentId: z.number(),
|
||||
});
|
||||
|
||||
export type TGetDocumentInternalUrlForQRCodeInput = z.infer<
|
||||
typeof ZGetDocumentInternalUrlForQRCodeInput
|
||||
>;
|
||||
|
||||
export const ZGetDocumentInternalUrlForQRCodeOutput = z.string().nullable();
|
||||
|
||||
export type TGetDocumentInternalUrlForQRCodeOutput = z.infer<
|
||||
typeof ZGetDocumentInternalUrlForQRCodeOutput
|
||||
>;
|
||||
@ -1,6 +1,7 @@
|
||||
import { createOrGetShareLink } from '@documenso/lib/server-only/share/create-or-get-share-link';
|
||||
|
||||
import { procedure, router } from '../trpc';
|
||||
import { getDocumentInternalUrlForQRCodeRoute } from './get-document-internal-url-for-qr-code';
|
||||
import { ZCreateOrGetShareLinkMutationSchema } from './schema';
|
||||
|
||||
export const shareLinkRouter = router({
|
||||
@ -21,4 +22,6 @@ export const shareLinkRouter = router({
|
||||
|
||||
return await createOrGetShareLink({ documentId, userId: ctx.user.id });
|
||||
}),
|
||||
|
||||
getDocumentInternalUrlForQRCode: getDocumentInternalUrlForQRCodeRoute,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user