UNPKG

softypy-media-service

Version:

A media upload service client for Node.js and frontend applications

112 lines (108 loc) 3.15 kB
interface MediaServiceConfig { baseUrl: string; apiKey: string; timeout?: number; retryAttempts?: number; } interface TransformOptions { width?: number; height?: number; format?: 'jpeg' | 'png' | 'webp' | 'avif'; quality?: number; fit?: 'cover' | 'contain' | 'fill'; } interface FileMetadata { width?: number; height?: number; format?: string; versions: { original: string; thumbnail?: string; transformations: Record<string, string>; }; } interface TransformationRecord { key: string; url?: string; width?: number | null; height?: number | null; format?: string | null; quality?: number | null; size?: number | null; } interface UploadResponse { _id: string; filename: string; originalname: string; mimetype: string; size: number; path: string; thumbnailPath?: string; url: string; thumbnailUrl?: string; publicId: string; userId: string; versions: TransformationRecord[]; createdAt: Date; updatedAt: Date; } interface FileResponse { url: string; publicId: string; metadata: FileMetadata; mimetype: string; size: number; } interface DeleteResponse { success: boolean; message: string; } interface ErrorResponse { message: string; code: string; status: number; } declare class MediaService { private apiService; constructor(config: MediaServiceConfig); /** * Upload a file to the media service * @param file The file to upload * @param options Optional transform and metadata options */ uploadFile(file: File, options?: { transform?: TransformOptions; metadata?: Record<string, any>; }): Promise<UploadResponse>; /** * Get a file by its public ID * @param publicId The public ID of the file * @param transform Optional transformation parameters */ getFile(publicId: string, transform?: TransformOptions): Promise<FileResponse>; /** * Get the thumbnail version of a file * @param publicId The public ID of the file */ getThumbnail(publicId: string): Promise<FileResponse>; /** * Get a transformed version of a file * @param publicId The public ID of the file * @param transform The transformation options */ getTransformedFile(publicId: string, transform: TransformOptions): Promise<FileResponse>; /** * Get a file with custom transformation parameters * @param publicId The public ID of the file * @param transform The transformation options */ private getFileWithTransform; /** * Delete a file by its public ID * @param publicId The public ID of the file to delete */ deleteFile(publicId: string): Promise<DeleteResponse>; } declare const configureMediaService: (config: MediaServiceConfig) => MediaService; declare const getMediaService: () => MediaService; export { DeleteResponse, ErrorResponse, FileMetadata, FileResponse, MediaService, MediaServiceConfig, TransformOptions, TransformationRecord, UploadResponse, configureMediaService, getMediaService };