index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const { Plugin } = require('@uppy/core')
  2. const { Provider } = require('@uppy/companion-client')
  3. const ProviderViews = require('@uppy/provider-views')
  4. const { h } = require('preact')
  5. module.exports = class Dropbox extends Plugin {
  6. constructor (uppy, opts) {
  7. super(uppy, opts)
  8. this.id = this.opts.id || 'Dropbox'
  9. Provider.initPlugin(this, opts)
  10. this.title = this.opts.title || 'Dropbox'
  11. this.icon = () => (
  12. <svg aria-hidden="true" fill="#0060ff" width="128" height="118" viewBox="0 0 128 118">
  13. <path d="M38.145.777L1.108 24.96l25.608 20.507 37.344-23.06z" />
  14. <path d="M1.108 65.975l37.037 24.183L64.06 68.525l-37.343-23.06zM64.06 68.525l25.917 21.633 37.036-24.183-25.61-20.51z" />
  15. <path d="M127.014 24.96L89.977.776 64.06 22.407l37.345 23.06zM64.136 73.18l-25.99 21.567-11.122-7.262v8.142l37.112 22.256 37.114-22.256v-8.142l-11.12 7.262z" />
  16. </svg>
  17. )
  18. this.provider = new Provider(uppy, {
  19. serverUrl: this.opts.serverUrl,
  20. serverHeaders: this.opts.serverHeaders,
  21. storage: this.opts.storage,
  22. provider: 'dropbox',
  23. pluginId: this.id
  24. })
  25. this.onAuth = this.onAuth.bind(this)
  26. this.render = this.render.bind(this)
  27. }
  28. install () {
  29. this.view = new ProviderViews(this, {
  30. provider: this.provider
  31. })
  32. // Set default state for Dropbox
  33. this.setPluginState({
  34. authenticated: false,
  35. files: [],
  36. folders: [],
  37. directories: [],
  38. activeRow: -1,
  39. filterInput: '',
  40. isSearchVisible: false
  41. })
  42. const target = this.opts.target
  43. if (target) {
  44. this.mount(target, this)
  45. }
  46. }
  47. uninstall () {
  48. this.view.tearDown()
  49. this.unmount()
  50. }
  51. onAuth (authenticated) {
  52. this.setPluginState({ authenticated })
  53. if (authenticated) {
  54. this.view.getFolder()
  55. }
  56. }
  57. render (state) {
  58. return this.view.render(state)
  59. }
  60. }