123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- const { UIPlugin } = require('@uppy/core')
- const { Provider } = require('@uppy/companion-client')
- const DriveProviderViews = require('./DriveProviderViews')
- const { h } = require('preact')
- module.exports = class GoogleDrive extends UIPlugin {
- static VERSION = require('../package.json').version
- constructor (uppy, opts) {
- super(uppy, opts)
- this.id = this.opts.id || 'GoogleDrive'
- this.title = this.opts.title || 'Google Drive'
- Provider.initPlugin(this, opts)
- this.title = this.opts.title || 'Google Drive'
- this.icon = () => (
- <svg aria-hidden="true" focusable="false" width="32" height="32" viewBox="0 0 32 32">
- <g fill="none" fillRule="evenodd">
- <rect className="uppy-ProviderIconBg" fill="#4285F4" width="32" height="32" rx="16" />
- <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" />
- </g>
- </svg>
- )
- this.provider = new Provider(uppy, {
- companionUrl: this.opts.companionUrl,
- companionHeaders: this.opts.companionHeaders,
- companionKeysParams: this.opts.companionKeysParams,
- companionCookiesRule: this.opts.companionCookiesRule,
- provider: 'drive',
- pluginId: this.id,
- })
- this.onFirstRender = this.onFirstRender.bind(this)
- this.render = this.render.bind(this)
- }
- install () {
- this.view = new DriveProviderViews(this, {
- provider: this.provider,
- })
- const target = this.opts.target
- if (target) {
- this.mount(target, this)
- }
- }
- uninstall () {
- this.view.tearDown()
- this.unmount()
- }
- onFirstRender () {
- return Promise.all([
- this.provider.fetchPreAuthToken(),
- this.view.getFolder('root', '/'),
- ])
- }
- render (state) {
- return this.view.render(state)
- }
- }
|