UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 991 B
import{o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{n as estimateBase64DecodedBytes}from"./base64-BbBj85Rq.mjs";import{n as formatMediaSize}from"./store.shared-DVFM20XA.mjs"; //!src/media/image-data-url.ts function decodeDataUrl(e,t){const n=e.trim();const r=/^data:([^;,]+)(?:;[^,]*)?;base64,/i.exec(n);const i=r?n.slice(r[0].length):``;if(!r||!i||/[^a-z0-9+/=\r\n]/i.test(i))throw new Error(`Invalid data URL (expected base64 data: URL).`);const a=normalizeLowercaseStringOrEmpty(r[1]);if(!a.startsWith(`image/`))throw new Error(`Unsupported data URL type: ${a||`unknown`}`);const o=estimateBase64DecodedBytes(i);if(typeof t?.maxBytes===`number`&&o>t.maxBytes)throw new Error(`Invalid data URL: payload exceeds size limit (${formatMediaSize(o)}, limit ${formatMediaSize(t.maxBytes)}).`);const s=Buffer.from(i,`base64`);if(s.length===0)throw new Error(`Invalid data URL: empty payload.`);return{buffer:s,mimeType:a,kind:`image`}}export{decodeDataUrl as t};