vargai 0.4.0-alpha43 → 0.4.0-alpha44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -69,7 +69,7 @@
69
69
  "sharp": "^0.34.5",
70
70
  "zod": "^4.2.1"
71
71
  },
72
- "version": "0.4.0-alpha43",
72
+ "version": "0.4.0-alpha44",
73
73
  "exports": {
74
74
  ".": "./src/index.ts",
75
75
  "./ai": "./src/ai-sdk/index.ts",
@@ -183,6 +183,8 @@ function detectImageType(bytes: Uint8Array): string | undefined {
183
183
  return undefined;
184
184
  }
185
185
 
186
+ const uploadCache = fileCache({ dir: ".cache/fal-uploads" });
187
+
186
188
  async function fileToUrl(file: ImageModelV3File): Promise<string> {
187
189
  if (file.type === "url") return file.url;
188
190
  const data = file.data;
@@ -190,9 +192,15 @@ async function fileToUrl(file: ImageModelV3File): Promise<string> {
190
192
  typeof data === "string"
191
193
  ? Uint8Array.from(atob(data), (c) => c.charCodeAt(0))
192
194
  : data;
193
- // Use mediaType from file if available, otherwise detect from bytes or default to png
195
+
196
+ const hash = Bun.hash(bytes).toString(16);
197
+ const cached = (await uploadCache.get(hash)) as string | undefined;
198
+ if (cached) return cached;
199
+
194
200
  const mediaType = file.mediaType ?? detectImageType(bytes) ?? "image/png";
195
- return fal.storage.upload(new Blob([bytes], { type: mediaType }));
201
+ const url = await fal.storage.upload(new Blob([bytes], { type: mediaType }));
202
+ await uploadCache.set(hash, url, 7 * 24 * 60 * 60 * 1000);
203
+ return url;
196
204
  }
197
205
 
198
206
  async function uploadBuffer(buffer: ArrayBuffer): Promise<string> {