aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client_secret.json1
-rw-r--r--client_secret.json.json1
-rw-r--r--src/client/DocServer.ts6
-rw-r--r--src/client/apis/youtube/YoutubeBox.tsx9
-rw-r--r--src/server/Message.ts6
-rw-r--r--src/server/Search.ts2
-rw-r--r--src/server/index.ts29
-rw-r--r--src/server/youtubeApi/youtubeApiSample.d.ts (renamed from src/client/apis/youtube/youtubeApiSample.d.ts)1
-rw-r--r--src/server/youtubeApi/youtubeApiSample.js (renamed from src/client/apis/youtube/youtubeApiSample.js)19
9 files changed, 41 insertions, 33 deletions
diff --git a/client_secret.json b/client_secret.json
new file mode 100644
index 000000000..a9c698421
--- /dev/null
+++ b/client_secret.json
@@ -0,0 +1 @@
+{"installed":{"client_id":"1005546247619-kqpnvh42mpa803tem8556b87umi4j9r0.apps.googleusercontent.com","project_id":"brown-dash","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"WshLb5TH9SdFVGGbQcnYj7IU","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}} \ No newline at end of file
diff --git a/client_secret.json.json b/client_secret.json.json
deleted file mode 100644
index 99dfbdf7b..000000000
--- a/client_secret.json.json
+++ /dev/null
@@ -1 +0,0 @@
-{"installed":{"client_id":"605555062960-ebbjrsv6ugkigpdoh6cdb3g6gmhdalnn.apps.googleusercontent.com","project_id":"dulcet-name-244817","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"3e8A9w5OJacQCGYIrHTu9ef2","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}} \ No newline at end of file
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index c9cbce78e..9dae54d74 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -1,5 +1,5 @@
import * as OpenSocket from 'socket.io-client';
-import { MessageStore } from "./../server/Message";
+import { MessageStore, YoutubeQueryTypes } from "./../server/Message";
import { Opt } from '../new_fields/Doc';
import { Utils, emptyFunction } from '../Utils';
import { SerializationHelper } from './util/SerializationHelper';
@@ -47,8 +47,8 @@ export namespace DocServer {
}
}
- export async function getYoutubeApiKey() {
- let apiKey = await Utils.EmitCallback(_socket, MessageStore.YoutubeApiKey, undefined);
+ export async function getYoutubeChannels() {
+ let apiKey = await Utils.EmitCallback(_socket, MessageStore.YoutubeApiQuery, YoutubeQueryTypes.Channels);
return apiKey;
}
diff --git a/src/client/apis/youtube/YoutubeBox.tsx b/src/client/apis/youtube/YoutubeBox.tsx
index ee190750f..b029c51ec 100644
--- a/src/client/apis/youtube/YoutubeBox.tsx
+++ b/src/client/apis/youtube/YoutubeBox.tsx
@@ -7,7 +7,6 @@ import { observer } from "mobx-react";
import { computed, reaction, IReactionDisposer } from 'mobx';
import { DocumentDecorations } from "../../views/DocumentDecorations";
import { InkingControl } from "../../views/InkingControl";
-import * as YoutubeApi from "./youtubeApiSample";
import { Utils } from "../../../Utils";
import { DocServer } from "../../DocServer";
@@ -15,14 +14,11 @@ import { DocServer } from "../../DocServer";
@observer
export class YoutubeBox extends React.Component<FieldViewProps> {
- private youtubeApiKey: string = "";
public static LayoutString() { return FieldView.LayoutString(YoutubeBox); }
- async componentWillMount() {
- let apiKey = await DocServer.getYoutubeApiKey();
- this.youtubeApiKey = apiKey;
- YoutubeApi.authorizedGetChannel(this.youtubeApiKey);
+ componentWillMount() {
+ DocServer.getYoutubeChannels();
}
_ignore = 0;
@@ -45,7 +41,6 @@ export class YoutubeBox extends React.Component<FieldViewProps> {
render() {
let field = this.props.Document[this.props.fieldKey];
let view;
- YoutubeApi.readFsFile();
if (field instanceof HtmlField) {
view = <span id="webBox-htmlSpan" dangerouslySetInnerHTML={{ __html: field.html }} />;
} else if (field instanceof WebField) {
diff --git a/src/server/Message.ts b/src/server/Message.ts
index ee9142222..0fc5dd4b5 100644
--- a/src/server/Message.ts
+++ b/src/server/Message.ts
@@ -24,6 +24,10 @@ export interface Transferable {
readonly data?: any;
}
+export enum YoutubeQueryTypes {
+ Channels
+}
+
export interface Reference {
readonly id: string;
}
@@ -45,5 +49,5 @@ export namespace MessageStore {
export const GetRefFields = new Message<string[]>("Get Ref Fields");
export const UpdateField = new Message<Diff>("Update Ref Field");
export const CreateField = new Message<Reference>("Create Ref Field");
- export const YoutubeApiKey = new Message<string>("Youtube Api Key");
+ export const YoutubeApiQuery = new Message<YoutubeQueryTypes>("Youtube Api Query");
}
diff --git a/src/server/Search.ts b/src/server/Search.ts
index 5ca5578a7..d776480c6 100644
--- a/src/server/Search.ts
+++ b/src/server/Search.ts
@@ -14,7 +14,7 @@ export class Search {
});
return res;
} catch (e) {
- console.warn("Search error: " + e + document);
+ // console.warn("Search error: " + e + document);
}
}
diff --git a/src/server/index.ts b/src/server/index.ts
index 2629519a7..b36cb0bf2 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -24,7 +24,7 @@ import { getForgot, getLogin, getLogout, getReset, getSignup, postForgot, postLo
import { DashUserModel } from './authentication/models/user_model';
import { Client } from './Client';
import { Database } from './database';
-import { MessageStore, Transferable, Types, Diff } from "./Message";
+import { MessageStore, Transferable, Types, Diff, YoutubeQueryTypes as YoutubeQueryType } from "./Message";
import { RouteStore } from './RouteStore';
const app = express();
const config = require('../../webpack.config');
@@ -37,15 +37,16 @@ import c = require("crypto");
import { Search } from './Search';
import { debug } from 'util';
import _ = require('lodash');
+import * as YoutubeApi from './youtubeApi/youtubeApiSample.js';
const MongoStore = require('connect-mongo')(session);
const mongoose = require('mongoose');
-//let fs = require('fs');
-let readline = require('readline');
-let { google } = require('googleapis');
-let OAuth2 = google.auth.OAuth2;
+// let { google } = require('googleapis');
+// let OAuth2 = google.auth.OAuth2;
const download = (url: string, dest: fs.PathLike) => request.get(url).pipe(fs.createWriteStream(dest));
+let youtubeApiKey: string;
+YoutubeApi.readApiKey((apiKey: string) => youtubeApiKey = apiKey);
const mongoUrl = 'mongodb://localhost:27017/Dash';
mongoose.connect(mongoUrl);
@@ -315,7 +316,7 @@ server.on("connection", function (socket: Socket) {
Utils.AddServerHandler(socket, MessageStore.DeleteAll, deleteFields);
Utils.AddServerHandler(socket, MessageStore.CreateField, CreateField);
- Utils.AddServerHandlerCallback(socket, MessageStore.YoutubeApiKey, GetYoutubeApiKey);
+ Utils.AddServerHandlerCallback(socket, MessageStore.YoutubeApiQuery, HandleYoutubeQuery);
Utils.AddServerHandler(socket, MessageStore.UpdateField, diff => UpdateField(socket, diff));
Utils.AddServerHandlerCallback(socket, MessageStore.GetRefField, GetRefField);
Utils.AddServerHandlerCallback(socket, MessageStore.GetRefFields, GetRefFields);
@@ -366,18 +367,14 @@ function GetRefFields([ids, callback]: [string[], (result?: Transferable[]) => v
Database.Instance.getDocuments(ids, callback, "newDocuments");
}
-function GetYoutubeApiKey(callback: (result?: string) => void) {
- // Load client secrets from a local file.
- fs.readFile('client_secret.json', function processClientSecrets(err: any, content: any) {
- if (err) {
- console.log('Error loading client secret file: ' + err);
- return;
- }
- callback(content);
- });
+function HandleYoutubeQuery([type, callback]: [YoutubeQueryType, (result?: string) => void]) {
+ switch (type) {
+ case YoutubeQueryType.Channels:
+ YoutubeApi.authorizedGetChannel(youtubeApiKey);
+ break;
+ }
}
-
const suffixMap: { [type: string]: (string | [string, string | ((json: any) => any)]) } = {
"number": "_n",
"string": "_t",
diff --git a/src/client/apis/youtube/youtubeApiSample.d.ts b/src/server/youtubeApi/youtubeApiSample.d.ts
index 87a669e36..427f54608 100644
--- a/src/client/apis/youtube/youtubeApiSample.d.ts
+++ b/src/server/youtubeApi/youtubeApiSample.d.ts
@@ -1,3 +1,2 @@
-
declare const YoutubeApi: any;
export = YoutubeApi; \ No newline at end of file
diff --git a/src/client/apis/youtube/youtubeApiSample.js b/src/server/youtubeApi/youtubeApiSample.js
index 7f14f2d3e..7d5c936f5 100644
--- a/src/client/apis/youtube/youtubeApiSample.js
+++ b/src/server/youtubeApi/youtubeApiSample.js
@@ -1,4 +1,7 @@
-import { Utils } from "tslint";
+const fs = require('fs');
+const readline = require('readline');
+const { google } = require('googleapis');
+const OAuth2 = google.auth.OAuth2;
// If modifying these scopes, delete your previously saved credentials
@@ -8,9 +11,19 @@ let TOKEN_DIR = (process.env.HOME || process.env.HOMEPATH ||
process.env.USERPROFILE) + '/.credentials/';
let TOKEN_PATH = TOKEN_DIR + 'youtube-nodejs-quickstart.json';
+module.exports.readApiKey = (callback) => {
+ fs.readFile('client_secret.json', function processClientSecrets(err, content) {
+ if (err) {
+ console.log('Error loading client secret file: ' + err);
+ return;
+ }
+ callback(content);
+ });
+}
-
-function authorizedGetChannel(apiKey) {
+module.exports.authorizedGetChannel = (apiKey) => {
+ //this didnt get called
+ console.log("I get called");
// Authorize a client with the loaded credentials, then call the YouTube API.
authorize(JSON.parse(apiKey), getChannel);
}