aboutsummaryrefslogtreecommitdiff
path: root/src/server/apis
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/apis')
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts46
-rw-r--r--src/server/apis/google/GooglePhotosUploadUtils.ts19
2 files changed, 35 insertions, 30 deletions
diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts
index 35a2541a9..b3657ee43 100644
--- a/src/server/apis/google/GoogleApiServerUtils.ts
+++ b/src/server/apis/google/GoogleApiServerUtils.ts
@@ -1,12 +1,11 @@
import { google } from "googleapis";
-import { readFile } from "fs";
import { OAuth2Client, Credentials, OAuth2ClientOptions } from "google-auth-library";
import { Opt } from "../../../new_fields/Doc";
import { GaxiosResponse } from "gaxios";
import request = require('request-promise');
import * as qs from 'query-string';
import { Database } from "../../database";
-import * as path from "path";
+import { GoogleCredentialsLoader } from "../../credentials/CredentialsLoader";
/**
* Scopes give Google users fine granularity of control
@@ -62,6 +61,23 @@ export namespace GoogleApiServerUtils {
let worker: OAuth2Client;
/**
+ * This function is called once before the server is started,
+ * reading in Dash's project-specific credentials (client secret
+ * and client id) for later repeated access. It also sets up the
+ * global, intentionally unauthenticated worker OAuth2 client instance.
+ */
+ export function processProjectCredentials(): void {
+ const { client_secret, client_id, redirect_uris } = GoogleCredentialsLoader.ProjectCredentials;
+ // initialize the global authorization client
+ installed = {
+ clientId: client_id,
+ clientSecret: client_secret,
+ redirectUri: redirect_uris[0]
+ };
+ worker = generateClient();
+ }
+
+ /**
* A briefer format for the response from a 'googleapis' API request
*/
export type ApiResponse = Promise<GaxiosResponse>;
@@ -97,32 +113,6 @@ export namespace GoogleApiServerUtils {
}
/**
- * This function is called once before the server is started,
- * reading in Dash's project-specific credentials (client secret
- * and client id) for later repeated access. It also sets up the
- * global, intentionally unauthenticated worker OAuth2 client instance.
- */
- export async function loadClientSecret(): Promise<void> {
- return new Promise((resolve, reject) => {
- readFile(path.join(__dirname, "../../credentials/google_docs_credentials.json"), async (err, projectCredentials) => {
- if (err) {
- reject(err);
- return console.log('Error loading client secret file:', err);
- }
- const { client_secret, client_id, redirect_uris } = JSON.parse(projectCredentials.toString()).installed;
- // initialize the global authorization client
- installed = {
- clientId: client_id,
- clientSecret: client_secret,
- redirectUri: redirect_uris[0]
- };
- worker = generateClient();
- resolve();
- });
- });
- }
-
- /**
* Maps the Dash user id of a given user to their single
* associated OAuth2 client, mitigating the creation
* of needless duplicate clients that would arise from
diff --git a/src/server/apis/google/GooglePhotosUploadUtils.ts b/src/server/apis/google/GooglePhotosUploadUtils.ts
index d8cf795b5..0abed3f1d 100644
--- a/src/server/apis/google/GooglePhotosUploadUtils.ts
+++ b/src/server/apis/google/GooglePhotosUploadUtils.ts
@@ -1,7 +1,6 @@
import request = require('request-promise');
import * as path from 'path';
-import { MediaItemCreationResult, NewMediaItemResult } from './SharedTypes';
-import { NewMediaItem } from "../../index";
+import { NewMediaItemResult } from './SharedTypes';
import { BatchedArray, TimeUnit } from 'array-batcher';
import { DashUploadUtils } from '../../DashUploadUtils';
@@ -29,6 +28,22 @@ export namespace GooglePhotosUploadUtils {
}
/**
+ * This is the format needed to pass
+ * into the BatchCreate API request
+ * to take a reference to raw uploaded bytes
+ * and actually create an image in Google Photos.
+ *
+ * So, to instantiate this interface you must have already dispatched an upload
+ * and received an upload token.
+ */
+ export interface NewMediaItem {
+ description: string;
+ simpleMediaItem: {
+ uploadToken: string;
+ };
+ }
+
+ /**
* A utility function to streamline making
* calls to the API's url - accentuates
* the relative path in the caller.