MCPcopy
hub / github.com/pingdotgg/uploadthing / typedUploadFiles

Function typedUploadFiles

packages/uploadthing/src/client.ts:259–288  ·  view source on GitHub ↗
(
    slug: EndpointArg<TRouter, TEndpoint>,
    opts: Omit<
      UploadFilesOptions<TRouter[TEndpoint]>,
      keyof GenerateUploaderOptions
    >,
  )

Source from the content-addressed store, hash-verified

257 * and then uploads the files to UploadThing
258 */
259 const typedUploadFiles = <TEndpoint extends keyof TRouter>(
260 slug: EndpointArg<TRouter, TEndpoint>,
261 opts: Omit<
262 UploadFilesOptions<TRouter[TEndpoint]>,
263 keyof GenerateUploaderOptions
264 >,
265 ) => {
266 const endpoint = typeof slug === "function" ? slug(routeRegistry) : slug;
267 const fetchFn: FetchEsque = initOpts?.fetch ?? window.fetch;
268
269 return uploadFilesInternal<TRouter, TEndpoint>(endpoint, {
270 ...opts,
271 skipPolling: {} as never, // Remove in a future version, it's type right not is an ErrorMessage<T> to help migrations.
272 url: resolveMaybeUrlArg(initOpts?.url),
273 package: initOpts?.package ?? "uploadthing/client",
274 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
275 input: (opts as any).input as inferEndpointInput<TRouter[TEndpoint]>,
276 })
277 .pipe(Micro.provideService(FetchContext, fetchFn), (effect) =>
278 Micro.runPromiseExit(effect, opts.signal && { signal: opts.signal }),
279 )
280 .then((exit) => {
281 if (exit._tag === "Success") {
282 return exit.value;
283 } else if (exit.cause._tag === "Interrupt") {
284 throw new UploadAbortedError();
285 }
286 throw Micro.causeSquash(exit.cause);
287 });
288 };
289
290 return {
291 uploadFiles: typedUploadFiles,

Callers

nothing calls this directly

Calls 2

uploadFilesInternalFunction · 0.90
resolveMaybeUrlArgFunction · 0.90

Tested by

no test coverage detected