Setup project correctly for development and release
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import { fetch } from 'undici'; // Node ≥18 has global fetch; otherwise add undici
|
||||
|
||||
export async function fetchAndEncode(url: string) {
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error(`Failed to fetch image: ${url}`);
|
||||
const buf = Buffer.from(await res.arrayBuffer());
|
||||
const mimeType = res.headers.get('content-type') || 'image/png';
|
||||
const mimeType = res.headers.get('content-type') ?? 'image/png';
|
||||
return { mimeType, data: buf.toString('base64') };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user