aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/util/CurrentUserUtils.ts (renamed from src/server/authentication/models/current_user_utils.ts)46
-rw-r--r--src/client/util/SettingsManager.tsx2
-rw-r--r--src/client/views/GestureOverlay.tsx2
-rw-r--r--src/client/views/InkingControl.tsx2
-rw-r--r--src/client/views/Main.tsx2
-rw-r--r--src/client/views/MainView.tsx2
-rw-r--r--src/client/views/collections/CollectionMapView.tsx13
-rw-r--r--src/client/views/collections/CollectionSubView.tsx2
-rw-r--r--src/client/views/collections/CollectionView.tsx2
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormRemoteCursors.tsx2
-rw-r--r--src/client/views/nodes/ColorBox.tsx2
-rw-r--r--src/mobile/ImageUpload.tsx3
-rw-r--r--src/mobile/MobileInterface.tsx4
-rw-r--r--src/server/ApiManagers/ApiManager.ts2
-rw-r--r--src/server/ApiManagers/DeleteManager.ts2
-rw-r--r--src/server/ApiManagers/GeneralGoogleManager.ts2
-rw-r--r--src/server/DashSession/DashSessionAgent.ts2
-rw-r--r--src/server/RouteManager.ts2
-rw-r--r--src/server/apis/google/CredentialsLoader.ts (renamed from src/server/credentials/CredentialsLoader.ts)0
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts10
-rw-r--r--src/server/apis/google/google_project_credentials.json (renamed from src/server/credentials/google_project_credentials.json)0
-rw-r--r--src/server/apis/youtube/youtubeApiSample.js22
-rw-r--r--src/server/authentication/AuthenticationManager.ts (renamed from src/server/authentication/controllers/user_controller.ts)8
-rw-r--r--src/server/authentication/DashUserModel.ts (renamed from src/server/authentication/models/user_model.ts)4
-rw-r--r--src/server/authentication/Passport.ts (renamed from src/server/authentication/config/passport.ts)2
-rw-r--r--src/server/database.ts78
-rw-r--r--src/server/index.ts7
-rw-r--r--src/server/server_Initialization.ts4
-rw-r--r--src/server/websocket.ts (renamed from src/server/Websocket/Websocket.ts)32
-rw-r--r--webpack.config.js27
30 files changed, 170 insertions, 118 deletions
diff --git a/src/server/authentication/models/current_user_utils.ts b/src/client/util/CurrentUserUtils.ts
index 1e98bbbd0..b67c3ea60 100644
--- a/src/server/authentication/models/current_user_utils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -1,27 +1,27 @@
-import { action, computed, observable, reaction } from "mobx";
+import { computed, observable, reaction } from "mobx";
import * as rp from 'request-promise';
-import { Utils } from "../../../Utils";
-import { DocServer } from "../../../client/DocServer";
-import { Docs, DocumentOptions } from "../../../client/documents/Documents";
-import { UndoManager } from "../../../client/util/UndoManager";
-import { Doc, DocListCast, DocListCastAsync } from "../../../new_fields/Doc";
-import { List } from "../../../new_fields/List";
-import { listSpec } from "../../../new_fields/Schema";
-import { ScriptField, ComputedField } from "../../../new_fields/ScriptField";
-import { Cast, PromiseValue, StrCast, NumCast } from "../../../new_fields/Types";
-import { nullAudio, ImageField } from "../../../new_fields/URLField";
-import { DragManager } from "../../../client/util/DragManager";
-import { InkingControl } from "../../../client/views/InkingControl";
-import { Scripting, CompileScript } from "../../../client/util/Scripting";
-import { CollectionViewType } from "../../../client/views/collections/CollectionView";
-import { makeTemplate } from "../../../client/util/DropConverter";
-import { RichTextField } from "../../../new_fields/RichTextField";
-import { PrefetchProxy } from "../../../new_fields/Proxy";
-import { FormattedTextBox } from "../../../client/views/nodes/formattedText/FormattedTextBox";
-import { MainView } from "../../../client/views/MainView";
-import { DocumentType } from "../../../client/documents/DocumentTypes";
-import { SchemaHeaderField } from "../../../new_fields/SchemaHeaderField";
-import { DimUnit } from "../../../client/views/collections/collectionMulticolumn/CollectionMulticolumnView";
+import { Utils } from "../../Utils";
+import { DocServer } from "../DocServer";
+import { Docs, DocumentOptions } from "../documents/Documents";
+import { UndoManager } from "./UndoManager";
+import { Doc, DocListCast, DocListCastAsync } from "../../new_fields/Doc";
+import { List } from "../../new_fields/List";
+import { listSpec } from "../../new_fields/Schema";
+import { ScriptField, ComputedField } from "../../new_fields/ScriptField";
+import { Cast, PromiseValue, StrCast, NumCast } from "../../new_fields/Types";
+import { nullAudio } from "../../new_fields/URLField";
+import { DragManager } from "./DragManager";
+import { InkingControl } from "../views/InkingControl";
+import { Scripting } from "./Scripting";
+import { CollectionViewType } from "../views/collections/CollectionView";
+import { makeTemplate } from "./DropConverter";
+import { RichTextField } from "../../new_fields/RichTextField";
+import { PrefetchProxy } from "../../new_fields/Proxy";
+import { FormattedTextBox } from "../views/nodes/formattedText/FormattedTextBox";
+import { MainView } from "../views/MainView";
+import { DocumentType } from "../documents/DocumentTypes";
+import { SchemaHeaderField } from "../../new_fields/SchemaHeaderField";
+import { DimUnit } from "../views/collections/collectionMulticolumn/CollectionMulticolumnView";
export class CurrentUserUtils {
private static curr_id: string;
diff --git a/src/client/util/SettingsManager.tsx b/src/client/util/SettingsManager.tsx
index e20434461..0e15197c4 100644
--- a/src/client/util/SettingsManager.tsx
+++ b/src/client/util/SettingsManager.tsx
@@ -8,7 +8,7 @@ import { SelectionManager } from "./SelectionManager";
import "./SettingsManager.scss";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Networking } from "../Network";
-import { CurrentUserUtils } from "../../server/authentication/models/current_user_utils";
+import { CurrentUserUtils } from "./CurrentUserUtils";
import { Utils } from "../../Utils";
library.add(fa.faWindowClose);
diff --git a/src/client/views/GestureOverlay.tsx b/src/client/views/GestureOverlay.tsx
index 4f8f9ed69..812ff3b93 100644
--- a/src/client/views/GestureOverlay.tsx
+++ b/src/client/views/GestureOverlay.tsx
@@ -13,7 +13,7 @@ import { DocUtils, Docs } from "../documents/Documents";
import { undoBatch } from "../util/UndoManager";
import { Scripting } from "../util/Scripting";
import { FieldValue, Cast, NumCast, BoolCast } from "../../new_fields/Types";
-import { CurrentUserUtils } from "../../server/authentication/models/current_user_utils";
+import { CurrentUserUtils } from "../util/CurrentUserUtils";
import HorizontalPalette from "./Palette";
import { Utils, emptyPath, emptyFunction, returnFalse, returnOne, returnEmptyString, returnTrue, numberRange, returnZero } from "../../Utils";
import { DocumentView } from "./nodes/DocumentView";
diff --git a/src/client/views/InkingControl.tsx b/src/client/views/InkingControl.tsx
index 81d99e009..af9c4a562 100644
--- a/src/client/views/InkingControl.tsx
+++ b/src/client/views/InkingControl.tsx
@@ -3,7 +3,7 @@ import { ColorState } from 'react-color';
import { Doc } from "../../new_fields/Doc";
import { InkTool } from "../../new_fields/InkField";
import { FieldValue, NumCast, StrCast } from "../../new_fields/Types";
-import { CurrentUserUtils } from "../../server/authentication/models/current_user_utils";
+import { CurrentUserUtils } from "../util/CurrentUserUtils";
import { Scripting } from "../util/Scripting";
import { SelectionManager } from "../util/SelectionManager";
import { undoBatch } from "../util/UndoManager";
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index b21eb9c8f..17c001971 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -1,6 +1,6 @@
import { MainView } from "./MainView";
import { Docs } from "../documents/Documents";
-import { CurrentUserUtils } from "../../server/authentication/models/current_user_utils";
+import { CurrentUserUtils } from "../util/CurrentUserUtils";
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { DocServer } from "../DocServer";
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 9bfef06b4..9bc08de3e 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -19,7 +19,7 @@ import { List } from '../../new_fields/List';
import { listSpec } from '../../new_fields/Schema';
import { BoolCast, Cast, FieldValue, StrCast } from '../../new_fields/Types';
import { TraceMobx } from '../../new_fields/util';
-import { CurrentUserUtils } from '../../server/authentication/models/current_user_utils';
+import { CurrentUserUtils } from '../util/CurrentUserUtils';
import { emptyFunction, emptyPath, returnFalse, returnOne, returnZero, returnTrue, Utils } from '../../Utils';
import GoogleAuthenticationManager from '../apis/GoogleAuthenticationManager';
import { DocServer } from '../DocServer';
diff --git a/src/client/views/collections/CollectionMapView.tsx b/src/client/views/collections/CollectionMapView.tsx
index 13c06b0a3..618285293 100644
--- a/src/client/views/collections/CollectionMapView.tsx
+++ b/src/client/views/collections/CollectionMapView.tsx
@@ -1,4 +1,4 @@
-import { GoogleApiWrapper, Map as GeoMap, IMapProps, Marker } from "google-maps-react";
+import { GoogleApiWrapper, Map as GeoMap, MapProps as IMapProps, Marker } from "google-maps-react";
import { observer } from "mobx-react";
import { Doc, Opt, DocListCast, FieldResult, Field } from "../../../new_fields/Doc";
import { documentSchema } from "../../../new_fields/documentSchemas";
@@ -47,7 +47,7 @@ class CollectionMapView extends CollectionSubView<MapSchema, Partial<IMapProps>
private _cancelAddrReq = new Map<string, boolean>();
private _cancelLocReq = new Map<string, boolean>();
private _initialLookupPending = new Map<string, boolean>();
- private responders: { location: Lambda, address: Lambda }[] = [];
+ private responders: { locationDisposer: Lambda, addressDisposer: Lambda }[] = [];
/**
* Note that all the uses of runInAction below are not included
@@ -176,13 +176,16 @@ class CollectionMapView extends CollectionSubView<MapSchema, Partial<IMapProps>
}
@computed get reactiveContents() {
- this.responders.forEach(({ location, address }) => { location(); address(); });
+ this.responders.forEach(({ locationDisposer, addressDisposer }) => {
+ locationDisposer();
+ addressDisposer();
+ });
this.responders = [];
return this.childLayoutPairs.map(({ layout }) => {
const fieldKey = Doc.LayoutFieldKey(layout);
const id = layout[Id];
this.responders.push({
- location: computed(() => ({ lat: layout[`${fieldKey}-lat`], lng: layout[`${fieldKey}-lng`] }))
+ locationDisposer: computed(() => ({ lat: layout[`${fieldKey}-lat`], lng: layout[`${fieldKey}-lng`] }))
.observe(({ oldValue, newValue }) => {
if (this._cancelLocReq.get(id)) {
this._cancelLocReq.set(id, false);
@@ -190,7 +193,7 @@ class CollectionMapView extends CollectionSubView<MapSchema, Partial<IMapProps>
this.respondToLocationChange(layout, fieldKey, newValue, oldValue);
}
}),
- address: computed(() => Cast(layout[`${fieldKey}-address`], "string", null))
+ addressDisposer: computed(() => Cast(layout[`${fieldKey}-address`], "string", null))
.observe(({ oldValue, newValue }) => {
if (this._cancelAddrReq.get(id)) {
this._cancelAddrReq.set(id, false);
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 8b50bd8fc..bff6d121b 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -8,7 +8,7 @@ import { listSpec } from "../../../new_fields/Schema";
import { ScriptField } from "../../../new_fields/ScriptField";
import { Cast, ScriptCast } from "../../../new_fields/Types";
import { GestureUtils } from "../../../pen-gestures/GestureUtils";
-import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils";
+import { CurrentUserUtils } from "../../util/CurrentUserUtils";
import { Upload } from "../../../server/SharedMediaTypes";
import { Utils } from "../../../Utils";
import { GooglePhotos } from "../../apis/google_docs/GooglePhotosClientUtils";
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 0f239d385..4b3b2e234 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -35,7 +35,7 @@ import { CollectionTimeView } from './CollectionTimeView';
import { CollectionTreeView } from "./CollectionTreeView";
import './CollectionView.scss';
import { CollectionViewBaseChrome } from './CollectionViewChromes';
-import { CurrentUserUtils } from '../../../server/authentication/models/current_user_utils';
+import { CurrentUserUtils } from '../../util/CurrentUserUtils';
import { Id } from '../../../new_fields/FieldSymbols';
import { listSpec } from '../../../new_fields/Schema';
import { Docs } from '../../documents/Documents';
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormRemoteCursors.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormRemoteCursors.tsx
index 92fa2781c..9a5b2c27c 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormRemoteCursors.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormRemoteCursors.tsx
@@ -3,7 +3,7 @@ import * as mobxUtils from 'mobx-utils';
import CursorField from "../../../../new_fields/CursorField";
import { listSpec } from "../../../../new_fields/Schema";
import { Cast } from "../../../../new_fields/Types";
-import { CurrentUserUtils } from "../../../../server/authentication/models/current_user_utils";
+import { CurrentUserUtils } from "../../../util/CurrentUserUtils";
import { CollectionViewProps } from "../CollectionSubView";
import "./CollectionFreeFormView.scss";
import React = require("react");
diff --git a/src/client/views/nodes/ColorBox.tsx b/src/client/views/nodes/ColorBox.tsx
index 7ab6d99c2..bc84204b9 100644
--- a/src/client/views/nodes/ColorBox.tsx
+++ b/src/client/views/nodes/ColorBox.tsx
@@ -4,7 +4,7 @@ import { SketchPicker } from 'react-color';
import { documentSchema } from "../../../new_fields/documentSchemas";
import { makeInterface } from "../../../new_fields/Schema";
import { StrCast } from "../../../new_fields/Types";
-import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils";
+import { CurrentUserUtils } from "../../util/CurrentUserUtils";
import { SelectionManager } from "../../util/SelectionManager";
import { ViewBoxBaseComponent } from "../DocComponent";
import { InkingControl } from "../InkingControl";
diff --git a/src/mobile/ImageUpload.tsx b/src/mobile/ImageUpload.tsx
index 295e82142..f30e9869a 100644
--- a/src/mobile/ImageUpload.tsx
+++ b/src/mobile/ImageUpload.tsx
@@ -12,8 +12,7 @@ import { observer } from 'mobx-react';
import { observable } from 'mobx';
import { Utils } from '../Utils';
import MobileInterface from './MobileInterface';
-import { CurrentUserUtils } from '../server/authentication/models/current_user_utils';
-import { Scripting } from '../client/util/Scripting';
+import { CurrentUserUtils } from '../client/util/CurrentUserUtils';
diff --git a/src/mobile/MobileInterface.tsx b/src/mobile/MobileInterface.tsx
index 69a80e1b4..9d4d58ad1 100644
--- a/src/mobile/MobileInterface.tsx
+++ b/src/mobile/MobileInterface.tsx
@@ -10,7 +10,6 @@ import { DocumentManager } from '../client/util/DocumentManager';
import RichTextMenu from '../client/views/nodes/formattedText/RichTextMenu';
import { Scripting } from '../client/util/Scripting';
import { Transform } from '../client/util/Transform';
-import { CollectionView } from '../client/views/collections/CollectionView';
import { DocumentDecorations } from '../client/views/DocumentDecorations';
import GestureOverlay from '../client/views/GestureOverlay';
import { InkingControl } from '../client/views/InkingControl';
@@ -23,9 +22,10 @@ import { InkTool } from '../new_fields/InkField';
import { listSpec } from '../new_fields/Schema';
import { Cast, FieldValue } from '../new_fields/Types';
import { WebField } from "../new_fields/URLField";
-import { CurrentUserUtils } from '../server/authentication/models/current_user_utils';
+import { CurrentUserUtils } from '../client/util/CurrentUserUtils';
import { emptyFunction, emptyPath, returnEmptyString, returnFalse, returnOne, returnTrue, returnZero } from '../Utils';
import "./MobileInterface.scss";
+import { CollectionView } from '../client/views/collections/CollectionView';
library.add(faLongArrowAltLeft);
diff --git a/src/server/ApiManagers/ApiManager.ts b/src/server/ApiManagers/ApiManager.ts
index e2b01d585..27e9de065 100644
--- a/src/server/ApiManagers/ApiManager.ts
+++ b/src/server/ApiManagers/ApiManager.ts
@@ -1,4 +1,4 @@
-import RouteManager, { RouteInitializer } from "../RouteManager";
+import { RouteInitializer } from "../RouteManager";
export type Registration = (initializer: RouteInitializer) => void;
diff --git a/src/server/ApiManagers/DeleteManager.ts b/src/server/ApiManagers/DeleteManager.ts
index bd80d6500..7fbb37658 100644
--- a/src/server/ApiManagers/DeleteManager.ts
+++ b/src/server/ApiManagers/DeleteManager.ts
@@ -1,6 +1,6 @@
import ApiManager, { Registration } from "./ApiManager";
import { Method, _permission_denied } from "../RouteManager";
-import { WebSocket } from "../Websocket/Websocket";
+import { WebSocket } from "../websocket";
import { Database } from "../database";
import rimraf = require("rimraf");
import { filesDirectory } from "..";
diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts
index 17968cc7d..f94b77cac 100644
--- a/src/server/ApiManagers/GeneralGoogleManager.ts
+++ b/src/server/ApiManagers/GeneralGoogleManager.ts
@@ -38,7 +38,7 @@ export default class GeneralGoogleManager extends ApiManager {
method: Method.GET,
subscription: "/revokeGoogleAccessToken",
secureHandler: async ({ user, res }) => {
- await Database.Auxiliary.GoogleAuthenticationToken.Revoke(user.id);
+ await Database.Auxiliary.GoogleAccessToken.Revoke(user.id);
res.send();
}
});
diff --git a/src/server/DashSession/DashSessionAgent.ts b/src/server/DashSession/DashSessionAgent.ts
index ef9b88541..ab3dfffcc 100644
--- a/src/server/DashSession/DashSessionAgent.ts
+++ b/src/server/DashSession/DashSessionAgent.ts
@@ -2,7 +2,7 @@ import { Email, pathFromRoot } from "../ActionUtilities";
import { red, yellow, green, cyan } from "colors";
import { get } from "request-promise";
import { Utils } from "../../Utils";
-import { WebSocket } from "../Websocket/Websocket";
+import { WebSocket } from "../websocket";
import { MessageStore } from "../Message";
import { launchServer, onWindows } from "..";
import { readdirSync, statSync, createWriteStream, readFileSync, unlinkSync } from "fs";
diff --git a/src/server/RouteManager.ts b/src/server/RouteManager.ts
index 80e4a6741..b23215996 100644
--- a/src/server/RouteManager.ts
+++ b/src/server/RouteManager.ts
@@ -1,5 +1,5 @@
import RouteSubscriber from "./RouteSubscriber";
-import { DashUserModel } from "./authentication/models/user_model";
+import { DashUserModel } from "./authentication/DashUserModel";
import { Request, Response, Express } from 'express';
import { cyan, red, green } from 'colors';
diff --git a/src/server/credentials/CredentialsLoader.ts b/src/server/apis/google/CredentialsLoader.ts
index e3f4d167b..e3f4d167b 100644
--- a/src/server/credentials/CredentialsLoader.ts
+++ b/src/server/apis/google/CredentialsLoader.ts
diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts
index 48a8da89f..2e4811c86 100644
--- a/src/server/apis/google/GoogleApiServerUtils.ts
+++ b/src/server/apis/google/GoogleApiServerUtils.ts
@@ -3,9 +3,9 @@ import { OAuth2Client, Credentials, OAuth2ClientOptions } from "google-auth-libr
import { Opt } from "../../../new_fields/Doc";
import { GaxiosResponse } from "gaxios";
import request = require('request-promise');
-import * as qs from 'query-string';
+import * as qs from "query-string";
import { Database } from "../../database";
-import { GoogleCredentialsLoader } from "../../credentials/CredentialsLoader";
+import { GoogleCredentialsLoader } from "./CredentialsLoader";
/**
* Scopes give Google users fine granularity of control
@@ -224,7 +224,7 @@ export namespace GoogleApiServerUtils {
});
});
const enriched = injectUserInfo(credentials);
- await Database.Auxiliary.GoogleAuthenticationToken.Write(userId, enriched);
+ await Database.Auxiliary.GoogleAccessToken.Write(userId, enriched);
return enriched;
}
@@ -280,7 +280,7 @@ export namespace GoogleApiServerUtils {
* and a flag indicating whether or not they were refreshed during retrieval
*/
export async function retrieveCredentials(userId: string): Promise<{ credentials: Opt<EnrichedCredentials>, refreshed: boolean }> {
- let credentials = await Database.Auxiliary.GoogleAuthenticationToken.Fetch(userId);
+ let credentials = await Database.Auxiliary.GoogleAccessToken.Fetch(userId);
let refreshed = false;
if (!credentials) {
return { credentials: undefined, refreshed };
@@ -318,7 +318,7 @@ export namespace GoogleApiServerUtils {
});
// expires_in is in seconds, but we're building the new expiry date in milliseconds
const expiry_date = new Date().getTime() + (expires_in * 1000);
- await Database.Auxiliary.GoogleAuthenticationToken.Update(userId, access_token, expiry_date);
+ await Database.Auxiliary.GoogleAccessToken.Update(userId, access_token, expiry_date);
// update the relevant properties
credentials.access_token = access_token;
credentials.expiry_date = expiry_date;
diff --git a/src/server/credentials/google_project_credentials.json b/src/server/apis/google/google_project_credentials.json
index 955c5a3c1..955c5a3c1 100644
--- a/src/server/credentials/google_project_credentials.json
+++ b/src/server/apis/google/google_project_credentials.json
diff --git a/src/server/apis/youtube/youtubeApiSample.js b/src/server/apis/youtube/youtubeApiSample.js
index 50b3c7b38..d535bd9ff 100644
--- a/src/server/apis/youtube/youtubeApiSample.js
+++ b/src/server/apis/youtube/youtubeApiSample.js
@@ -1,6 +1,8 @@
const fs = require('fs');
const readline = require('readline');
-const { google } = require('googleapis');
+const {
+ google
+} = require('googleapis');
const OAuth2 = google.auth.OAuth2;
@@ -19,21 +21,27 @@ module.exports.readApiKey = (callback) => {
}
callback(content);
});
-}
+};
module.exports.authorizedGetChannel = (apiKey) => {
//this didnt get called
// Authorize a client with the loaded credentials, then call the YouTube API.
authorize(JSON.parse(apiKey), getChannel);
-}
+};
module.exports.authorizedGetVideos = (apiKey, userInput, callBack) => {
- authorize(JSON.parse(apiKey), getVideos, { userInput: userInput, callBack: callBack });
-}
+ authorize(JSON.parse(apiKey), getVideos, {
+ userInput: userInput,
+ callBack: callBack
+ });
+};
module.exports.authorizedGetVideoDetails = (apiKey, videoIds, callBack) => {
- authorize(JSON.parse(apiKey), getVideoDetails, { videoIds: videoIds, callBack: callBack });
-}
+ authorize(JSON.parse(apiKey), getVideoDetails, {
+ videoIds: videoIds,
+ callBack: callBack
+ });
+};
/**
diff --git a/src/server/authentication/controllers/user_controller.ts b/src/server/authentication/AuthenticationManager.ts
index f0086d4ea..00f1fe44e 100644
--- a/src/server/authentication/controllers/user_controller.ts
+++ b/src/server/authentication/AuthenticationManager.ts
@@ -1,13 +1,13 @@
-import { default as User, DashUserModel, AuthToken } from "../models/user_model";
+import { default as User, DashUserModel } from "./DashUserModel";
import { Request, Response, NextFunction } from "express";
import * as passport from "passport";
import { IVerifyOptions } from "passport-local";
-import "../config/passport";
+import "./Passport";
import flash = require("express-flash");
import * as async from 'async';
import * as nodemailer from 'nodemailer';
import c = require("crypto");
-import { Utils } from "../../../Utils";
+import { Utils } from "../../Utils";
import { MailOptions } from "nodemailer/lib/stream-transport";
/**
@@ -111,7 +111,7 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => {
return res.redirect("/signup");
}
- passport.authenticate("local", (err: Error, user: DashUserModel, info: IVerifyOptions) => {
+ passport.authenticate("local", (err: Error, user: DashUserModel, _info: IVerifyOptions) => {
if (err) { next(err); return; }
if (!user) {
return res.redirect("/signup");
diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/DashUserModel.ts
index a0b688328..51d920a8f 100644
--- a/src/server/authentication/models/user_model.ts
+++ b/src/server/authentication/DashUserModel.ts
@@ -58,11 +58,11 @@ userSchema.pre("save", function save(next) {
if (!user.isModified("password")) {
return next();
}
- bcrypt.genSalt(10, (err, salt) => {
+ bcrypt.genSalt(10, (err: any, salt: string) => {
if (err) {
return next(err);
}
- bcrypt.hash(user.password, salt, () => void {}, (err: mongoose.Error, hash) => {
+ bcrypt.hash(user.password, salt, () => void {}, (err: mongoose.Error, hash: string) => {
if (err) {
return next(err);
}
diff --git a/src/server/authentication/config/passport.ts b/src/server/authentication/Passport.ts
index 286209b20..9b0069414 100644
--- a/src/server/authentication/config/passport.ts
+++ b/src/server/authentication/Passport.ts
@@ -1,6 +1,6 @@
import * as passport from 'passport';
import * as passportLocal from 'passport-local';
-import { default as User } from '../models/user_model';
+import { default as User } from './DashUserModel';
const LocalStrategy = passportLocal.Strategy;
diff --git a/src/server/database.ts b/src/server/database.ts
index 580f7f919..ed9a246e3 100644
--- a/src/server/database.ts
+++ b/src/server/database.ts
@@ -293,13 +293,26 @@ export namespace Database {
export const Instance = getDatabase();
+ /**
+ * Provides definitions and apis for working with
+ * portions of the database not dedicated to storing documents
+ * or Dash-internal user data.
+ */
export namespace Auxiliary {
+ /**
+ * All the auxiliary MongoDB collections (schemas)
+ */
export enum AuxiliaryCollections {
GooglePhotosUploadHistory = "uploadedFromGooglePhotos",
- GoogleAuthentication = "googleAuthentication"
+ GoogleAccess = "googleAuthentication"
}
+ /**
+ * Searches for the @param query in the specified @param collection,
+ * and returns at most the first @param cap results. If @param removeId is true,
+ * as it is by default, each object will be stripped of its database id.
+ */
const SanitizedCappedQuery = async (query: { [key: string]: any }, collection: string, cap: number, removeId = true) => {
const cursor = await Instance.query(query, undefined, collection);
const results = await cursor.toArray();
@@ -310,52 +323,89 @@ export namespace Database {
}) : slice;
};
+ /**
+ * Searches for the @param query in the specified @param collection,
+ * and returns at most the first result. If @param removeId is true,
+ * as it is by default, each object will be stripped of its database id.
+ * Worth the special case since it converts the Array return type to a single
+ * object of the specified type.
+ */
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;
};
+ /**
+ * Checks to see if an image with the given @param contentSize
+ * already exists in the aux database, i.e. has already been downloaded from Google Photos.
+ */
export const QueryUploadHistory = async (contentSize: number) => {
return SanitizedSingletonQuery<Upload.ImageInformation>({ contentSize }, AuxiliaryCollections.GooglePhotosUploadHistory);
};
- export namespace GoogleAuthenticationToken {
+ /**
+ * Records the uploading of the image with the given @param information,
+ * using the given content size as a seed for the database id.
+ */
+ export const LogUpload = async (information: Upload.ImageInformation) => {
+ const bundle = {
+ _id: Utils.GenerateDeterministicGuid(String(information.contentSize)),
+ ...information
+ };
+ return Instance.insert(bundle, AuxiliaryCollections.GooglePhotosUploadHistory);
+ };
+
+ /**
+ * Manages the storage, retrieval and updating of the access token that
+ * facilitates interactions with all their APIs for a given account.
+ */
+ export namespace GoogleAccessToken {
+ /**
+ * Format stored in database.
+ */
type StoredCredentials = GoogleApiServerUtils.EnrichedCredentials & { _id: string };
+ /**
+ * Retrieves the credentials associaed with @param userId
+ * and optionally removes their database id according to @param removeId.
+ */
export const Fetch = async (userId: string, removeId = true): Promise<Opt<StoredCredentials>> => {
- return SanitizedSingletonQuery<StoredCredentials>({ userId }, AuxiliaryCollections.GoogleAuthentication, removeId);
+ return SanitizedSingletonQuery<StoredCredentials>({ userId }, AuxiliaryCollections.GoogleAccess, removeId);
};
+ /**
+ * Writes the @param enrichedCredentials to the database, associated
+ * with @param userId for later retrieval and updating.
+ */
export const Write = async (userId: string, enrichedCredentials: GoogleApiServerUtils.EnrichedCredentials) => {
- return Instance.insert({ userId, canAccess: [], ...enrichedCredentials }, AuxiliaryCollections.GoogleAuthentication);
+ return Instance.insert({ userId, canAccess: [], ...enrichedCredentials }, AuxiliaryCollections.GoogleAccess);
};
+ /**
+ * Updates the @param access_token and @param expiry_date fields
+ * in the stored credentials associated with @param userId.
+ */
export const Update = async (userId: string, access_token: string, expiry_date: number) => {
const entry = await Fetch(userId, false);
if (entry) {
const parameters = { $set: { access_token, expiry_date } };
- return Instance.update(entry._id, parameters, emptyFunction, true, AuxiliaryCollections.GoogleAuthentication);
+ return Instance.update(entry._id, parameters, emptyFunction, true, AuxiliaryCollections.GoogleAccess);
}
};
+ /**
+ * Revokes the credentials associated with @param userId.
+ */
export const Revoke = async (userId: string) => {
const entry = await Fetch(userId, false);
if (entry) {
- Instance.delete({ _id: entry._id }, AuxiliaryCollections.GoogleAuthentication);
+ Instance.delete({ _id: entry._id }, AuxiliaryCollections.GoogleAccess);
}
};
}
- export const LogUpload = async (information: Upload.ImageInformation) => {
- const bundle = {
- _id: Utils.GenerateDeterministicGuid(String(information.contentSize)),
- ...information
- };
- return Instance.insert(bundle, AuxiliaryCollections.GooglePhotosUploadHistory);
- };
-
}
}
diff --git a/src/server/index.ts b/src/server/index.ts
index f26c8a6ab..af8f95a5e 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -11,9 +11,9 @@ import * as qs from 'query-string';
import UtilManager from './ApiManagers/UtilManager';
import { SearchManager } from './ApiManagers/SearchManager';
import UserManager from './ApiManagers/UserManager';
-import { WebSocket } from './Websocket/Websocket';
+import { WebSocket } from './websocket';
import DownloadManager from './ApiManagers/DownloadManager';
-import { GoogleCredentialsLoader } from './credentials/CredentialsLoader';
+import { GoogleCredentialsLoader } from './apis/google/CredentialsLoader';
import DeleteManager from "./ApiManagers/DeleteManager";
import PDFManager from "./ApiManagers/PDFManager";
import UploadManager from "./ApiManagers/UploadManager";
@@ -25,7 +25,6 @@ import { yellow } from "colors";
import { DashSessionAgent } from "./DashSession/DashSessionAgent";
import SessionManager from "./ApiManagers/SessionManager";
import { AppliedSessionAgent } from "./DashSession/Session/agents/applied_session_agent";
-import { Utils } from "../Utils";
export const onWindows = process.platform === "win32";
export let sessionAgent: AppliedSessionAgent;
@@ -125,7 +124,7 @@ function routeSetter({ isRelease, addSupervisedRoute, logRegistrationOutcome }:
// initialize the web socket (bidirectional communication: if a user changes
// a field on one client, that change must be broadcast to all other clients)
- WebSocket.start(isRelease);
+ WebSocket.initialize(isRelease);
}
diff --git a/src/server/server_Initialization.ts b/src/server/server_Initialization.ts
index add607761..4b3094616 100644
--- a/src/server/server_Initialization.ts
+++ b/src/server/server_Initialization.ts
@@ -7,7 +7,7 @@ import * as cookieParser from 'cookie-parser';
import expressFlash = require('express-flash');
import flash = require('connect-flash');
import { Database } from './database';
-import { getForgot, getLogin, getLogout, getReset, getSignup, postForgot, postLogin, postReset, postSignup } from './authentication/controllers/user_controller';
+import { getForgot, getLogin, getLogout, getReset, getSignup, postForgot, postLogin, postReset, postSignup } from './authentication/AuthenticationManager';
const MongoStore = require('connect-mongo')(session);
import RouteManager from './RouteManager';
import * as webpack from 'webpack';
@@ -94,6 +94,8 @@ function determineEnvironment() {
const label = isRelease ? "release" : "development";
console.log(`\nrunning server in ${color(label)} mode`);
+ // swilkins: I don't think we need to read from ClientUtils.RELEASE anymore. Should be able to invoke process.env.RELEASE
+ // on the client side, thanks to dotenv in webpack.config.js
let clientUtils = fs.readFileSync("./src/client/util/ClientUtils.ts.temp", "utf8");
clientUtils = `//AUTO-GENERATED FILE: DO NOT EDIT\n${clientUtils.replace('"mode"', String(isRelease))}`;
fs.writeFileSync("./src/client/util/ClientUtils.ts", clientUtils, "utf8");
diff --git a/src/server/Websocket/Websocket.ts b/src/server/websocket.ts
index 844535056..7278bdc32 100644
--- a/src/server/Websocket/Websocket.ts
+++ b/src/server/websocket.ts
@@ -1,18 +1,18 @@
-import { Utils } from "../../Utils";
-import { MessageStore, Transferable, Types, Diff, YoutubeQueryInput, YoutubeQueryTypes, GestureContent, MobileInkOverlayContent, UpdateMobileInkOverlayPositionContent, MobileDocumentUploadContent, RoomMessage } from "../Message";
-import { Client } from "../Client";
+import { Utils } from "../Utils";
+import { MessageStore, Transferable, Types, Diff, YoutubeQueryInput, YoutubeQueryTypes, GestureContent, MobileInkOverlayContent, UpdateMobileInkOverlayPositionContent, MobileDocumentUploadContent, RoomMessage } from "./Message";
+import { Client } from "./Client";
import { Socket } from "socket.io";
-import { Database } from "../database";
-import { Search } from "../Search";
+import { Database } from "./database";
+import { Search } from "./Search";
import * as io from 'socket.io';
-import YoutubeApi from "../apis/youtube/youtubeApiSample";
-import { GoogleCredentialsLoader } from "../credentials/CredentialsLoader";
-import { logPort } from "../ActionUtilities";
-import { timeMap } from "../ApiManagers/UserManager";
+import YoutubeApi from "./apis/youtube/youtubeApiSample";
+import { GoogleCredentialsLoader } from "./apis/google/CredentialsLoader";
+import { logPort } from "./ActionUtilities";
+import { timeMap } from "./ApiManagers/UserManager";
import { green } from "colors";
import { networkInterfaces } from "os";
-import executeImport from "../../scraping/buxton/final/BuxtonImporter";
-import { DocumentsCollection } from "../IDatabase";
+import executeImport from "../scraping/buxton/final/BuxtonImporter";
+import { DocumentsCollection } from "./IDatabase";
export namespace WebSocket {
@@ -21,15 +21,7 @@ export namespace WebSocket {
export const socketMap = new Map<SocketIO.Socket, string>();
export let disconnect: Function;
-
- export async function start(isRelease: boolean) {
- await preliminaryFunctions();
- initialize(isRelease);
- }
-
- async function preliminaryFunctions() {
- }
- function initialize(isRelease: boolean) {
+ export function initialize(isRelease: boolean) {
const endpoint = io();
endpoint.on("connection", function (socket: Socket) {
_socket = socket;
diff --git a/webpack.config.js b/webpack.config.js
index 6265883fd..67d492e1f 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -16,22 +16,21 @@ const plugins = [
new webpack.HotModuleReplacementPlugin(),
];
-const dotenv = require('dotenv');
-
-function transferEnvironmentVariables() {
+(function transferEnvironmentVariables() {
const prefix = "_CLIENT_";
- const env = dotenv.config().parsed;
- if (env) {
- plugins.push(new webpack.DefinePlugin(Object.keys(env).reduce((mapping, envKey) => {
- if (envKey.startsWith(prefix)) {
- mapping[`process.env.${envKey.replace(prefix, "")}`] = JSON.stringify(env[envKey]);
- }
- return mapping;
- }, {})));
+ const {
+ parsed
+ } = require('dotenv').config();
+ if (!parsed) {
+ return;
}
-}
-
-transferEnvironmentVariables();
+ plugins.push(new webpack.DefinePlugin(Object.keys(parsed).reduce((mapping, envKey) => {
+ if (envKey.startsWith(prefix)) {
+ mapping[`process.env.${envKey.replace(prefix, "")}`] = JSON.stringify(parsed[envKey]);
+ }
+ return mapping;
+ }, {})));
+})();
module.exports = {
mode: 'development',