index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const { UIPlugin } = require('@uppy/core')
  2. const { Provider } = require('@uppy/companion-client')
  3. const { h } = require('preact')
  4. const DriveProviderViews = require('./DriveProviderViews')
  5. module.exports = class GoogleDrive extends UIPlugin {
  6. static VERSION = require('../package.json').version
  7. constructor (uppy, opts) {
  8. super(uppy, opts)
  9. this.id = this.opts.id || 'GoogleDrive'
  10. this.title = this.opts.title || 'Google Drive'
  11. Provider.initPlugin(this, opts)
  12. this.title = this.opts.title || 'Google Drive'
  13. this.icon = () => (
  14. <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
  15. <g fill="none" fillRule="evenodd">
  16. <rect className="uppy-ProviderIconBg" fill="#4285F4" width="32" height="32" rx="16" />
  17. <path d="M10.324 23.3l3-5.1H25l-3 5.1H10.324zM13 18.2l-3 5.1-3-5.1 5.839-9.924 2.999 5.1L13 18.2zm11.838-.276h-6L13 8h6l5.84 9.924h-.002z" fill="#FFF" />
  18. </g>
  19. </svg>
  20. )
  21. this.provider = new Provider(uppy, {
  22. companionUrl: this.opts.companionUrl,
  23. companionHeaders: this.opts.companionHeaders,
  24. companionKeysParams: this.opts.companionKeysParams,
  25. companionCookiesRule: this.opts.companionCookiesRule,
  26. provider: 'drive',
  27. pluginId: this.id,
  28. })
  29. this.onFirstRender = this.onFirstRender.bind(this)
  30. this.render = this.render.bind(this)
  31. }
  32. install () {
  33. this.view = new DriveProviderViews(this, {
  34. provider: this.provider,
  35. })
  36. const { target } = this.opts
  37. if (target) {
  38. this.mount(target, this)
  39. }
  40. }
  41. uninstall () {
  42. this.view.tearDown()
  43. this.unmount()
  44. }
  45. onFirstRender () {
  46. return Promise.all([
  47. this.provider.fetchPreAuthToken(),
  48. this.view.getFolder('root', '/'),
  49. ])
  50. }
  51. render (state) {
  52. return this.view.render(state)
  53. }
  54. }