1 | import { UploadApiOptions, v2 as Cloudinary } from 'cloudinary';
|
2 | import type { Request } from 'express';
|
3 | import type { StorageEngine } from 'multer';
|
4 | declare 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;
|
9 | declare type File = Express.Multer.File;
|
10 | declare type PickedUploadApiOptions = Pick<UploadApiOptions, KnownKeys<UploadApiOptions>>;
|
11 | export declare type OptionCallback<T> = (req: Request, file: File) => Promise<T> | T;
|
12 | declare type CloudinaryStorageUploadOptionsWithoutPublicId = {
|
13 | [key in keyof PickedUploadApiOptions]: OptionCallback<PickedUploadApiOptions[key]> | PickedUploadApiOptions[key];
|
14 | };
|
15 | declare type CloudinaryStorageUploadOptions = CloudinaryStorageUploadOptionsWithoutPublicId & {
|
16 | public_id?: OptionCallback<string>;
|
17 | };
|
18 | declare type Params = CloudinaryStorageUploadOptions | OptionCallback<PickedUploadApiOptions>;
|
19 | export interface Options {
|
20 | cloudinary: typeof Cloudinary;
|
21 | params?: Params;
|
22 | }
|
23 | export 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 | }
|
31 | export declare function createCloudinaryStorage(opts: Options): CloudinaryStorage;
|
32 | export default createCloudinaryStorage;
|