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 |
|
6 | module.exports = class OneDrive extends Plugin {
|
7 | static VERSION = require('../package.json').version
|
8 |
|
9 | constructor (uppy, opts) {
|
10 | super(uppy, opts)
|
11 | this.id = this.opts.id || 'OneDrive'
|
12 | Provider.initPlugin(this, opts)
|
13 | this.title = this.opts.title || 'OneDrive'
|
14 | this.icon = () => (
|
15 | <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
16 | <g fill="none" fill-rule="evenodd">
|
17 | <rect width="32" height="32" rx="16" fill="#0262C0" />
|
18 | <g fill="#FFF" fill-rule="nonzero">
|
19 | <path d="M24.157 22s1.492-.205 1.79-1.655a2.624 2.624 0 0 0 .03-.878c-.22-1.64-1.988-2.01-1.988-2.01s.307-1.765-1.312-2.69c-1.62-.925-3.1 0-3.1 0S18.711 13 16.366 13c-3.016 0-3.519 3.448-3.519 3.448S10 16.618 10 19.14c0 2.523 2.597 2.86 2.597 2.86h11.56z" />
|
20 | <path d="M9.421 19.246c0-2.197 1.606-3.159 2.871-3.472.44-1.477 1.654-3.439 4.135-3.439H16.445c1.721 0 2.79.823 3.368 1.476a3.99 3.99 0 0 1 1.147-.171h.01l.03.002C21.017 13.5 20.691 10 16.757 10c-2.69 0-3.639 2.345-3.639 2.345s-1.95-1.482-3.955.567c-1.028 1.052-.79 2.669-.79 2.669S6 15.824 6 18.412C6 20.757 8.452 21 8.452 21h1.372a3.77 3.77 0 0 1-.403-1.754z" />
|
21 | </g>
|
22 | </g>
|
23 | </svg>
|
24 | )
|
25 |
|
26 | this.provider = new Provider(uppy, {
|
27 | companionUrl: this.opts.companionUrl,
|
28 | companionHeaders: this.opts.companionHeaders || this.opts.serverHeaders,
|
29 | provider: 'onedrive',
|
30 | pluginId: this.id
|
31 | })
|
32 |
|
33 | this.onFirstRender = this.onFirstRender.bind(this)
|
34 | this.render = this.render.bind(this)
|
35 | }
|
36 |
|
37 | install () {
|
38 | this.view = new ProviderViews(this, {
|
39 | provider: this.provider
|
40 | })
|
41 |
|
42 | this.setPluginState({
|
43 | authenticated: false,
|
44 | files: [],
|
45 | folders: [],
|
46 | directories: [],
|
47 | activeRow: -1,
|
48 | filterInput: '',
|
49 | isSearchVisible: false
|
50 | })
|
51 |
|
52 | const target = this.opts.target
|
53 | if (target) {
|
54 | this.mount(target, this)
|
55 | }
|
56 | }
|
57 |
|
58 | uninstall () {
|
59 | this.view.tearDown()
|
60 | this.unmount()
|
61 | }
|
62 |
|
63 | onFirstRender () {
|
64 | return this.view.getFolder()
|
65 | }
|
66 |
|
67 | render (state) {
|
68 | return this.view.render(state)
|
69 | }
|
70 | }
|