123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- const html = require('yo-yo')
- const Plugin = require('../../core/Plugin')
- const Provider = require('../../Provider')
- const View = require('../../generic-provider-views')
- const icons = require('./icons')
- module.exports = class Dropbox extends Plugin {
- constructor (core, opts) {
- super(core, opts)
- this.type = 'acquirer'
- this.id = this.opts.id || 'Dropbox'
- this.title = 'Dropbox'
- this.icon = () => html`
- <svg class="UppyIcon" width="128" height="118" viewBox="0 0 128 118">
- <path d="M38.145.777L1.108 24.96l25.608 20.507 37.344-23.06z"/>
- <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"/>
- <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"/>
- </svg>
- `
- // writing out the key explicitly for readability the key used to store
- // the provider instance must be equal to this.id.
- this[this.id] = new Provider(core, {
- host: this.opts.host,
- provider: 'dropbox'
- })
- this.files = []
- this.onAuth = this.onAuth.bind(this)
- this.render = this.render.bind(this)
- // set default options
- const defaultOptions = {}
- // merge default options with the ones set by user
- this.opts = Object.assign({}, defaultOptions, opts)
- }
- install () {
- this.view = new View(this)
- // Set default state
- this.setPluginState({
- authenticated: false,
- files: [],
- folders: [],
- directories: [],
- activeRow: -1,
- filterInput: '',
- isSearchVisible: false
- })
- const target = this.opts.target
- if (target) {
- this.mount(target, this)
- }
- }
- uninstall () {
- this.view.tearDown()
- this.unmount()
- }
- onAuth (authenticated) {
- this.setPluginState({ authenticated })
- if (authenticated) {
- this.view.getFolder()
- }
- }
- isFolder (item) {
- return item['.tag'] === 'folder'
- }
- getItemData (item) {
- return item
- }
- getItemIcon (item) {
- return icons[item['.tag']]()
- }
- getItemSubList (item) {
- return item.entries
- }
- getItemName (item) {
- return item.name || ''
- }
- getMimeType (item) {
- // mime types aren't supported.
- return null
- }
- getItemId (item) {
- return item.id
- }
- getItemRequestPath (item) {
- return encodeURIComponent(item.path_lower)
- }
- getItemModifiedDate (item) {
- return item.server_modified
- }
- getItemThumbnailUrl (item) {
- return `${this.opts.host}/${this.Dropbox.id}/thumbnail/${this.getItemRequestPath(item)}`
- }
- render (state) {
- return this.view.render(state)
- }
- }
|