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.

functions.any.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // @flow
  2. export * from './functions';
  3. import { getDisplayName, getSpaceUsage } from './functions';
  4. import logger from './logger';
  5. /**
  6. * Information related to the user's dropbox account.
  7. */
  8. type DropboxUserData = {
  9. /**
  10. * The available space left in MB into the user's Dropbox account.
  11. */
  12. spaceLeft: number,
  13. /**
  14. * The display name of the user in Dropbox.
  15. */
  16. userName: string
  17. };
  18. /**
  19. * Fetches information about the user's dropbox account.
  20. *
  21. * @param {string} token - The dropbox access token.
  22. * @param {string} appKey - The Jitsi Recorder dropbox app key.
  23. * @returns {Promise<DropboxUserData|undefined>}
  24. */
  25. export function getDropboxData(
  26. token: string,
  27. appKey: string
  28. ): Promise<?DropboxUserData> {
  29. return Promise.all(
  30. [ getDisplayName(token, appKey), getSpaceUsage(token, appKey) ]
  31. ).then(([ userName, space ]) => {
  32. const { allocated, used } = space;
  33. return {
  34. userName,
  35. spaceLeft: Math.floor((allocated - used) / 1048576)// 1MiB=1048576B
  36. };
  37. }, error => {
  38. logger.error(error);
  39. return undefined;
  40. });
  41. }