GoogleDrive.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { UIPlugin } from '@uppy/core'
  2. import { Provider } from '@uppy/companion-client'
  3. import { h } from 'preact'
  4. import packageJson from '../package.json'
  5. import DriveProviderViews from './DriveProviderViews.js'
  6. import locale from './locale.js'
  7. export default class GoogleDrive extends UIPlugin {
  8. static VERSION = packageJson.version
  9. constructor (uppy, opts) {
  10. super(uppy, opts)
  11. this.id = this.opts.id || 'GoogleDrive'
  12. this.title = this.opts.title || 'Google Drive'
  13. Provider.initPlugin(this, opts)
  14. this.title = this.opts.title || 'Google Drive'
  15. this.icon = () => (
  16. <svg
  17. aria-hidden="true"
  18. focusable="false"
  19. width="32"
  20. height="32"
  21. viewBox="0 0 32 32"
  22. >
  23. <g fill="none" fillRule="evenodd">
  24. <rect
  25. className="uppy-ProviderIconBg"
  26. fill="#4285F4"
  27. width="32"
  28. height="32"
  29. rx="16"
  30. />
  31. <path
  32. d="M25.216 17.736L19.043 7h-6.086l6.175 10.736h6.084zm-11.275.896L10.9 24h11.723l3.04-5.368H13.942zm-1.789-10.29l-5.816 10.29L9.38 24l5.905-10.29-3.132-5.369z"
  33. fill="#FFF"
  34. />
  35. </g>
  36. </svg>
  37. )
  38. this.provider = new Provider(uppy, {
  39. companionUrl: this.opts.companionUrl,
  40. companionHeaders: this.opts.companionHeaders,
  41. companionKeysParams: this.opts.companionKeysParams,
  42. companionCookiesRule: this.opts.companionCookiesRule,
  43. provider: 'drive',
  44. pluginId: this.id,
  45. })
  46. this.defaultLocale = locale
  47. this.i18nInit()
  48. this.title = this.i18n('pluginNameGoogleDrive')
  49. this.onFirstRender = this.onFirstRender.bind(this)
  50. this.render = this.render.bind(this)
  51. }
  52. install () {
  53. this.view = new DriveProviderViews(this, {
  54. provider: this.provider,
  55. })
  56. const { target } = this.opts
  57. if (target) {
  58. this.mount(target, this)
  59. }
  60. }
  61. uninstall () {
  62. this.view.tearDown()
  63. this.unmount()
  64. }
  65. onFirstRender () {
  66. return Promise.all([
  67. this.provider.fetchPreAuthToken(),
  68. this.view.getFolder('root', '/'),
  69. ])
  70. }
  71. render (state) {
  72. return this.view.render(state)
  73. }
  74. }