OneDrive.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { h } from 'preact'
  2. import { UIPlugin } from '@uppy/core'
  3. import { Provider, tokenStorage, getAllowedHosts } from '@uppy/companion-client'
  4. import { ProviderViews } from '@uppy/provider-views'
  5. import packageJson from '../package.json'
  6. import locale from './locale.js'
  7. export default class OneDrive extends UIPlugin {
  8. static VERSION = packageJson.version
  9. constructor (uppy, opts) {
  10. super(uppy, opts)
  11. this.type = 'acquirer'
  12. this.files = []
  13. this.storage = this.opts.storage || tokenStorage
  14. this.id = this.opts.id || 'OneDrive'
  15. this.icon = () => (
  16. <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
  17. <g fill="none" fillRule="nonzero">
  18. <path d="M13.39 12.888l4.618 2.747 2.752-1.15a4.478 4.478 0 012.073-.352 6.858 6.858 0 00-5.527-5.04 6.895 6.895 0 00-6.876 2.982l.07-.002a5.5 5.5 0 012.89.815z" fill="#0364B8" />
  19. <path d="M13.39 12.887v.001a5.5 5.5 0 00-2.89-.815l-.07.002a5.502 5.502 0 00-4.822 2.964 5.43 5.43 0 00.38 5.62l4.073-1.702 1.81-.757 4.032-1.685 2.105-.88-4.619-2.748z" fill="#0078D4" />
  20. <path d="M22.833 14.133a4.479 4.479 0 00-2.073.352l-2.752 1.15.798.475 2.616 1.556 1.141.68 3.902 2.321a4.413 4.413 0 00-.022-4.25 4.471 4.471 0 00-3.61-2.284z" fill="#1490DF" />
  21. <path d="M22.563 18.346l-1.141-.68-2.616-1.556-.798-.475-2.105.88L11.87 18.2l-1.81.757-4.073 1.702A5.503 5.503 0 0010.5 23h12.031a4.472 4.472 0 003.934-2.333l-3.902-2.321z" fill="#28A8EA" />
  22. </g>
  23. </svg>
  24. )
  25. this.opts.companionAllowedHosts = getAllowedHosts(this.opts.companionAllowedHosts, this.opts.companionUrl)
  26. this.provider = new Provider(uppy, {
  27. companionUrl: this.opts.companionUrl,
  28. companionHeaders: this.opts.companionHeaders,
  29. companionKeysParams: this.opts.companionKeysParams,
  30. companionCookiesRule: this.opts.companionCookiesRule,
  31. provider: 'onedrive',
  32. pluginId: this.id,
  33. supportsRefreshToken: false,
  34. })
  35. this.defaultLocale = locale
  36. this.i18nInit()
  37. this.title = this.i18n('pluginNameOneDrive')
  38. this.onFirstRender = this.onFirstRender.bind(this)
  39. this.render = this.render.bind(this)
  40. }
  41. install () {
  42. this.view = new ProviderViews(this, {
  43. provider: this.provider,
  44. loadAllFiles: true,
  45. })
  46. const { target } = this.opts
  47. if (target) {
  48. this.mount(target, this)
  49. }
  50. }
  51. uninstall () {
  52. this.view.tearDown()
  53. this.unmount()
  54. }
  55. onFirstRender () {
  56. return Promise.all([
  57. this.provider.fetchPreAuthToken(),
  58. this.view.getFolder(),
  59. ])
  60. }
  61. render (state) {
  62. return this.view.render(state)
  63. }
  64. }