mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-06 08:18:39 +00:00
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:
parent
1c7700eb69
commit
09d512b1e5
1 changed files with 16 additions and 0 deletions
16
webview-ui/src/utils/image.ts
Normal file
16
webview-ui/src/utils/image.ts
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue