chore(webview): add image utils for size estimation and 10MB limit enforcement [TS.image.ts](webview-ui/src/utils/image.ts:1)

This commit is contained in:
daniel-lxs 2025-10-28 13:09:17 -05:00
parent 1c7700eb69
commit 09d512b1e5
No known key found for this signature in database
GPG key ID: 21C74479048B3AA6

View file

@ -0,0 +1,16 @@
/**
* Utilities for image handling in webview.
*/
export const MAX_IMAGE_BYTES = 10 * 1024 * 1024
/**
* Estimate raw bytes from a base64 data URL. Returns 0 for invalid input.
*/
export function estimateBytesFromBase64DataUrl(dataUrl: string): number {
if (typeof dataUrl !== "string") return 0
const idx = dataUrl.indexOf(",")
if (idx === -1) return 0
const base64 = dataUrl.slice(idx + 1).replace(/=+$/, "")
// 4 base64 chars represent 3 bytes
return Math.floor((base64.length * 3) / 4)
}