fix(client): remove auto-upload of data uri (#73)

This commit is contained in:
Daniel Rochetti 2024-07-11 08:49:14 -07:00 committed by GitHub
parent ab210d9da4
commit cf300e9cc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 30 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "@fal-ai/serverless-client", "name": "@fal-ai/serverless-client",
"description": "The fal serverless JS/TS client", "description": "The fal serverless JS/TS client",
"version": "0.13.0-alpha.0", "version": "0.13.0",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -29,11 +29,9 @@ type RunOptions<Input> = {
/** /**
* If `true`, the function will automatically upload any files * 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 * This is enabled by default. You can disable it by setting it to `false`.
* is useful in cases where you want to upload the files yourself
* or use small data:uri in the input.
*/ */
readonly autoUpload?: boolean; readonly autoUpload?: boolean;
}; };
@ -241,6 +239,8 @@ type QueueSubscribeOptions = {
/** /**
* The interval (in milliseconds) at which to poll for updates. * The interval (in milliseconds) at which to poll for updates.
* If not provided, a default value of `500` will be used. * If not provided, a default value of `500` will be used.
*
* This value is ignored if `mode` is set to `streaming`.
*/ */
pollInterval?: number; pollInterval?: number;
} }

View File

@ -28,19 +28,6 @@ export interface StorageSupport {
transformInput: (input: Record<string, any>) => Promise<Record<string, any>>; transformInput: (input: Record<string, any>) => Promise<Record<string, any>>;
} }
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 = { type InitiateUploadResult = {
file_url: string; file_url: string;
upload_url: string; upload_url: string;
@ -106,18 +93,8 @@ export const storageImpl: StorageSupport = {
transformInput: async (input: any): Promise<any> => { transformInput: async (input: any): Promise<any> => {
if (Array.isArray(input)) { if (Array.isArray(input)) {
return Promise.all(input.map((item) => storageImpl.transformInput(item))); return Promise.all(input.map((item) => storageImpl.transformInput(item)));
} else if ( } else if (input instanceof Blob) {
input instanceof Blob || return await storageImpl.upload(input);
(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 (isPlainObject(input)) { } else if (isPlainObject(input)) {
const inputObject = input as Record<string, any>; const inputObject = input as Record<string, any>;
const promises = Object.entries(inputObject).map( const promises = Object.entries(inputObject).map(