Skip to content

Commit 09d512b

Browse files
committed
chore(webview): add image utils for size estimation and 10MB limit enforcement [TS.image.ts](webview-ui/src/utils/image.ts:1)
1 parent 1c7700e commit 09d512b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

webview-ui/src/utils/image.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Utilities for image handling in webview.
3+
*/
4+
export const MAX_IMAGE_BYTES = 10 * 1024 * 1024
5+
6+
/**
7+
* Estimate raw bytes from a base64 data URL. Returns 0 for invalid input.
8+
*/
9+
export function estimateBytesFromBase64DataUrl(dataUrl: string): number {
10+
if (typeof dataUrl !== "string") return 0
11+
const idx = dataUrl.indexOf(",")
12+
if (idx === -1) return 0
13+
const base64 = dataUrl.slice(idx + 1).replace(/=+$/, "")
14+
// 4 base64 chars represent 3 bytes
15+
return Math.floor((base64.length * 3) / 4)
16+
}

0 commit comments

Comments
 (0)