/// /// /// /// /// declare module '@ioc:Adonis/Addons/ResponsiveAttachment' { import type { ColumnOptions } from '@ioc:Adonis/Lucid/Orm'; import type { LoggerContract } from '@ioc:Adonis/Core/Logger'; import type { MultipartFileContract } from '@ioc:Adonis/Core/BodyParser'; import type { DisksList, ContentHeaders, DriverContract, DriveManagerContract } from '@ioc:Adonis/Core/Drive'; type Breakpoints = Partial<{ large: number | 'off'; medium: number | 'off'; small: number | 'off'; }> & Record; /** * Options used to persist the attachment to * the disk */ type AttachmentOptions = { disk?: keyof DisksList; folder?: string; keepOriginal?: boolean; breakpoints?: Breakpoints; forceFormat?: 'jpeg' | 'png' | 'webp' | 'avif' | 'tiff' | 'heif'; optimizeSize?: boolean; optimizeOrientation?: boolean; responsiveDimensions?: boolean; disableThumbnail?: boolean; preComputeUrls?: boolean | ((disk: DriverContract, attachment: ResponsiveAttachmentContract) => Promise); /** * When enabled, blurhash will be generated for the images */ blurhash?: BlurhashOptions; /** * When enabled, filenames of attachments will be persistent by not generating a random suffix during each upload */ persistentFileNames?: boolean; }; type BlurhashOptions = { enabled: boolean; componentX?: number; componentY?: number; }; interface ImageAttributes { /** * The name is available only when "isPersisted" is true. */ name?: string; /** * The url is available only when "isPersisted" is true. */ url?: string; /** * The file size in bytes */ size?: number; /** * The file extname. Inferred from the BodyParser file extname * property */ extname?: string; /** * The file mimetype. */ mimeType?: string; /** * The width of the image */ width?: number; /** * The height of the image */ height?: number; /** * The blurhash of the image */ blurhash?: string; /** * The format of the image */ format?: AttachmentOptions['forceFormat']; /** * The breakpoints object for the image */ breakpoints?: Record; } /** * Attachment class represents an attachment data type * for Lucid models */ interface ResponsiveAttachmentContract extends ImageAttributes { /** * The breakpoint objects */ breakpoints?: Record; /** * The URLs object */ urls?: UrlRecords | null; /** * "isLocal = true" means the instance is created locally * using the bodyparser file object */ isLocal: boolean; /** * Find if the file has been persisted or not. */ isPersisted: boolean; /** * Find if the file has been deleted or not */ isDeleted: boolean; /** * Define persistence options */ setOptions(options?: AttachmentOptions): this; /** * Get current state of attachment options within a responsive * attachment instance */ readonly getOptions: AttachmentOptions; /** * Save responsive images to the disk. Results if noop when "this.isLocal = false" */ save(): Promise; /** * Delete the responsive images from the disk */ delete(): Promise; /** * Computes the URLs for the responsive images. * @param options * @param options.forced Force the URLs to be completed whether * `preComputedURLs` is true or not */ computeUrls(signedUrlOptions?: ContentHeaders & { expiresIn?: string | number; }): Promise; /** * Returns the signed or unsigned URL for each responsive image */ getUrls(signingOptions?: ContentHeaders & { expiresIn?: string | number; }): Promise; /** * Attachment attributes * Convert attachment to plain object to be persisted inside * the database */ toObject(): AttachmentAttributes; /** * Attachment attributes + url * Convert attachment to JSON object to be sent over * the wire */ toJSON(): (AttachmentAttributes & (UrlRecords | null)) | null; } /** * File attachment decorator */ type ResponsiveAttachmentDecorator = (options?: AttachmentOptions & Partial) => (target: TTarget, property: TKey) => void; /** * Attachment class constructor */ interface AttachmentConstructorContract { new (attributes: ImageAttributes, file?: MultipartFileContract): ResponsiveAttachmentContract; fromFile(file: MultipartFileContract, fileName?: string): Promise; fromDbResponse(response: string): ResponsiveAttachmentContract; fromBuffer(buffer: Buffer, fileName?: string): Promise; getDrive(): DriveManagerContract; setDrive(drive: DriveManagerContract): void; setLogger(logger: LoggerContract): void; getLogger(): LoggerContract; } const responsiveAttachment: ResponsiveAttachmentDecorator; const ResponsiveAttachment: AttachmentConstructorContract; }