export declare const DEFAULT_ROUTE = "/api/image-op"; export declare const ONE_YEAR_IN_SECONDS = 31536000; /** * @description Options for the image optimizer * @param route - The route to handle image optimization requests * @param formatPriority - The order of formats to try when optimizing images defaults to avif, webp, jpeg, jpg, png, gif * @param fallbackFormat - If the the format query is not specified, and the accept header did not specify a format, this is the format that will be used. Defaults to jpeg * @param quality - The quality of the image. Defaults to 75 * @param cache - Optional cache handler for storing processed images * @param cacheTTLStrategy - The TTL for the cache. defaults to same as source. valid values are number of seconds, 'source', 'immutable' * @param allowedDomains - The domains that are allowed to be optimized. Defaults to all domains. (this could be useful to avoid DDOS attacks) * @param minSizeThreshold - The minimum size of the image to be optimized. Defaults to 5kb. * @param skipFormats - The formats that will not be optimized, this only applies to images without a resize query. Defaults to avif, webp */ export type Options = { route: string; formatPriority: Array; fallbackFormat: string; quality?: number; cache?: ImageCacheHandler; cacheTTLStrategy?: number | 'source' | 'immutable' | 'no-cache'; allowedDomains?: Array | ApproveDomainFunction; minSizeThreshold?: number; skipFormats?: Array; }; export type ApproveDomainFunction = (url: string) => boolean; export declare enum CacheTTLStrategy { source = "source", immutable = "immutable", noCache = "no-cache" } export declare enum FitEnum { cover = "cover", contain = "contain", fill = "fill", inside = "inside", outside = "outside" } export declare enum AcceptedImageOutputFormats { avif = "avif", webp = "webp", jpeg = "jpeg", jpg = "jpg", png = "png", gif = "gif", ico = "ico", svg = "svg" } export declare const DEFAULT_FORMAT_PRIORITIES: AcceptedImageOutputFormats[]; export declare const DEFAULT_SKIP_FORMATS: AcceptedImageOutputFormats[]; export declare const DEFAULT_MIN_SIZE_THRESHOLD: number; export declare const DEFAULT_QUALITY = 75; export declare const DEFAULT_QUALITY_PER_FORMAT: { avif: number; webp: number; jpeg: number; jpg: number; png: number; }; /** * Interface for handling image cache operations. */ export interface ImageCacheHandler { /** * Indicates whether redirects should be used. */ useRedirects: boolean; /** * Retrieves the cached data associated with the given hash. * @param hash - The unique identifier for the cached data. * @returns A promise that resolves to a readable stream, buffer, or null if the key does not exist. */ getKey(hash: string): Promise<{ value: NodeJS.ReadableStream | Buffer | null; ttl?: number; }>; /** * Stores data in the cache with the specified hash. * @param hash - The unique identifier for the data to be cached. * @param value - The data to be cached, which can be a readable stream, buffer, or readable stream. * @param ttl - Optional time to live for the cached data (in seconds). * @param contentType - Optional MIME type of the data being cached. * @returns A promise that resolves when the data has been successfully cached. */ setKey(hash: string, value: NodeJS.ReadableStream | Buffer | ReadableStream, ttl?: number, contentType?: string): Promise; /** * Deletes the cached data associated with the given hash. * @param hash - The unique identifier for the cached data to be deleted. * @returns A promise that resolves when the data has been successfully deleted. */ delKey(hash: string): Promise; /** * Retrieves the public URL for the cached data associated with the given hash. * This is useful incase of using cdns for caching, the sveltekit endpoint will not pipe * the image stream, instead it will return a permanent redirect to the cached file. * @param hash - The unique identifier for the cached data. * @returns A promise that resolves to the public URL as a string, or null if the URL cannot be generated. */ getPublicUrl(hash: string): Promise<{ url: string | null; ttl?: number; }>; } export declare const DEFAULT_CACHE_TTL_STRATEGY = CacheTTLStrategy.source;