Skip to content

Commit 08dcaac

Browse files
committed
fixed FaceService
1 parent da3f034 commit 08dcaac

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Diff for: src/service/FaceService.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ import {IdentifyModel} from "../application/model/Identify/IdentifyModel";
1010

1111
export default class FaceService {
1212
public static async listPersonGroupsAsync(): Promise<PersonGroupModel[]> {
13-
return await this.client.callApiAsync(`/persongroups`);
13+
return await this.getClient().callApiAsync(`/persongroups`);
1414
}
1515

1616
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);
1818
}
1919

2020
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);
2222
}
2323

2424
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`);
2626
}
2727

2828
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`);
3030
}
3131

3232
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);
3434

3535
model.personId = res.personId;
3636
delete model.persistedFaceIds;
@@ -51,7 +51,7 @@ export default class FaceService {
5151
`targetFace=${coordinates}`,
5252
].join("&");
5353

54-
return await this.client.callApiAsync(
54+
return await this.getClient().callApiAsync(
5555
`/persongroups/${groupId}/persons/${personId}/persistedFaces?${query}`,
5656
HttpMethod.POST,
5757
{ url });
@@ -84,20 +84,26 @@ export default class FaceService {
8484
`detectionModel=${ConfigService.Face.DetectionModel}`,
8585
].join("&");
8686

87-
return await this.client.callApiAsync(
87+
return await this.getClient().callApiAsync(
8888
`/detect?${query}`,
8989
HttpMethod.POST,
9090
{ url });
9191
}
9292

9393
public static async identifyFacesAsync(faceIds: string[], personGroupId: string): Promise<IdentifyModel[]> {
94-
return await this.client.callApiAsync(
94+
return await this.getClient().callApiAsync(
9595
"/identify",
9696
HttpMethod.POST,
9797
{ faceIds, personGroupId });
9898
}
9999

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+
}
103109
}

0 commit comments

Comments
 (0)