diff options
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/apis/google/GoogleApiServerUtils.ts | 2 | ||||
-rw-r--r-- | src/server/database.ts | 11 |
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) => { |