uppy
Version:
Extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:
137 lines (105 loc) • 4.78 kB
JavaScript
;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Plugin = require('../../core/Plugin');
var Provider = require('../Provider');
var View = require('../Provider/view');
var _require = require('preact'),
h = _require.h;
module.exports = function (_Plugin) {
_inherits(GoogleDrive, _Plugin);
function GoogleDrive(uppy, opts) {
_classCallCheck(this, GoogleDrive);
var _this = _possibleConstructorReturn(this, _Plugin.call(this, uppy, opts));
_this.type = 'acquirer';
_this.id = _this.opts.id || 'GoogleDrive';
_this.title = 'Google Drive';
_this.icon = function () {
return h(
'svg',
{ 'aria-hidden': 'true', 'class': 'UppyIcon UppyModalTab-icon', width: '28', height: '28', viewBox: '0 0 16 16' },
h('path', { d: 'M2.955 14.93l2.667-4.62H16l-2.667 4.62H2.955zm2.378-4.62l-2.666 4.62L0 10.31l5.19-8.99 2.666 4.62-2.523 4.37zm10.523-.25h-5.333l-5.19-8.99h5.334l5.19 8.99z' })
);
};
_this[_this.id] = new Provider(uppy, {
host: _this.opts.host,
provider: 'drive',
authProvider: 'google'
});
_this.files = [];
_this.onAuth = _this.onAuth.bind(_this);
_this.render = _this.render.bind(_this);
// set default options
var defaultOptions = {};
// merge default options with the ones set by user
_this.opts = _extends({}, defaultOptions, opts);
return _this;
}
GoogleDrive.prototype.install = function install() {
this.view = new View(this);
// Set default state for Google Drive
this.setPluginState({
authenticated: false,
files: [],
folders: [],
directories: [],
activeRow: -1,
filterInput: '',
isSearchVisible: false
});
var target = this.opts.target;
if (target) {
this.mount(target, this);
}
};
GoogleDrive.prototype.uninstall = function uninstall() {
this.view.tearDown();
this.unmount();
};
GoogleDrive.prototype.onAuth = function onAuth(authenticated) {
this.setPluginState({ authenticated: authenticated });
if (authenticated) {
this.view.getFolder('root');
}
};
GoogleDrive.prototype.isFolder = function isFolder(item) {
return item.mimeType === 'application/vnd.google-apps.folder';
};
GoogleDrive.prototype.getItemData = function getItemData(item) {
return _extends({}, item, { size: parseFloat(item.fileSize) });
};
GoogleDrive.prototype.getItemIcon = function getItemIcon(item) {
return h('img', { src: item.iconLink });
};
GoogleDrive.prototype.getItemSubList = function getItemSubList(item) {
var _this2 = this;
return item.items.filter(function (i) {
return _this2.isFolder(i) || !i.mimeType.startsWith('application/vnd.google');
});
};
GoogleDrive.prototype.getItemName = function getItemName(item) {
return item.title ? item.title : '/';
};
GoogleDrive.prototype.getMimeType = function getMimeType(item) {
return item.mimeType;
};
GoogleDrive.prototype.getItemId = function getItemId(item) {
return item.id;
};
GoogleDrive.prototype.getItemRequestPath = function getItemRequestPath(item) {
return this.getItemId(item);
};
GoogleDrive.prototype.getItemModifiedDate = function getItemModifiedDate(item) {
return item.modifiedByMeDate;
};
GoogleDrive.prototype.getItemThumbnailUrl = function getItemThumbnailUrl(item) {
return this.opts.host + '/' + this.GoogleDrive.id + '/thumbnail/' + this.getItemRequestPath(item);
};
GoogleDrive.prototype.render = function render(state) {
return this.view.render(state);
};
return GoogleDrive;
}(Plugin);
//# sourceMappingURL=index.js.map