Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // @flow
  2. import { Dropbox } from 'dropbox';
  3. import {
  4. getJitsiMeetGlobalNS,
  5. parseStandardURIString
  6. } from '../base/util';
  7. import { parseURLParams } from '../base/config';
  8. /**
  9. * Returns the display name for the current dropbox account.
  10. *
  11. * @param {string} token - The dropbox access token.
  12. * @param {string} clientId - The Jitsi Recorder dropbox app ID.
  13. * @returns {Promise<string>}
  14. */
  15. export function getDisplayName(token: string, clientId: string) {
  16. const dropboxAPI = new Dropbox({
  17. accessToken: token,
  18. clientId
  19. });
  20. return (
  21. dropboxAPI.usersGetCurrentAccount()
  22. .then(account => account.name.display_name));
  23. }
  24. /**
  25. * Returns information about the space usage for the current dropbox account.
  26. *
  27. * @param {string} token - The dropbox access token.
  28. * @param {string} clientId - The Jitsi Recorder dropbox app ID.
  29. * @returns {Promise<Object>}
  30. */
  31. export function getSpaceUsage(token: string, clientId: string) {
  32. const dropboxAPI = new Dropbox({
  33. accessToken: token,
  34. clientId
  35. });
  36. return dropboxAPI.usersGetSpaceUsage().then(space => {
  37. const { allocation, used } = space;
  38. const { allocated } = allocation;
  39. return {
  40. used,
  41. allocated
  42. };
  43. });
  44. }
  45. /**
  46. * Executes the oauth flow.
  47. *
  48. * @param {string} authUrl - The URL to oauth service.
  49. * @returns {Promise<string>} - The URL with the authorization details.
  50. */
  51. function authorize(authUrl: string): Promise<string> {
  52. const windowName = `oauth${Date.now()}`;
  53. const gloabalNS = getJitsiMeetGlobalNS();
  54. gloabalNS.oauthCallbacks = gloabalNS.oauthCallbacks || {};
  55. return new Promise(resolve => {
  56. const popup = window.open(authUrl, windowName);
  57. gloabalNS.oauthCallbacks[windowName] = () => {
  58. const returnURL = popup.location.href;
  59. popup.close();
  60. delete gloabalNS.oauthCallbacks.windowName;
  61. resolve(returnURL);
  62. };
  63. });
  64. }
  65. /**
  66. * Action to authorize the Jitsi Recording app in dropbox.
  67. *
  68. * @param {string} clientId - The Jitsi Recorder dropbox app ID.
  69. * @param {string} redirectURI - The return URL.
  70. * @returns {Promise<string>}
  71. */
  72. export function _authorizeDropbox(
  73. clientId: string,
  74. redirectURI: string
  75. ): Promise<string> {
  76. const dropboxAPI = new Dropbox({ clientId });
  77. const url = dropboxAPI.getAuthenticationUrl(redirectURI);
  78. return authorize(url).then(returnUrl => {
  79. const params
  80. = parseURLParams(parseStandardURIString(returnUrl), true) || {};
  81. return params.access_token;
  82. });
  83. }
  84. /**
  85. * Returns <tt>true</tt> if the dropbox features is enabled and <tt>false</tt>
  86. * otherwise.
  87. *
  88. * @param {Object} state - The redux state.
  89. * @returns {boolean}
  90. */
  91. export function isEnabled(state: Object) {
  92. const { dropbox = {} } = state['features/base/config'];
  93. return typeof dropbox.clientId === 'string';
  94. }