Files
Compass/_old/lib/client/media.tsx
MartinBraquet 14c12ffb08 Rename
2025-09-18 11:19:09 +02:00

24 lines
534 B
TypeScript

'use client';
export async function parseImage(img: string, setImage: any, batch = false) {
if (!img) {
return;
}
let url = img;
if (!img.startsWith('http')) {
const imageResponse = await fetch(`/api/download?key=${img}`);
console.log(`imageResponse: ${imageResponse}`)
if (imageResponse.ok) {
const imageBlob = await imageResponse.json();
url = imageBlob['url'];
}
}
if (url) {
if (batch) {
setImage((prev: any) => [...prev, url]);
} else {
setImage(url);
}
}
}