2023-09-21 00:51:02 +00:00
|
|
|
import { createOrGetShareLink } from '@documenso/lib/server-only/share/create-or-get-share-link';
|
|
|
|
|
|
|
|
|
|
import { procedure, router } from '../trpc';
|
|
|
|
|
import { ZCreateOrGetShareLinkMutationSchema } from './schema';
|
|
|
|
|
|
|
|
|
|
export const shareLinkRouter = router({
|
|
|
|
|
createOrGetShareLink: procedure
|
|
|
|
|
.input(ZCreateOrGetShareLinkMutationSchema)
|
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
2024-12-06 16:01:24 +09:00
|
|
|
const { documentId, token } = input;
|
2023-09-21 00:51:02 +00:00
|
|
|
|
2024-12-06 16:01:24 +09:00
|
|
|
if (token) {
|
|
|
|
|
return await createOrGetShareLink({ documentId, token });
|
|
|
|
|
}
|
2023-09-21 00:51:02 +00:00
|
|
|
|
2024-12-06 16:01:24 +09:00
|
|
|
if (!ctx.user?.id) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'You must either provide a token or be logged in to create a sharing link.',
|
|
|
|
|
);
|
2023-09-21 00:51:02 +00:00
|
|
|
}
|
2024-12-06 16:01:24 +09:00
|
|
|
|
|
|
|
|
return await createOrGetShareLink({ documentId, userId: ctx.user.id });
|
2023-09-21 00:51:02 +00:00
|
|
|
}),
|
|
|
|
|
});
|