Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

actions.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // @flow
  2. import { Dropbox } from 'dropbox';
  3. import {
  4. getJitsiMeetGlobalNS,
  5. getLocationContextRoot,
  6. parseStandardURIString
  7. } from '../base/util';
  8. import { parseURLParams } from '../base/config';
  9. import { UPDATE_DROPBOX_TOKEN } from './actionTypes';
  10. /**
  11. * Executes the oauth flow.
  12. *
  13. * @param {string} authUrl - The URL to oauth service.
  14. * @returns {Promise<string>} - The URL with the authorization details.
  15. */
  16. function authorize(authUrl: string): Promise<string> {
  17. const windowName = `oauth${Date.now()}`;
  18. const gloabalNS = getJitsiMeetGlobalNS();
  19. gloabalNS.oauthCallbacks = gloabalNS.oauthCallbacks || {};
  20. return new Promise(resolve => {
  21. const popup = window.open(authUrl, windowName);
  22. gloabalNS.oauthCallbacks[windowName] = () => {
  23. const returnURL = popup.location.href;
  24. popup.close();
  25. delete gloabalNS.oauthCallbacks.windowName;
  26. resolve(returnURL);
  27. };
  28. });
  29. }
  30. /**
  31. * Action to authorize the Jitsi Recording app in dropbox.
  32. *
  33. * @returns {Function}
  34. */
  35. export function authorizeDropbox() {
  36. return (dispatch: Function, getState: Function) => {
  37. const state = getState();
  38. const { locationURL } = state['features/base/connection'];
  39. const { dropbox } = state['features/base/config'];
  40. const redirectURI = `${locationURL.origin
  41. + getLocationContextRoot(locationURL)}static/oauth.html`;
  42. const dropboxAPI = new Dropbox({ clientId: dropbox.clientId });
  43. const url = dropboxAPI.getAuthenticationUrl(redirectURI);
  44. authorize(url).then(returnUrl => {
  45. const params
  46. = parseURLParams(parseStandardURIString(returnUrl), true) || {};
  47. dispatch(updateDropboxToken(params.access_token));
  48. });
  49. };
  50. }
  51. /**
  52. * Action to update the dropbox access token.
  53. *
  54. * @param {string} token - The new token.
  55. * @returns {{
  56. * type: UPDATE_DROPBOX_TOKEN,
  57. * token: string
  58. * }}
  59. */
  60. export function updateDropboxToken(token: string) {
  61. return {
  62. type: UPDATE_DROPBOX_TOKEN,
  63. token
  64. };
  65. }