mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 16:02:37 +00:00
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
export const CLIPBOARD_IMAGE_MAX_BASE64_CHARS = 24 * 1024 * 1024
|
|
export const CLIPBOARD_IMAGE_MAX_SOURCE_BYTES = Math.floor(
|
|
(CLIPBOARD_IMAGE_MAX_BASE64_CHARS / 4) * 3
|
|
)
|
|
export const CLIPBOARD_IMAGE_MAX_PIXELS = 32 * 1024 * 1024
|
|
export const CLIPBOARD_IMAGE_TOO_LARGE_ERROR = 'Clipboard image is too large'
|
|
|
|
export type ClipboardImageDimensions = {
|
|
height: number
|
|
width: number
|
|
}
|
|
|
|
export function assertClipboardImageBase64LengthWithinLimit(length: number): void {
|
|
if (!Number.isFinite(length) || length > CLIPBOARD_IMAGE_MAX_BASE64_CHARS) {
|
|
throw new Error(CLIPBOARD_IMAGE_TOO_LARGE_ERROR)
|
|
}
|
|
}
|
|
|
|
export function assertClipboardImageByteLengthWithinLimit(byteLength: number): void {
|
|
if (!Number.isFinite(byteLength) || byteLength > CLIPBOARD_IMAGE_MAX_SOURCE_BYTES) {
|
|
throw new Error(CLIPBOARD_IMAGE_TOO_LARGE_ERROR)
|
|
}
|
|
}
|
|
|
|
export function assertClipboardImageDimensionsWithinLimit({
|
|
height,
|
|
width
|
|
}: ClipboardImageDimensions): void {
|
|
const pixelCount = width * height
|
|
if (
|
|
!Number.isFinite(pixelCount) ||
|
|
width <= 0 ||
|
|
height <= 0 ||
|
|
pixelCount > CLIPBOARD_IMAGE_MAX_PIXELS
|
|
) {
|
|
throw new Error(CLIPBOARD_IMAGE_TOO_LARGE_ERROR)
|
|
}
|
|
}
|