UNPKG

1.55 kBTypeScriptView Raw
1import { UploadApiOptions, v2 as Cloudinary } from 'cloudinary';
2import type { Request } from 'express';
3import type { StorageEngine } from 'multer';
4declare type KnownKeys<T> = {
5 [K in keyof T]: string extends K ? never : number extends K ? never : K;
6} extends {
7 [_ in keyof T]: infer U;
8} ? U : never;
9declare type File = Express.Multer.File;
10declare type PickedUploadApiOptions = Pick<UploadApiOptions, KnownKeys<UploadApiOptions>>;
11export declare type OptionCallback<T> = (req: Request, file: File) => Promise<T> | T;
12declare type CloudinaryStorageUploadOptionsWithoutPublicId = {
13 [key in keyof PickedUploadApiOptions]: OptionCallback<PickedUploadApiOptions[key]> | PickedUploadApiOptions[key];
14};
15declare type CloudinaryStorageUploadOptions = CloudinaryStorageUploadOptionsWithoutPublicId & {
16 public_id?: OptionCallback<string>;
17};
18declare type Params = CloudinaryStorageUploadOptions | OptionCallback<PickedUploadApiOptions>;
19export interface Options {
20 cloudinary: typeof Cloudinary;
21 params?: Params;
22}
23export declare class CloudinaryStorage implements StorageEngine {
24 private cloudinary;
25 private params;
26 constructor(opts: Options);
27 _handleFile(req: Request, file: File, callback: (error?: any, info?: Partial<File>) => void): Promise<void>;
28 _removeFile(req: Request, file: File, callback: (error: Error) => void): void;
29 private upload;
30}
31export declare function createCloudinaryStorage(opts: Options): CloudinaryStorage;
32export default createCloudinaryStorage;