52 lines
1.2 KiB
TypeScript
Executable file
52 lines
1.2 KiB
TypeScript
Executable file
/**
|
|
* @lilith/image-security/validation
|
|
*
|
|
* Browser-safe image validation functions.
|
|
* This subpath export has no Node.js or NestJS dependencies,
|
|
* making it suitable for use in frontend applications.
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* import {
|
|
* validateImageBytes,
|
|
* isAllowedMimeType,
|
|
* isValidFileSize,
|
|
* formatFileSize,
|
|
* } from '@lilith/image-security/validation'
|
|
*
|
|
* // Validate a file before upload
|
|
* const file = inputEl.files[0]
|
|
* if (!isValidFileSize(file.size)) {
|
|
* alert(`File too large. Max: ${formatFileSize(5 * 1024 * 1024)}`)
|
|
* return
|
|
* }
|
|
*
|
|
* const bytes = new Uint8Array(await file.slice(0, 12).arrayBuffer())
|
|
* const result = validateImageBytes(bytes, file.type)
|
|
* if (!result.valid) {
|
|
* alert(result.error)
|
|
* return
|
|
* }
|
|
* ```
|
|
*/
|
|
|
|
// Re-export types needed for validation
|
|
export {
|
|
ALLOWED_IMAGE_MIME_TYPES,
|
|
IMAGE_MAGIC_BYTES,
|
|
DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
DEFAULT_MAX_IMAGES_PER_BATCH,
|
|
ImageSecurityStatus,
|
|
type AllowedImageMimeType,
|
|
type ImageValidationResult,
|
|
} from '../types'
|
|
|
|
// Export validation functions
|
|
export {
|
|
isAllowedMimeType,
|
|
isValidFileSize,
|
|
validateMagicBytes,
|
|
detectMimeTypeFromBytes,
|
|
validateImageBytes,
|
|
formatFileSize,
|
|
} from './image-validator'
|