@@ -1058,17 +1058,31 @@ function unsigned_url_prefix(
10581058 return prefix ;
10591059}
10601060
1061- function base_api_url ( path = [ ] , options = { } ) {
1062- let cloudinary = ensureOption ( options , "upload_prefix" , UPLOAD_PREFIX ) ;
1063- let cloud_name = ensureOption ( options , "cloud_name" ) ;
1064- let encode_path = unencoded_path => encodeURIComponent ( unencoded_path ) . replace ( "'" , '%27' ) ;
1065- let encoded_path = Array . isArray ( path ) ? path . map ( encode_path ) : encode_path ( path ) ;
1066- return [ cloudinary , "v1_1" , cloud_name ] . concat ( encoded_path ) . join ( "/" ) ;
1061+ function base_api_url_v1_1 ( ) {
1062+ return base_api_url ( 'v1_1' ) ;
1063+ }
1064+
1065+ function base_api_url_v2 ( ) {
1066+ return base_api_url ( 'v2' ) ;
1067+ }
1068+
1069+ function base_api_url ( api_version ) {
1070+ if ( ! api_version || api_version . length === 0 ) {
1071+ throw new Error ( 'api_version needs to be a non-empty string' ) ;
1072+ }
1073+
1074+ return ( path = [ ] , options = [ ] ) => {
1075+ let cloudinary = ensureOption ( options , "upload_prefix" , UPLOAD_PREFIX ) ;
1076+ let cloud_name = ensureOption ( options , "cloud_name" ) ;
1077+ let encode_path = unencoded_path => encodeURIComponent ( unencoded_path ) . replace ( "'" , '%27' ) ;
1078+ let encoded_path = Array . isArray ( path ) ? path . map ( encode_path ) : encode_path ( path ) ;
1079+ return [ cloudinary , api_version , cloud_name ] . concat ( encoded_path ) . join ( "/" ) ;
1080+ } ;
10671081}
10681082
10691083function api_url ( action = 'upload' , options = { } ) {
10701084 let resource_type = options . resource_type || "image" ;
1071- return base_api_url ( [ resource_type , action ] , options ) ;
1085+ return base_api_url_v1_1 ( ) ( [ resource_type , action ] , options ) ;
10721086}
10731087
10741088function random_public_id ( ) {
@@ -1225,7 +1239,7 @@ function download_backedup_asset(asset_id, version_id, options = {}) {
12251239 asset_id : asset_id ,
12261240 version_id : version_id
12271241 } , options ) ;
1228- return exports . base_api_url ( [ 'download_backup' ] , options ) + "?" + hashToQuery ( params ) ;
1242+ return exports . base_api_url_v1 ( ) ( [ 'download_backup' ] , options ) + "?" + hashToQuery ( params ) ;
12291243}
12301244
12311245/**
@@ -1681,7 +1695,8 @@ exports.only = pickOnlyExistingValues; // for backwards compatibility
16811695exports . pickOnlyExistingValues = pickOnlyExistingValues ;
16821696exports . jsonArrayParam = jsonArrayParam ;
16831697exports . download_folder = download_folder ;
1684- exports . base_api_url = base_api_url ;
1698+ exports . base_api_url_v1 = base_api_url_v1_1 ;
1699+ exports . base_api_url_v2 = base_api_url_v2 ;
16851700exports . download_backedup_asset = download_backedup_asset ;
16861701exports . compute_hash = compute_hash ;
16871702exports . build_distribution_domain = build_distribution_domain ;
0 commit comments