import React , { useEffect } from 'react' ; import { DialogPageProps } from './DialogPage' ; interface GoogleDriveImportProps extends DialogPageProps { onSelectedFile : ( text : string ) => void ; } export const GoogleDriveImport = ( { onSelectedFile } ) => { const developerKey = 'AIzaSyAADCXxUujmh0VqXIzJofwl03MA5O8v8EQ' ; const clientId = "858773398697-vki2lito392c5dlss9s31ap077nn0qbd.apps.googleusercontent.com" ; const appId = "binarual-meet" ; const scope = [ 'https://www.googleapis.com/auth/drive.file' ] ; let pickerApiLoaded = false ; let oauthToken ; function loadPicker ( ) { gapi . load ( 'auth' , { 'callback' : onAuthApiLoad } ) ; gapi . load ( 'picker' , { 'callback' : onPickerApiLoad } ) ; } function onAuthApiLoad ( ) { window . gapi . auth . authorize ( { 'client_id' : clientId , 'scope' : scope , 'immediate' : false } , handleAuthResult ) ; } function onPickerApiLoad ( ) { pickerApiLoaded = true ; createPicker ( ) ; } function handleAuthResult ( authResult ) { if ( authResult && ! authResult . error ) { oauthToken = authResult . access_token ; createPicker ( ) ; } } function createPicker ( ) { if ( pickerApiLoaded && oauthToken ) { const view = new google . picker . DocsView ( google . picker . ViewId . DOCS ) ; const picker = new google . picker . PickerBuilder ( ) . enableFeature ( google . picker . Feature . NAV_HIDDEN ) . setAppId ( appId ) . setOAuthToken ( oauthToken ) . addView ( view ) . addView ( new google . picker . DocsUploadView ( ) ) . setDeveloperKey ( developerKey ) . setCallback ( pickerCallback ) . build ( ) ; picker . setVisible ( true ) ; } } function pickerCallback ( data ) { if ( data . action === google . picker . Action . PICKED ) { const fileId = data . docs [ 0 ] . id ; onSelectedFile ( data . docs [ 0 ] . embedUrl ) ; } } param { String } fileId param { String } value param { String } type param { String } role function insertPermission ( fileId , value , type , role ) { var body = { value , type , role } ; if ( gapi . client . drive ) { var request = gapi . client . drive . permissions . create ( { fileId , 'resource' : body } ) ; request . execute ( function ( resp ) { console . log ( { resp } ) ; } ) ; } else { gapi . client . load ( 'drive' , 'v3' ) . then ( ( ) => insertPermission ( fileId , value , type , role ) ) ; } } useEffect ( ( ) => { if ( gapi ) { loadPicker ( ) ; } } , [ gapi ] ) ; return < > { 'loading...' } < />; } ; GoogleDriveImport . displayName = 'GoogleDriveImport' ;