mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
feat: allow multipart requests for public api
Adds support for multipart/form-data requests in the public api allowing documents to be uploaded without having to perform a secondary request. Need to rollout further endpoints for envelopes and templates. Need to change how we store files to not use `putFileServerSide`
This commit is contained in:
@ -1,17 +1,23 @@
|
||||
import { createTRPCClient, httpBatchLink, httpLink, splitLink } from '@trpc/client';
|
||||
import SuperJSON from 'superjson';
|
||||
import {
|
||||
createTRPCClient,
|
||||
httpBatchLink,
|
||||
httpLink,
|
||||
isNonJsonSerializable,
|
||||
splitLink,
|
||||
} from '@trpc/client';
|
||||
|
||||
import { getBaseUrl } from '@documenso/lib/universal/get-base-url';
|
||||
|
||||
import type { AppRouter } from '../server/router';
|
||||
import { dataTransformer } from '../utils/data-transformer';
|
||||
|
||||
export const trpc = createTRPCClient<AppRouter>({
|
||||
links: [
|
||||
splitLink({
|
||||
condition: (op) => op.context.skipBatch === true,
|
||||
condition: (op) => op.context.skipBatch === true || isNonJsonSerializable(op.input),
|
||||
true: httpLink({
|
||||
url: `${getBaseUrl()}/api/trpc`,
|
||||
transformer: SuperJSON,
|
||||
transformer: dataTransformer,
|
||||
headers: (opts) => {
|
||||
if (typeof opts.op.context.teamId === 'string') {
|
||||
return {
|
||||
@ -24,7 +30,7 @@ export const trpc = createTRPCClient<AppRouter>({
|
||||
}),
|
||||
false: httpBatchLink({
|
||||
url: `${getBaseUrl()}/api/trpc`,
|
||||
transformer: SuperJSON,
|
||||
transformer: dataTransformer,
|
||||
headers: (opts) => {
|
||||
const operationWithTeamId = opts.opList.find(
|
||||
(op) => op.context.teamId && typeof op.context.teamId === 'string',
|
||||
|
||||
Reference in New Issue
Block a user