adonis-responsive-attachment
Version:
Generate and persist optimised and responsive breakpoint images on the fly in your AdonisJS application.
175 lines (174 loc) • 5.36 kB
TypeScript
/// <reference path="../../adonis-typings/index.d.ts" />
/// <reference types="@adonisjs/drive/build/adonis-typings" />
/// <reference types="@adonisjs/logger/build/adonis-typings/logger" />
/// <reference types="@adonisjs/bodyparser/build/adonis-typings" />
/// <reference types="node" />
import { LoggerContract } from '@ioc:Adonis/Core/Logger';
import type { MultipartFileContract } from '@ioc:Adonis/Core/BodyParser';
import { DriveManagerContract, ContentHeaders } from '@ioc:Adonis/Core/Drive';
import type { AttachmentOptions, ResponsiveAttachmentContract, AttachmentAttributes, ImageInfo, UrlRecords, ImageBreakpoints, ImageAttributes } from '@ioc:Adonis/Addons/ResponsiveAttachment';
export declare const tempUploadFolder = "image_upload_tmp";
/**
* Attachment class represents an attachment data type
* for Lucid models
*/
export declare class ResponsiveAttachment implements ResponsiveAttachmentContract {
private buffer?;
private static drive;
private static logger;
/**
* Reference to the drive
*/
static getDrive(): DriveManagerContract;
/**
* Set the drive instance
*/
static setDrive(drive: DriveManagerContract): void;
/**
* Set the logger instance
*/
static setLogger(logger: LoggerContract): void;
/**
* Reference to the logger instance
*/
static getLogger(): LoggerContract;
/**
* Create attachment instance from the bodyparser
* file
*/
static fromFile(file: MultipartFileContract, fileName?: string): Promise<ResponsiveAttachmentContract>;
/**
* Create attachment instance from the bodyparser via a buffer
*/
static fromBuffer(buffer: Buffer, name?: string): Promise<ResponsiveAttachmentContract>;
/**
* Create attachment instance from the database response
*/
static fromDbResponse(response: string | ImageAttributes): ResponsiveAttachment | null;
/**
* The generated name of the original file.
* Available only when "isPersisted" is true.
*/
name?: string;
/**
* The generated url of the original file.
* Available only when "isPersisted" is true.
*/
url?: string;
/**
* The urls of the original and breakpoint files.
* Available only when "isPersisted" is true.
*/
urls?: UrlRecords;
/**
* The image size of the original file in bytes
*/
size?: number;
/**
* The image extname. Inferred from the bodyparser file extname
* property
*/
extname?: string;
/**
* The image mimetype.
*/
mimeType?: string;
/**
* The image width.
*/
width?: number;
/**
* The image height.
*/
height?: number;
/**
* The image's blurhash.
*/
blurhash?: string;
/**
* This file name.
*/
fileName?: string;
/**
* The format or filetype of the image.
*/
format?: AttachmentOptions['forceFormat'];
/**
* The format or filetype of the image.
*/
breakpoints?: Record<keyof ImageBreakpoints, ImageInfo>;
/**
* Find if the image has been persisted or not.
*/
isPersisted: boolean;
/**
* Find if the image has been deleted or not
*/
isDeleted: boolean;
constructor(attributes: AttachmentAttributes & {
fileName?: string;
}, buffer?: Buffer | undefined);
get attributes(): {
name: string | undefined;
size: number | undefined;
width: number | undefined;
format: "jpeg" | "png" | "webp" | "avif" | "tiff" | "heif" | undefined;
height: number | undefined;
extname: string | undefined;
mimeType: string | undefined;
url: string | undefined;
breakpoints: Record<string, ImageInfo> | undefined;
buffer: Buffer | undefined;
blurhash: string | undefined;
};
/**
* Is `true` when the instance is created locally using the
* bodyparser file object or a file buffer.
*/
isLocal: boolean;
/**
* Returns disk instance
*/
private getDisk;
get getOptions(): AttachmentOptions;
/**
* Returns disk instance
*/
private get loggerInstance();
/**
* Define persistance options
*/
setOptions(options?: AttachmentOptions): this;
protected enhanceFile(options: AttachmentOptions): Promise<ImageInfo>;
/**
* Save image to the disk. Results in noop when "this.isLocal = false"
*/
save(): Promise<this>;
/**
* Delete original and responsive images from the disk
*/
delete(): Promise<void>;
computeUrls(signedUrlOptions?: ContentHeaders & {
expiresIn?: string | number;
}): Promise<UrlRecords | undefined>;
/**
* Returns the signed or unsigned URL for each responsive image
*/
getUrls(signingOptions?: ContentHeaders & {
expiresIn?: string | number;
}): Promise<UrlRecords | undefined>;
/**
* Convert attachment instance to object without the `url` property
* for persistence to the database
*/
toObject(): {
breakpoints: Record<string, ImageInfo> | undefined;
};
/**
* Serialize attachment instance to JSON object to be sent over the wire
*/
toJSON(): {
breakpoints: Record<string, ImageInfo> | undefined;
} & UrlRecords;
}