From cf300e9cc0d65ab999a506f07e3806e239d4d3d9 Mon Sep 17 00:00:00 2001 From: Daniel Rochetti Date: Thu, 11 Jul 2024 08:49:14 -0700 Subject: [PATCH] fix(client): remove auto-upload of data uri (#73) --- libs/client/package.json | 2 +- libs/client/src/function.ts | 8 ++++---- libs/client/src/storage.ts | 27 ++------------------------- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/libs/client/package.json b/libs/client/package.json index 77e0dbd..608083e 100644 --- a/libs/client/package.json +++ b/libs/client/package.json @@ -1,7 +1,7 @@ { "name": "@fal-ai/serverless-client", "description": "The fal serverless JS/TS client", - "version": "0.13.0-alpha.0", + "version": "0.13.0", "license": "MIT", "repository": { "type": "git", diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts index 019ad44..e74e8d9 100644 --- a/libs/client/src/function.ts +++ b/libs/client/src/function.ts @@ -29,11 +29,9 @@ type RunOptions = { /** * If `true`, the function will automatically upload any files - * (i.e. instances of `Blob`) or data:uri in the input. + * (i.e. instances of `Blob`). * - * You can disable this behavior by setting it to `false`, which - * is useful in cases where you want to upload the files yourself - * or use small data:uri in the input. + * This is enabled by default. You can disable it by setting it to `false`. */ readonly autoUpload?: boolean; }; @@ -241,6 +239,8 @@ type QueueSubscribeOptions = { /** * The interval (in milliseconds) at which to poll for updates. * If not provided, a default value of `500` will be used. + * + * This value is ignored if `mode` is set to `streaming`. */ pollInterval?: number; } diff --git a/libs/client/src/storage.ts b/libs/client/src/storage.ts index 8c3e213..1388823 100644 --- a/libs/client/src/storage.ts +++ b/libs/client/src/storage.ts @@ -28,19 +28,6 @@ export interface StorageSupport { transformInput: (input: Record) => Promise>; } -function isDataUri(uri: string): boolean { - // avoid uri parsing if it doesn't start with data: - if (!uri.startsWith('data:')) { - return false; - } - try { - const url = new URL(uri); - return url.protocol === 'data:'; - } catch (_) { - return false; - } -} - type InitiateUploadResult = { file_url: string; upload_url: string; @@ -106,18 +93,8 @@ export const storageImpl: StorageSupport = { transformInput: async (input: any): Promise => { if (Array.isArray(input)) { return Promise.all(input.map((item) => storageImpl.transformInput(item))); - } else if ( - input instanceof Blob || - (typeof input === 'string' && isDataUri(input)) - ) { - let blob = input; - // If the string is a data URI, convert it to a blob - if (typeof input === 'string' && isDataUri(input)) { - const response = await fetch(input); - blob = await response.blob(); - } - const url = await storageImpl.upload(blob as Blob); - return url; + } else if (input instanceof Blob) { + return await storageImpl.upload(input); } else if (isPlainObject(input)) { const inputObject = input as Record; const promises = Object.entries(inputObject).map(