mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import type { EnvelopeItem } from '@prisma/client';
|
|
|
|
import { NEXT_PUBLIC_WEBAPP_URL } from '../constants/app';
|
|
|
|
export type EnvelopeItemPdfUrlOptions =
|
|
| {
|
|
type: 'download';
|
|
envelopeItem: Pick<EnvelopeItem, 'id' | 'envelopeId'>;
|
|
token: string | undefined;
|
|
version: 'original' | 'signed';
|
|
}
|
|
| {
|
|
type: 'view';
|
|
envelopeItem: Pick<EnvelopeItem, 'id' | 'envelopeId'>;
|
|
token: string | undefined;
|
|
};
|
|
|
|
export const getEnvelopeItemPdfUrl = (options: EnvelopeItemPdfUrlOptions) => {
|
|
const { envelopeItem, token, type } = options;
|
|
|
|
const { id, envelopeId } = envelopeItem;
|
|
|
|
if (type === 'download') {
|
|
const version = options.version;
|
|
|
|
return token
|
|
? `${NEXT_PUBLIC_WEBAPP_URL()}/api/files/token/${token}/envelopeItem/${id}/download/${version}`
|
|
: `${NEXT_PUBLIC_WEBAPP_URL()}/api/files/envelope/${envelopeId}/envelopeItem/${id}/download/${version}`;
|
|
}
|
|
|
|
return token
|
|
? `${NEXT_PUBLIC_WEBAPP_URL()}/api/files/token/${token}/envelopeItem/${id}`
|
|
: `${NEXT_PUBLIC_WEBAPP_URL()}/api/files/envelope/${envelopeId}/envelopeItem/${id}`;
|
|
};
|