@@ -10,27 +10,27 @@ import {IdentifyModel} from "../application/model/Identify/IdentifyModel";
10
10
11
11
export default class FaceService {
12
12
public static async listPersonGroupsAsync ( ) : Promise < PersonGroupModel [ ] > {
13
- return await this . client . callApiAsync ( `/persongroups` ) ;
13
+ return await this . getClient ( ) . callApiAsync ( `/persongroups` ) ;
14
14
}
15
15
16
16
public static async createPersonGroupAsync ( groupId : string , model : PersonGroupModel ) : Promise < void > {
17
- await this . client . callApiAsync ( `/persongroups/${ groupId } ` , HttpMethod . PUT , model ) ;
17
+ await this . getClient ( ) . callApiAsync ( `/persongroups/${ groupId } ` , HttpMethod . PUT , model ) ;
18
18
}
19
19
20
20
public static async trainPersonGroupAsync ( groupId : string ) : Promise < void > {
21
- await this . client . callApiAsync ( `/persongroups/${ groupId } /train` , HttpMethod . POST ) ;
21
+ await this . getClient ( ) . callApiAsync ( `/persongroups/${ groupId } /train` , HttpMethod . POST ) ;
22
22
}
23
23
24
24
public static async checkPersonGroupTrainingStatusAsync ( groupId : string ) : Promise < PersonGroupTrainingStatusModel > {
25
- return await this . client . callApiAsync ( `/persongroups/${ groupId } /training` ) ;
25
+ return await this . getClient ( ) . callApiAsync ( `/persongroups/${ groupId } /training` ) ;
26
26
}
27
27
28
28
public static async listPersonsAsync ( groupId : string ) : Promise < PersonModel [ ] > {
29
- return await this . client . callApiAsync ( `/persongroups/${ groupId } /persons` ) ;
29
+ return await this . getClient ( ) . callApiAsync ( `/persongroups/${ groupId } /persons` ) ;
30
30
}
31
31
32
32
public static async createPersonAsync ( groupId : string , model : PersonModel ) : Promise < PersonModel > {
33
- const res = await this . client . callApiAsync ( `/persongroups/${ groupId } /persons` , HttpMethod . POST , model ) ;
33
+ const res = await this . getClient ( ) . callApiAsync ( `/persongroups/${ groupId } /persons` , HttpMethod . POST , model ) ;
34
34
35
35
model . personId = res . personId ;
36
36
delete model . persistedFaceIds ;
@@ -51,7 +51,7 @@ export default class FaceService {
51
51
`targetFace=${ coordinates } ` ,
52
52
] . join ( "&" ) ;
53
53
54
- return await this . client . callApiAsync (
54
+ return await this . getClient ( ) . callApiAsync (
55
55
`/persongroups/${ groupId } /persons/${ personId } /persistedFaces?${ query } ` ,
56
56
HttpMethod . POST ,
57
57
{ url } ) ;
@@ -84,20 +84,26 @@ export default class FaceService {
84
84
`detectionModel=${ ConfigService . Face . DetectionModel } ` ,
85
85
] . join ( "&" ) ;
86
86
87
- return await this . client . callApiAsync (
87
+ return await this . getClient ( ) . callApiAsync (
88
88
`/detect?${ query } ` ,
89
89
HttpMethod . POST ,
90
90
{ url } ) ;
91
91
}
92
92
93
93
public static async identifyFacesAsync ( faceIds : string [ ] , personGroupId : string ) : Promise < IdentifyModel [ ] > {
94
- return await this . client . callApiAsync (
94
+ return await this . getClient ( ) . callApiAsync (
95
95
"/identify" ,
96
96
HttpMethod . POST ,
97
97
{ faceIds, personGroupId } ) ;
98
98
}
99
99
100
- private static client = new HttpService ( ConfigService . Face . Url , {
101
- "Ocp-Apim-Subscription-Key" : ConfigService . Face . Key ,
102
- } ) ;
100
+ private static _client : HttpService ;
101
+ private static getClient ( ) {
102
+ if ( ! this . _client ) {
103
+ this . _client = new HttpService ( ConfigService . Face . Url , {
104
+ "Ocp-Apim-Subscription-Key" : ConfigService . Face . Key ,
105
+ } ) ;
106
+ }
107
+ return this . _client ;
108
+ }
103
109
}
0 commit comments