Skip to content

Commit b7e3b3c

Browse files
authored
Added types for upload response callback (#360)
1 parent 219e628 commit b7e3b3c

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

types/cloudinary_ts_spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,13 +688,13 @@ cloudinary.v2.uploader.text("Sample text string",
688688
font_weight: "bold"
689689
});
690690

691-
// $ExpectType Promise<any>
691+
// $ExpectType Promise<UploadApiResponse>
692692
cloudinary.v2.uploader.upload("http://www.example.com/sample.jpg",
693693
function (error, result) {
694694
console.log(result, error);
695695
});
696696

697-
// $ExpectType Promise<any>
697+
// $ExpectType Promise<UploadApiResponse>
698698
cloudinary.v2.uploader.upload("ftp://user1:[email protected]/sample.jpg",
699699
{
700700
eager: [
@@ -705,7 +705,7 @@ cloudinary.v2.uploader.upload("ftp://user1:[email protected]/sample.jpg",
705705
console.log(result, error);
706706
});
707707

708-
// $ExpectType Promise<any>
708+
// $ExpectType Promise<UploadApiResponse>
709709
cloudinary.v2.uploader.upload_large("my_large_video.mp4",
710710
{
711711
resource_type: "video",
@@ -714,7 +714,7 @@ cloudinary.v2.uploader.upload_large("my_large_video.mp4",
714714
function (error, result) {console.log(result, error);
715715
});
716716

717-
// $ExpectType Promise<any>
717+
// $ExpectType Promise<UploadApiResponse>
718718
cloudinary.v2.uploader.upload_large("my_large_video.mp4",
719719
{resource_type: "video"},
720720
function (error, result) {

types/index.d.ts

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,44 @@ declare module 'cloudinary' {
550550
type TargetArchiveFormat = string | "zip" | "tgz";
551551

552552
// err is kept for backwards compatibility, it currently will always be undefined
553-
type ResponseCallback = (callResult: any, err?: any) => any;
553+
type ResponseCallback = (err?: any, callResult?: any) => any;
554+
555+
type UploadResponseCallback = (err?: UploadApiErrorResponse, callResult?: UploadApiResponse) => void;
556+
557+
export interface UploadApiResponse {
558+
public_id: string;
559+
version: number;
560+
signature: string;
561+
width: number;
562+
height: number;
563+
format: string;
564+
resource_type: string;
565+
created_at: string;
566+
tags: Array<string>;
567+
pages: number;
568+
bytes: number;
569+
type: string;
570+
etag: string;
571+
placeholder: boolean;
572+
url: string;
573+
secure_url: string;
574+
access_mode: string;
575+
original_filename: string;
576+
moderation: Array<string>;
577+
access_control: Array<string>;
578+
context: object;
579+
metadata: object;
580+
581+
[futureKey: string]: any;
582+
}
583+
584+
export interface UploadApiErrorResponse {
585+
message: string;
586+
name: string;
587+
http_code: number;
588+
589+
[futureKey: string]: any;
590+
}
554591

555592
class UploadStream extends Transform {
556593
}
@@ -887,25 +924,25 @@ declare module 'cloudinary' {
887924

888925
function unsigned_upload_stream(upload_preset: string, callback?: ResponseCallback): UploadStream;
889926

890-
function upload(file: string, options?: UploadApiOptions, callback?: ResponseCallback): Promise<any>;
927+
function upload(file: string, options?: UploadApiOptions, callback?: UploadResponseCallback): Promise<UploadApiResponse>;
891928

892-
function upload(file: string, callback?: ResponseCallback): Promise<any>;
929+
function upload(file: string, callback?: UploadResponseCallback): Promise<UploadApiResponse>;
893930

894-
function upload_chunked(path: string, options?: UploadApiOptions, callback?: ResponseCallback): Promise<any>;
931+
function upload_chunked(path: string, options?: UploadApiOptions, callback?: UploadResponseCallback): Promise<UploadApiResponse>;
895932

896-
function upload_chunked(path: string, callback?: ResponseCallback): Promise<any>;
933+
function upload_chunked(path: string, callback?: UploadResponseCallback): Promise<UploadApiResponse>;
897934

898-
function upload_chunked_stream(options?: UploadApiOptions, callback?: ResponseCallback): UploadStream;
935+
function upload_chunked_stream(options?: UploadApiOptions, callback?: UploadResponseCallback): UploadStream;
899936

900-
function upload_large(path: string, options?: UploadApiOptions, callback?: ResponseCallback): Promise<any>;
937+
function upload_large(path: string, options?: UploadApiOptions, callback?: UploadResponseCallback): Promise<UploadApiResponse>;
901938

902-
function upload_large(path: string, callback?: ResponseCallback): Promise<any>;
939+
function upload_large(path: string, callback?: UploadResponseCallback): Promise<UploadApiResponse>;
903940

904-
function upload_stream(options?: UploadApiOptions, callback?: ResponseCallback): UploadStream;
941+
function upload_stream(options?: UploadApiOptions, callback?: UploadResponseCallback): UploadStream;
905942

906-
function upload_stream(callback?: ResponseCallback): UploadStream;
943+
function upload_stream(callback?: UploadResponseCallback): UploadStream;
907944

908-
function upload_tag_params(options?: UploadApiOptions, callback?: ResponseCallback): Promise<any>;
945+
function upload_tag_params(options?: UploadApiOptions, callback?: UploadResponseCallback): Promise<any>;
909946

910947
function upload_url(options?: ConfigOptions): Promise<any>;
911948
}

0 commit comments

Comments
 (0)