@@ -39,21 +39,25 @@ class RecognitionService {
3939 * @param {Object } options
4040 * @returns {String }
4141 */
42- add_options_to_url ( url , localOptions , needLimitOption , needDetOption , needPredictionOption ) {
42+ add_options_to_url ( url , localOptions , required_parameters ) {
43+ // merge options passed by localy and globally NOTE: global options will override local on if same value passed from both of them
4344 let uniqueOptions = { ...localOptions , ...this . options } ;
4445 let isThereAnyOptions = Object . keys ( uniqueOptions ) ;
4546
46- // check whether user passed options by main class
47+ // check whether any parameters passed
4748 if ( isThereAnyOptions . length > 0 ) {
48- if ( ! isNaN ( uniqueOptions [ 'limit' ] ) && needLimitOption ) {
49+ // check whether limit parameter passed and it is required for particular endpoint (ex: it is not requrid for add())
50+ if ( uniqueOptions [ 'limit' ] >= 0 && required_parameters [ 'limit' ] ) {
4951 url = `${ url } ?limit=${ uniqueOptions [ 'limit' ] } `
5052 }
5153
52- if ( ! isNaN ( uniqueOptions [ 'det_prob_threshold' ] ) && needDetOption ) {
54+ // check whether det_prob_threshold parameter passed and is it required for particular endpoint
55+ if ( uniqueOptions [ 'det_prob_threshold' ] >= 0 && required_parameters [ 'det_prob_threshold' ] ) {
5356 url = `${ url } &det_prob_threshold=${ uniqueOptions [ 'det_prob_threshold' ] } `
5457 }
5558
56- if ( ! isNaN ( uniqueOptions [ 'prediction_count' ] ) && needPredictionOption ) {
59+ // check whether prediction_count passed and is it required for particular endpoint
60+ if ( uniqueOptions [ 'prediction_count' ] >= 0 && required_parameters [ 'prediction_count' ] ) {
5761 url = `${ url } &prediction_count=${ uniqueOptions [ 'prediction_count' ] } `
5862 }
5963 }
@@ -94,12 +98,15 @@ class RecognitionService {
9498 * @returns {Promise }
9599 */
96100 add ( image_path , subject , options ) {
101+ // add extra parameter(s) name with true value if it is referenced in API documentation for particular endpoint
102+ // add_options_to_url() adds this parameter to url if user passes some value as option otherwise function ignores this parameter
103+ let required_url_parameters = { det_prob_threshold : true } ;
97104 let urlRegEX = / ^ (?: h t t p ( s ) ? : \/ \/ ) ? [ \w . - ] + (?: \. [ \w \. - ] + ) + [ \w \- \. _ ~ : / ? # [ \] @ ! \$ & ' \( \) \* \+ , ; = . ] + $ / ;
98105 let isUrl = urlRegEX . test ( image_path ) ;
99106
100107 // add parameters to basic url
101108 url = `${ url } ?subject=${ subject } `
102- url = that . add_options_to_url ( url , options , false , true , false ) ;
109+ url = that . add_options_to_url ( url , options , required_url_parameters ) ;
103110
104111 return new Promise ( ( resolve , reject ) => {
105112 if ( isUrl ) {
@@ -129,9 +136,12 @@ class RecognitionService {
129136 * @returns {Promise }
130137 */
131138 recognize ( image_path , options ) {
139+ // add extra parameter(s) name with true value if it is referenced in API documentation for particular endpoint
140+ // add_options_to_url() adds this parameter to url if user passes some value as option otherwise function ignores this parameter
141+ let required_url_parameters = { limit : true , det_prob_threshold : true , prediction_count : true } ;
132142 // add parameters to basic url
133143 url = `${ url } /recognize` ;
134- url = that . add_options_to_url ( url , options , true , true , true ) ;
144+ url = that . add_options_to_url ( url , options , required_url_parameters ) ;
135145
136146 return new Promise ( ( resolve , reject ) => {
137147 recognition_endpoints . recognize_face_request ( image_path , url , key )
@@ -152,9 +162,12 @@ class RecognitionService {
152162 * @returns {Promise }
153163 */
154164 verify ( image_path , image_id , options ) {
165+ // add extra parameter(s) name with true value if it is referenced in API documentation for particular endpoint
166+ // add_options_to_url() adds this parameter to url if user passes some value as option otherwise function ignores this parameter
167+ let required_url_parameters = { det_prob_threshold : true , prediction_count : true } ;
155168 // add parameters to basic url
156169 url = `${ url } /${ image_id } /verify` ;
157- url = that . add_options_to_url ( url , options , true , true , false ) ;
170+ url = that . add_options_to_url ( url , options , required_url_parameters ) ;
158171
159172 return new Promise ( ( resolve , reject ) => {
160173 recognition_endpoints . verify_face_request ( image_path , url , key )
0 commit comments