aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-09-26 23:13:42 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-09-26 23:13:42 -0400
commit2553bafde4a6d492512f0a5dfd25f5bd407af929 (patch)
treea8d144840c7de9255de1ec121ed66e350245ebf0 /src/server
parent2e61db73a1fcba3b87cc84a7d1af51617f6a02f6 (diff)
parent087f96367936f33743a304b3446b24074290c367 (diff)
merged with master again
Diffstat (limited to 'src/server')
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts2
-rw-r--r--src/server/database.ts11
2 files changed, 8 insertions, 5 deletions
diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts
index f2ce51395..c899c2ef2 100644
--- a/src/server/apis/google/GoogleApiServerUtils.ts
+++ b/src/server/apis/google/GoogleApiServerUtils.ts
@@ -111,7 +111,7 @@ export namespace GoogleApiServerUtils {
// No token registered, so awaiting input from user
return getNewToken(oAuth2Client, userId).then(resolve, reject);
}
- if (token.expiry_date < new Date().getTime()) {
+ if (token.expiry_date! < new Date().getTime()) {
// Token has expired, so submitting a request for a refreshed access token
return refreshToken(token, client_id, client_secret, oAuth2Client, userId).then(resolve, reject);
}
diff --git a/src/server/database.ts b/src/server/database.ts
index 969437818..d2375ebd9 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -3,6 +3,7 @@ import { Transferable } from './Message';
import { Opt } from '../new_fields/Doc';
import { Utils, emptyFunction } from '../Utils';
import { DashUploadUtils } from './DashUploadUtils';
+import { Credentials } from 'google-auth-library';
export namespace Database {
@@ -240,21 +241,23 @@ export namespace Database {
}) : slice;
};
- const SanitizedSingletonQuery = async (query: { [key: string]: any }, collection: string, removeId = true) => {
+ const SanitizedSingletonQuery = async <T>(query: { [key: string]: any }, collection: string, removeId = true): Promise<Opt<T>> => {
const results = await SanitizedCappedQuery(query, collection, 1, removeId);
return results.length ? results[0] : undefined;
};
- export const QueryUploadHistory = async (contentSize: number): Promise<Opt<DashUploadUtils.UploadInformation>> => {
- return SanitizedSingletonQuery({ contentSize }, AuxiliaryCollections.GooglePhotosUploadHistory);
+ export const QueryUploadHistory = async (contentSize: number) => {
+ return SanitizedSingletonQuery<DashUploadUtils.UploadInformation>({ contentSize }, AuxiliaryCollections.GooglePhotosUploadHistory);
};
export namespace GoogleAuthenticationToken {
const GoogleAuthentication = "googleAuthentication";
+ export type StoredCredentials = Credentials & { _id: string };
+
export const Fetch = async (userId: string, removeId = true) => {
- return SanitizedSingletonQuery({ userId }, GoogleAuthentication, removeId);
+ return SanitizedSingletonQuery<StoredCredentials>({ userId }, GoogleAuthentication, removeId);
};
export const Write = async (userId: string, token: any) => {