@@ -100,61 +100,169 @@ const verification_endpoints = {
100100     */ 
101101    one_url_request ( source_image_path ,  isSourceImageUrl ,  target_image_path ,  url ,  api_key  ) { 
102102        var  bodyFormData  =  new  FormData ( ) ; 
103+         let  path_is_url  =  [ ] ; 
104+         let  path_is_relative  =  [ ] ; 
103105
104106        if ( isSourceImageUrl ) { 
105-             bodyFormData . append ( 'target_image' ,  fs . createReadStream ( target_image_path ) ,  {  knownLength : fs . statSync ( target_image_path ) . size  } ) ; 
106- 
107-             return  new  Promise (  async  ( resolve ,  reject )  =>  { 
108-                 await  axios . get ( source_image_path ,  {  responseType : 'stream'  } ) 
109-                     . then (  async  ( response )  =>  { 
110-                         let  image_extention  =  response . headers [ 'content-type' ] . split ( "/" ) [ 1 ] 
111-                         bodyFormData . append ( 'source_image' ,  response . data ,  `example.${ image_extention }  ` ) ; 
112- 
113-                         try  { 
114-                             const  res  =  await  axios . post (  url ,  bodyFormData ,  { 
115-                                 headers : { 
116-                                     ...bodyFormData . getHeaders ( ) , 
117-                                     "x-api-key" : api_key 
118-                                 } , 
119-                             } ) 
120-     
121-                             resolve ( res ) 
122-                         }  catch  ( error )  { 
123-                             reject ( error ) 
124-                         } 
125-                     } ) 
126-                     . catch ( error  =>  { 
107+             path_is_url [ 0 ]  =  "source_image" ; 
108+             path_is_url [ 1 ]  =  source_image_path ; 
109+ 
110+             path_is_relative [ 0 ]  =  "target_image" ; 
111+             path_is_relative [ 1 ]  =  target_image_path ; 
112+         } else { 
113+             path_is_url  =  "target_image" ; 
114+             path_is_url [ 1 ]  =  target_image_path ; 
115+ 
116+             path_is_relative  =  "source_image" ; 
117+             path_is_relative [ 1 ]  =  source_image_path ; 
118+         } 
119+ 
120+         bodyFormData . append ( path_is_relative [ 0 ] ,  fs . createReadStream ( path_is_relative [ 1 ] ) ,  {  knownLength : fs . statSync ( target_image_path ) . size  } ) ; 
121+ 
122+         return  new  Promise (  async  ( resolve ,  reject )  =>  { 
123+             await  axios . get ( path_is_url [ 1 ] ,  {  responseType : 'stream'  } ) 
124+                 . then (  async  ( response )  =>  { 
125+                     let  image_extention  =  response . headers [ 'content-type' ] . split ( "/" ) [ 1 ] 
126+                     bodyFormData . append ( path_is_url [ 0 ] ,  response . data ,  `example.${ image_extention }  ` ) ; 
127+ 
128+                     try  { 
129+                         const  res  =  await  axios . post (  url ,  bodyFormData ,  { 
130+                             headers : { 
131+                                 ...bodyFormData . getHeaders ( ) , 
132+                                 "x-api-key" : api_key 
133+                             } , 
134+                         } ) 
135+ 
136+                         resolve ( res ) 
137+                     }  catch  ( error )  { 
127138                        reject ( error ) 
128-                     } ) 
129-             } ) 
130-         } else  { 
131-             bodyFormData . append ( 'source_image' ,  fs . createReadStream ( source_image_path ) ,  {  knownLength : fs . statSync ( source_image_path ) . size  } ) ; 
132-             
133-             return  new  Promise (  async  ( resolve ,  reject )  =>  { 
134-                 await  axios . get ( target_image_path ,  {  responseType : 'stream'  } ) 
135-                     . then (  async  ( response )  =>  { 
136-                         let  image_extention  =  response . headers [ 'content-type' ] . split ( "/" ) [ 1 ] 
137-                         bodyFormData . append ( 'target_image' ,  response . data ,  `example.${ image_extention }  ` ) ; 
138-                            
139-                         try  { 
140-                             const  res  =  await  axios . post (  url ,  bodyFormData ,  { 
141-                                 headers : { 
142-                                     ...bodyFormData . getHeaders ( ) , 
143-                                     "x-api-key" : api_key 
144-                                 } , 
145-                             } ) 
146-     
147-                             resolve ( res ) 
148-                         }  catch  ( error )  { 
149-                             reject ( error ) 
150-                         } 
151-                     } ) 
152-                     . catch ( error  =>  { 
139+                     } 
140+                 } ) 
141+                 . catch ( error  =>  { 
142+                     reject ( error ) 
143+                 } ) 
144+         } ) 
145+     } , 
146+     /** 
147+      * Verify face(s) from given blob data 
148+      * @param  {String } source_image_path  
149+      * @param  {String } target_image_path  
150+      * @param  {Boolean } isSourceBlob 
151+      * @param  {String } url  
152+      * @param  {String } api_key  
153+      * @returns  {Promise } 
154+      */ 
155+     url_blob_request ( source_image_path ,  isSourceImageUrl ,  target_image_path ,  url ,  api_key ) { 
156+         let  bodyFormData  =  new  FormData ( ) ; 
157+         let  path_is_url  =  [ ] ; 
158+         let  path_is_blob  =  [ ] ; 
159+ 
160+         if ( isSourceImageUrl ) { 
161+             path_is_url [ 0 ]  =  "source_image" ; 
162+             path_is_url [ 1 ]  =  source_image_path ; 
163+ 
164+             path_is_blob [ 0 ]  =  "target_image" ; 
165+             path_is_blob [ 1 ]  =  target_image_path ; 
166+         } else { 
167+             path_is_url  =  "target_image" ; 
168+             path_is_url [ 1 ]  =  target_image_path ; 
169+ 
170+             path_is_blob  =  "source_image" ; 
171+             path_is_blob [ 1 ]  =  source_image_path ; 
172+         } 
173+         bodyFormData . append ( path_is_blob [ 0 ] ,  path_is_blob [ 1 ] ,  'example.jpg' ) ; 
174+ 
175+         return  new  Promise (  async  ( resolve ,  reject )  =>  { 
176+             await  axios . get ( path_is_url [ 1 ] ,  {  responseType : 'stream'  } ) 
177+                 . then (  async  ( response )  =>  { 
178+                     let  image_extention  =  response . headers [ 'content-type' ] . split ( "/" ) [ 1 ] 
179+                     bodyFormData . append ( path_is_url [ 0 ] ,  response . data ,  `example.${ image_extention }  ` ) ; 
180+ 
181+                     try  { 
182+                         const  res  =  await  axios . post (  url ,  bodyFormData ,  { 
183+                             headers : { 
184+                                 ...bodyFormData . getHeaders ( ) , 
185+                                 "x-api-key" : api_key 
186+                             } , 
187+                         } ) 
188+ 
189+                         resolve ( res ) 
190+                     }  catch  ( error )  { 
153191                        reject ( error ) 
154-                     } ) 
155-             } ) 
192+                     } 
193+                 } ) 
194+                 . catch ( error  =>  { 
195+                     reject ( error ) 
196+                 } ) 
197+         } ) 
198+     } , 
199+ 
200+     /** 
201+      * Both source and target images are blob 
202+      * @param  {Blob } source_image_blob  
203+      * @param  {Blob } target_image_blob  
204+      * @param  {String } url  
205+      * @param  {String } api_key  
206+      */ 
207+     both_blob_request ( source_image_blob ,  target_image_blob ,  url ,  api_key ) {  
208+         var  bodyFormData  =  new  FormData ( ) ; 
209+ 
210+         bodyFormData . append ( 'source_image' ,  source_image_blob ,  'example.jpg' ) ; 
211+         bodyFormData . append ( 'target_image' ,  target_image_blob ,  'example1.jpg' ) ; 
212+ 
213+         return  new  Promise (  async  ( resolve ,  reject )  =>  { 
214+             try  { 
215+                 const  response  =  await  axios . post (  url ,  bodyFormData ,  { 
216+                     headers : { 
217+                         'Content-Type' : 'multipart/form-data' , 
218+                         "x-api-key" : api_key 
219+                     } , 
220+                 } ) 
221+ 
222+                 resolve ( response ) 
223+             }  catch  ( error )  { 
224+                 reject ( error ) 
225+             } 
226+         } ) 
227+     } , 
228+ 
229+     one_blob_request ( source_image_path ,  isSourceImageBlob ,  target_image_path ,  url ,  api_key  ) { 
230+         var  bodyFormData  =  new  FormData ( ) ; 
231+         let  path_is_blob  =  [ ] ; 
232+         let  path_is_relative  =  [ ] ; 
233+ 
234+         if ( isSourceImageBlob ) { 
235+             path_is_blob [ 0 ]  =  "source_image" ; 
236+             path_is_blob [ 1 ]  =  source_image_path ; 
237+ 
238+             path_is_relative [ 0 ]  =  "target_image" ; 
239+             path_is_relative [ 1 ]  =  target_image_path ; 
240+         } else { 
241+             path_is_blob  =  "target_image" ; 
242+             path_is_blob [ 1 ]  =  target_image_path ; 
243+ 
244+             path_is_relative  =  "source_image" ; 
245+             path_is_relative [ 1 ]  =  source_image_path ; 
156246        } 
157-     } 
247+ 
248+         bodyFormData . append ( path_is_relative [ 0 ] ,  fs . createReadStream ( path_is_relative [ 1 ] ) ,  {  knownLength : fs . statSync ( target_image_path ) . size  } ) ; 
249+         bodyFormData . append ( path_is_blob [ 0 ] ,  path_is_blob [ 1 ] ,  'example.jpg' ) ; 
250+ 
251+         return  new  Promise (  async  ( resolve ,  reject )  =>  { 
252+             try  { 
253+                 const  response  =  await  axios . post (  url ,  bodyFormData ,  { 
254+                     headers : { 
255+                         'Content-Type' : 'multipart/form-data' , 
256+                         "x-api-key" : api_key 
257+                     } , 
258+                 } ) 
259+ 
260+                 resolve ( response ) 
261+             }  catch  ( error )  { 
262+                 reject ( error ) 
263+             } 
264+         } ) 
265+     } , 
158266
159267
160268} 
0 commit comments