You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // @flow
  2. import { Dropbox } from 'dropbox';
  3. import { getLocationContextRoot, parseStandardURIString } from '../util';
  4. import { parseURLParams } from '../config';
  5. import { authorize } from './functions';
  6. import { UPDATE_DROPBOX_TOKEN } from './actionTypes';
  7. /**
  8. * Action to authorize the Jitsi Recording app in dropbox.
  9. *
  10. * @returns {Function}
  11. */
  12. export function authorizeDropbox() {
  13. return (dispatch: Function, getState: Function) => {
  14. const state = getState();
  15. const { locationURL } = state['features/base/connection'];
  16. const { dropbox } = state['features/base/config'];
  17. const redirectURI = `${locationURL.origin
  18. + getLocationContextRoot(locationURL)}static/oauth.html`;
  19. const dropboxAPI = new Dropbox({ clientId: dropbox.clientId });
  20. const url = dropboxAPI.getAuthenticationUrl(redirectURI);
  21. authorize(url).then(returnUrl => {
  22. const params
  23. = parseURLParams(parseStandardURIString(returnUrl), true) || {};
  24. dispatch(updateDropboxToken(params.access_token));
  25. });
  26. };
  27. }
  28. /**
  29. * Action to update the dropbox access token.
  30. *
  31. * @param {string} token - The new token.
  32. * @returns {{
  33. * type: UPDATE_DROPBOX_TOKEN,
  34. * token: string
  35. * }}
  36. */
  37. export function updateDropboxToken(token: string) {
  38. return {
  39. type: UPDATE_DROPBOX_TOKEN,
  40. token
  41. };
  42. }