aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Utils.ts7
-rw-r--r--src/client/cognitive_services/CognitiveServices.ts28
-rw-r--r--src/server/ApiManagers/GeneralGoogleManager.ts16
-rw-r--r--src/server/ApiManagers/GooglePhotosManager.ts1
4 files changed, 22 insertions, 30 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index abff2eaba..91fa459c6 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -48,6 +48,11 @@ export namespace Utils {
return prepend("/corsProxy/") + encodeURIComponent(url);
}
+ export async function getApiKey(target: string): Promise<string> {
+ const response = await fetch(prepend(`environment/${target.toUpperCase()}`));
+ return response.text();
+ }
+
export function CopyText(text: string) {
var textArea = document.createElement("textarea");
textArea.value = text;
@@ -174,7 +179,7 @@ export namespace Utils {
}
let idString = (message.id || "").padStart(36, ' ');
prefix = prefix.padEnd(16, ' ');
- console.log(`${prefix}: ${idString}, ${receiving ? 'receiving' : 'sending'} ${messageName} with data ${JSON.stringify(message)}`);
+ console.log(`${prefix}: ${idString}, ${receiving ? 'receiving' : 'sending'} ${messageName} with data ${JSON.stringify(message)} `);
}
function loggingCallback(prefix: string, func: (args: any) => any, messageName: string) {
diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts
index e74aef998..5a7f5e991 100644
--- a/src/client/cognitive_services/CognitiveServices.ts
+++ b/src/client/cognitive_services/CognitiveServices.ts
@@ -38,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(`environment/${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 {
diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts
index 89efebf78..171912185 100644
--- a/src/server/ApiManagers/GeneralGoogleManager.ts
+++ b/src/server/ApiManagers/GeneralGoogleManager.ts
@@ -5,11 +5,7 @@ import { Database } from "../database";
import RouteSubscriber from "../RouteSubscriber";
const deletionPermissionError = "Cannot perform specialized delete outside of the development environment!";
-const ServicesApiKeyMap = new Map<string, string | undefined>([
- ["face", process.env.FACE],
- ["vision", process.env.VISION],
- ["handwriting", process.env.HANDWRITING]
-]);
+
const EndpointHandlerMap = new Map<GoogleApiServerUtils.Action, GoogleApiServerUtils.ApiRouter>([
["create", (api, params) => api.create(params)],
["retrieve", (api, params) => api.get(params)],
@@ -54,15 +50,6 @@ export default class GeneralGoogleManager extends ApiManager {
});
register({
- method: Method.GET,
- subscription: new RouteSubscriber("/cognitiveServices").add('requestedservice'),
- onValidation: ({ req, res }) => {
- let service = req.params.requestedservice;
- res.send(ServicesApiKeyMap.get(service));
- }
- });
-
- register({
method: Method.POST,
subscription: new RouteSubscriber("/googleDocs").add("sector", "action"),
onValidation: async ({ req, res, user }) => {
@@ -79,5 +66,6 @@ export default class GeneralGoogleManager extends ApiManager {
res.send(undefined);
}
});
+
}
} \ No newline at end of file
diff --git a/src/server/ApiManagers/GooglePhotosManager.ts b/src/server/ApiManagers/GooglePhotosManager.ts
index 1f6051c28..1138dede1 100644
--- a/src/server/ApiManagers/GooglePhotosManager.ts
+++ b/src/server/ApiManagers/GooglePhotosManager.ts
@@ -107,5 +107,6 @@ export default class GooglePhotosManager extends ApiManager {
_invalid(res, requestError);
}
});
+
}
} \ No newline at end of file