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 +1 -1
- package/src/ai-sdk/providers/fal.ts +10 -2
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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> {
|