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",
"description": "The fal serverless JS/TS client",
"version": "0.13.0-alpha.0",
"version": "0.13.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@ -29,11 +29,9 @@ type RunOptions<Input> = {
/**
* 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;
}

View File

@ -28,19 +28,6 @@ export interface StorageSupport {
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 = {
file_url: string;
upload_url: string;
@ -106,18 +93,8 @@ export const storageImpl: StorageSupport = {
transformInput: async (input: any): Promise<any> => {
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<string, any>;
const promises = Object.entries(inputObject).map(