From 21bc14319013e4757ca24f56a685b7d75eaa259a Mon Sep 17 00:00:00 2001 From: Mohammad Amoush Date: Wed, 26 Jun 2019 19:15:50 -0400 Subject: Searching through document for a youtube video done --- src/server/Message.ts | 7 ++++++- src/server/index.ts | 8 ++++---- src/server/youtubeApi/youtubeApiSample.js | 12 ++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src/server') diff --git a/src/server/Message.ts b/src/server/Message.ts index 87bb9d0fc..7b208dee9 100644 --- a/src/server/Message.ts +++ b/src/server/Message.ts @@ -28,6 +28,11 @@ export enum YoutubeQueryTypes { Channels, SearchVideo } +export interface YoutubeQueryInput { + readonly type: YoutubeQueryTypes; + readonly userInput?: string; +} + export interface Reference { readonly id: string; } @@ -49,5 +54,5 @@ export namespace MessageStore { export const GetRefFields = new Message("Get Ref Fields"); export const UpdateField = new Message("Update Ref Field"); export const CreateField = new Message("Create Ref Field"); - export const YoutubeApiQuery = new Message("Youtube Api Query"); + export const YoutubeApiQuery = new Message("Youtube Api Query"); } diff --git a/src/server/index.ts b/src/server/index.ts index 3d4f59ee4..9faeee381 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, YoutubeQueryTypes as YoutubeQueryType } from "./Message"; +import { MessageStore, Transferable, Types, Diff, YoutubeQueryTypes as YoutubeQueryType, YoutubeQueryInput } from "./Message"; import { RouteStore } from './RouteStore'; const app = express(); const config = require('../../webpack.config'); @@ -367,13 +367,13 @@ function GetRefFields([ids, callback]: [string[], (result?: Transferable[]) => v Database.Instance.getDocuments(ids, callback, "newDocuments"); } -function HandleYoutubeQuery([type, callback]: [YoutubeQueryType, (result?: string) => void]) { - switch (type) { +function HandleYoutubeQuery([query, callback]: [YoutubeQueryInput, (result?: string) => void]) { + switch (query.type) { case YoutubeQueryType.Channels: YoutubeApi.authorizedGetChannel(youtubeApiKey); break; case YoutubeQueryType.SearchVideo: - YoutubeApi.authorizedGetVideos(youtubeApiKey); + YoutubeApi.authorizedGetVideos(youtubeApiKey, query.userInput); } } diff --git a/src/server/youtubeApi/youtubeApiSample.js b/src/server/youtubeApi/youtubeApiSample.js index 35d74c62f..cd2e89cae 100644 --- a/src/server/youtubeApi/youtubeApiSample.js +++ b/src/server/youtubeApi/youtubeApiSample.js @@ -29,8 +29,8 @@ module.exports.authorizedGetChannel = (apiKey) => { authorize(JSON.parse(apiKey), getChannel); } -module.exports.authorizedGetVideos = (apiKey) => { - authorize(JSON.parse(apiKey), getSampleVideos); +module.exports.authorizedGetVideos = (apiKey, userInput) => { + authorize(JSON.parse(apiKey), getSampleVideos, { userInput: userInput }); } @@ -41,7 +41,7 @@ module.exports.authorizedGetVideos = (apiKey) => { * @param {Object} credentials The authorization client credentials. * @param {function} callback The callback to call with the authorized client. */ -function authorize(credentials, callback) { +function authorize(credentials, callback, args = {}) { let clientSecret = credentials.installed.client_secret; let clientId = credentials.installed.client_id; let redirectUrl = credentials.installed.redirect_uris[0]; @@ -53,7 +53,7 @@ function authorize(credentials, callback) { getNewToken(oauth2Client, callback); } else { oauth2Client.credentials = JSON.parse(token); - callback(oauth2Client); + callback(oauth2Client, args); } }); } @@ -139,13 +139,13 @@ function getChannel(auth) { }); } -function getSampleVideos(auth) { +function getSampleVideos(auth, args) { let service = google.youtube('v3'); service.search.list({ auth: auth, part: 'id, snippet', type: 'video', - q: 'istanbul', + q: args.userInput, maxResults: 3 }, function (err, response) { if (err) { -- cgit v1.2.3-70-g09d2