TypeScript API / laikacms/sanitizer / Sanitizer
Interface: Sanitizer
Abstract sanitizer interface
Implementations should:
- Throw errors for unsupported file types (unless in ignoreExtensions)
- Throw errors for corrupted files
- Throw errors for files exceeding maxFileSize
- Return sanitized data with metadata about what was stripped
Methods
canSanitize()
ts
canSanitize(data): object;Check if a file can be sanitized (without actually sanitizing it) Useful for validation before upload
Parameters
| Parameter | Type |
|---|---|
data | Uint8Array |
Returns
object
canSanitize
ts
canSanitize: boolean;detectedType
ts
detectedType: string;reason?
ts
optional reason?: string;getSupportedFileTypes()
ts
getSupportedFileTypes(): readonly string[];Get a list of supported file types/extensions
Returns
readonly string[]
sanitize()
ts
sanitize(
data,
options?,
expectedMimeType?
): Promise<SanitizeResult>;Sanitize a file, stripping privacy-sensitive metadata
Parameters
| Parameter | Type | Description |
|---|---|---|
data | Uint8Array | The file data as a Uint8Array |
options? | SanitizeOptions | Sanitization options |
expectedMimeType? | string | Optional expected MIME type for validation |
Returns
Promise<SanitizeResult>
SanitizeResult - the sanitized file data and metadata
Throws
Error if file type is not supported, file is corrupted, or file is too large