aboutsummaryrefslogtreecommitdiff
path: root/src/client/cognitive_services/CognitiveServices.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/cognitive_services/CognitiveServices.ts')
-rw-r--r--src/client/cognitive_services/CognitiveServices.ts29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts
index 08fcb4883..5a7f5e991 100644
--- a/src/client/cognitive_services/CognitiveServices.ts
+++ b/src/client/cognitive_services/CognitiveServices.ts
@@ -2,7 +2,6 @@ import * as request from "request-promise";
import { Doc, Field, Opt } from "../../new_fields/Doc";
import { Cast } from "../../new_fields/Types";
import { Docs } from "../documents/Documents";
-import { RouteStore } from "../../server/RouteStore";
import { Utils } from "../../Utils";
import { InkData } from "../../new_fields/InkField";
import { UndoManager } from "../util/UndoManager";
@@ -39,21 +38,19 @@ export enum Confidence {
export namespace CognitiveServices {
const ExecuteQuery = async <D>(service: Service, manager: APIManager<D>, data: D): Promise<any> => {
- return fetch(Utils.prepend(`${RouteStore.cognitiveServices}/${service}`)).then(async response => {
- let apiKey = await response.text();
- if (!apiKey) {
- console.log(`No API key found for ${service}: ensure index.ts has access to a .env file in your root directory`);
- return undefined;
- }
-
- let results: any;
- try {
- results = await manager.requester(apiKey, manager.converter(data), service).then(json => JSON.parse(json));
- } catch {
- results = undefined;
- }
- return results;
- });
+ const apiKey = await Utils.getApiKey(service);
+ if (!apiKey) {
+ console.log(`No API key found for ${service}: ensure index.ts has access to a .env file in your root directory.`);
+ return undefined;
+ }
+
+ let results: any;
+ try {
+ results = await manager.requester(apiKey, manager.converter(data), service).then(json => JSON.parse(json));
+ } catch {
+ results = undefined;
+ }
+ return results;
};
export namespace Image {