|
@@ -1,2023 +1,2087 @@
|
|
|
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-module.exports = require('./lib/core');
|
|
|
-
|
|
|
-},{"./lib/core":4}],2:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
-
|
|
|
-var _core = require('../../../../core');
|
|
|
-
|
|
|
-var _core2 = _interopRequireDefault(_core);
|
|
|
+/**
|
|
|
+ * Module dependencies.
|
|
|
+ */
|
|
|
|
|
|
-var _plugins = require('../../../../plugins');
|
|
|
+var Emitter = require('emitter');
|
|
|
+var reduce = require('reduce');
|
|
|
|
|
|
-var transloadit = new _core2['default']({ wait: false });
|
|
|
-var files = transloadit.use(_plugins.DragDrop, { modal: true, selector: '#upload-target' }).use(_plugins.Tus10, { endpoint: 'http://master.tus.io:8080' }).run();
|
|
|
+/**
|
|
|
+ * Root reference for iframes.
|
|
|
+ */
|
|
|
|
|
|
-console.log('--> Finished transloadit. Final result: ');
|
|
|
-console.dir(files);
|
|
|
+var root;
|
|
|
+if (typeof window !== 'undefined') { // Browser window
|
|
|
+ root = window;
|
|
|
+} else if (typeof self !== 'undefined') { // Web Worker
|
|
|
+ root = self;
|
|
|
+} else { // Other environments
|
|
|
+ root = this;
|
|
|
+}
|
|
|
|
|
|
-// var Transloadit = require('./src/core/Transloadit.js');
|
|
|
-// var DragDrop = require('./src/plugins/DragDrop.js');
|
|
|
-// var Tus10 = require('./src/plugins/Tus10.js');
|
|
|
-//
|
|
|
-// var transloadit = new Transloadit({wait: false});
|
|
|
-// var files = transloadit
|
|
|
-// .use(DragDrop, {modal: true})
|
|
|
-// .use(Tus10, {endpoint: 'http://master.tus.io:8080'})
|
|
|
-// .run();
|
|
|
-//
|
|
|
-// console.log('--> Finished transloadit. Final result: ');
|
|
|
-// console.dir(files);
|
|
|
+/**
|
|
|
+ * Noop.
|
|
|
+ */
|
|
|
|
|
|
-},{"../../../../core":1,"../../../../plugins":14}],3:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
+function noop(){};
|
|
|
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
+/**
|
|
|
+ * Check if `obj` is a host object,
|
|
|
+ * we don't want to serialize these :)
|
|
|
+ *
|
|
|
+ * TODO: future proof, move to compoent land
|
|
|
+ *
|
|
|
+ * @param {Object} obj
|
|
|
+ * @return {Boolean}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
-var _createClass = (function () {
|
|
|
- function defineProperties(target, props) {
|
|
|
- for (var i = 0; i < props.length; i++) {
|
|
|
- var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
|
|
|
- }
|
|
|
- }return function (Constructor, protoProps, staticProps) {
|
|
|
- if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
|
|
|
- };
|
|
|
-})();
|
|
|
+function isHost(obj) {
|
|
|
+ var str = {}.toString.call(obj);
|
|
|
|
|
|
-function _classCallCheck(instance, Constructor) {
|
|
|
- if (!(instance instanceof Constructor)) {
|
|
|
- throw new TypeError('Cannot call a class as a function');
|
|
|
+ switch (str) {
|
|
|
+ case '[object File]':
|
|
|
+ case '[object Blob]':
|
|
|
+ case '[object FormData]':
|
|
|
+ return true;
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-var _default = (function () {
|
|
|
- function _default(opts) {
|
|
|
- _classCallCheck(this, _default);
|
|
|
-
|
|
|
- // Dictates in what order different plugin types are ran:
|
|
|
- this.types = ['presetter', 'selecter', 'uploader'];
|
|
|
+/**
|
|
|
+ * Determine XHR.
|
|
|
+ */
|
|
|
|
|
|
- // Container for different types of plugins
|
|
|
- this.plugins = {};
|
|
|
+request.getXHR = function () {
|
|
|
+ if (root.XMLHttpRequest
|
|
|
+ && (!root.location || 'file:' != root.location.protocol
|
|
|
+ || !root.ActiveXObject)) {
|
|
|
+ return new XMLHttpRequest;
|
|
|
+ } else {
|
|
|
+ try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {}
|
|
|
+ try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {}
|
|
|
+ try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
|
|
|
+ try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
|
|
|
}
|
|
|
+ return false;
|
|
|
+};
|
|
|
|
|
|
- _createClass(_default, [{
|
|
|
- key: 'use',
|
|
|
- value: function use(Plugin, opts) {
|
|
|
- // Instantiate
|
|
|
- var plugin = new Plugin(this, opts);
|
|
|
-
|
|
|
- // Save in plugin container
|
|
|
- if (!this.plugins[plugin.type]) {
|
|
|
- this.plugins[plugin.type] = [];
|
|
|
- }
|
|
|
- this.plugins[plugin.type].push(plugin);
|
|
|
-
|
|
|
- return this;
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'setProgress',
|
|
|
- value: function setProgress(plugin, percentage) {
|
|
|
- // Any plugin can call this via `this.core.setProgress(this, precentage)`
|
|
|
- console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage);
|
|
|
-
|
|
|
- return this;
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'run',
|
|
|
- value: function run() {
|
|
|
- // Walk over plugins in the order as defined by this.types.
|
|
|
- var files = [];
|
|
|
- for (var j in this.types) {
|
|
|
- var type = this.types[j];
|
|
|
- // Walk over all plugins of this type, passing & modifying the files array as we go
|
|
|
- for (var i in this.plugins[type]) {
|
|
|
- var plugin = this.plugins[type][i];
|
|
|
- console.log('--> Now running ' + plugin.type + ' plugin ' + plugin.name + ': ');
|
|
|
- files = plugin.run(files);
|
|
|
- console.dir(files);
|
|
|
- console.log('');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // core.run is the final step and retuns the results (vs every other method, returning `this`)
|
|
|
- // for chainability
|
|
|
- return files;
|
|
|
- }
|
|
|
- }]);
|
|
|
+/**
|
|
|
+ * Removes leading and trailing whitespace, added to support IE.
|
|
|
+ *
|
|
|
+ * @param {String} s
|
|
|
+ * @return {String}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
- return _default;
|
|
|
-})();
|
|
|
+var trim = ''.trim
|
|
|
+ ? function(s) { return s.trim(); }
|
|
|
+ : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
|
|
|
|
|
-exports['default'] = _default;
|
|
|
-module.exports = exports['default'];
|
|
|
+/**
|
|
|
+ * Check if `obj` is an object.
|
|
|
+ *
|
|
|
+ * @param {Object} obj
|
|
|
+ * @return {Boolean}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
-},{}],4:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
+function isObject(obj) {
|
|
|
+ return obj === Object(obj);
|
|
|
+}
|
|
|
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
+/**
|
|
|
+ * Serialize the given `obj`.
|
|
|
+ *
|
|
|
+ * @param {Object} obj
|
|
|
+ * @return {String}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
-function _interopRequireDefault(obj) {
|
|
|
- return obj && obj.__esModule ? obj : { 'default': obj };
|
|
|
+function serialize(obj) {
|
|
|
+ if (!isObject(obj)) return obj;
|
|
|
+ var pairs = [];
|
|
|
+ for (var key in obj) {
|
|
|
+ if (null != obj[key]) {
|
|
|
+ pushEncodedKeyValuePair(pairs, key, obj[key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return pairs.join('&');
|
|
|
}
|
|
|
|
|
|
-var _Transloadit = require('./Transloadit');
|
|
|
+/**
|
|
|
+ * Helps 'serialize' with serializing arrays.
|
|
|
+ * Mutates the pairs array.
|
|
|
+ *
|
|
|
+ * @param {Array} pairs
|
|
|
+ * @param {String} key
|
|
|
+ * @param {Mixed} val
|
|
|
+ */
|
|
|
|
|
|
-var _Transloadit2 = _interopRequireDefault(_Transloadit);
|
|
|
+function pushEncodedKeyValuePair(pairs, key, val) {
|
|
|
+ if (Array.isArray(val)) {
|
|
|
+ return val.forEach(function(v) {
|
|
|
+ pushEncodedKeyValuePair(pairs, key, v);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ pairs.push(encodeURIComponent(key)
|
|
|
+ + '=' + encodeURIComponent(val));
|
|
|
+}
|
|
|
|
|
|
-exports['default'] = _Transloadit2['default'];
|
|
|
-module.exports = exports['default'];
|
|
|
+/**
|
|
|
+ * Expose serialization method.
|
|
|
+ */
|
|
|
|
|
|
-},{"./Transloadit":3}],5:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
+ request.serializeObject = serialize;
|
|
|
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
+ /**
|
|
|
+ * Parse the given x-www-form-urlencoded `str`.
|
|
|
+ *
|
|
|
+ * @param {String} str
|
|
|
+ * @return {Object}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
-var _createClass = (function () {
|
|
|
- function defineProperties(target, props) {
|
|
|
- for (var i = 0; i < props.length; i++) {
|
|
|
- var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
|
|
|
- }
|
|
|
- }return function (Constructor, protoProps, staticProps) {
|
|
|
- if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
|
|
|
- };
|
|
|
-})();
|
|
|
+function parseString(str) {
|
|
|
+ var obj = {};
|
|
|
+ var pairs = str.split('&');
|
|
|
+ var parts;
|
|
|
+ var pair;
|
|
|
|
|
|
-var _get = function get(_x, _x2, _x3) {
|
|
|
- var _again = true;_function: while (_again) {
|
|
|
- var object = _x,
|
|
|
- property = _x2,
|
|
|
- receiver = _x3;_again = false;if (object === null) object = Function.prototype;var desc = Object.getOwnPropertyDescriptor(object, property);if (desc === undefined) {
|
|
|
- var parent = Object.getPrototypeOf(object);if (parent === null) {
|
|
|
- return undefined;
|
|
|
- } else {
|
|
|
- _x = parent;_x2 = property;_x3 = receiver;_again = true;desc = parent = undefined;continue _function;
|
|
|
- }
|
|
|
- } else if ('value' in desc) {
|
|
|
- return desc.value;
|
|
|
- } else {
|
|
|
- var getter = desc.get;if (getter === undefined) {
|
|
|
- return undefined;
|
|
|
- }return getter.call(receiver);
|
|
|
- }
|
|
|
+ for (var i = 0, len = pairs.length; i < len; ++i) {
|
|
|
+ pair = pairs[i];
|
|
|
+ parts = pair.split('=');
|
|
|
+ obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
|
|
|
}
|
|
|
-};
|
|
|
|
|
|
-function _interopRequireDefault(obj) {
|
|
|
- return obj && obj.__esModule ? obj : { 'default': obj };
|
|
|
+ return obj;
|
|
|
}
|
|
|
|
|
|
-function _classCallCheck(instance, Constructor) {
|
|
|
- if (!(instance instanceof Constructor)) {
|
|
|
- throw new TypeError('Cannot call a class as a function');
|
|
|
- }
|
|
|
-}
|
|
|
+/**
|
|
|
+ * Expose parser.
|
|
|
+ */
|
|
|
|
|
|
-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;
|
|
|
-}
|
|
|
+request.parseString = parseString;
|
|
|
|
|
|
-var _TransloaditPlugin2 = require('./TransloaditPlugin');
|
|
|
+/**
|
|
|
+ * Default MIME type map.
|
|
|
+ *
|
|
|
+ * superagent.types.xml = 'application/xml';
|
|
|
+ *
|
|
|
+ */
|
|
|
|
|
|
-var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
|
|
|
+request.types = {
|
|
|
+ html: 'text/html',
|
|
|
+ json: 'application/json',
|
|
|
+ xml: 'application/xml',
|
|
|
+ urlencoded: 'application/x-www-form-urlencoded',
|
|
|
+ 'form': 'application/x-www-form-urlencoded',
|
|
|
+ 'form-data': 'application/x-www-form-urlencoded'
|
|
|
+};
|
|
|
|
|
|
-// This is how we roll $('.element').toggleClass in non-jQuery world
|
|
|
-function toggleClass(el, className) {
|
|
|
- // console.log(el);
|
|
|
+/**
|
|
|
+ * Default serialization map.
|
|
|
+ *
|
|
|
+ * superagent.serialize['application/xml'] = function(obj){
|
|
|
+ * return 'generated xml here';
|
|
|
+ * };
|
|
|
+ *
|
|
|
+ */
|
|
|
|
|
|
- if (el.classList) {
|
|
|
- el.classList.toggle(className);
|
|
|
- } else {
|
|
|
- var classes = el.className.split(' ');
|
|
|
- var existingIndex = classes.indexOf(className);
|
|
|
+ request.serialize = {
|
|
|
+ 'application/x-www-form-urlencoded': serialize,
|
|
|
+ 'application/json': JSON.stringify
|
|
|
+ };
|
|
|
|
|
|
- if (existingIndex >= 0) {
|
|
|
- classes.splice(existingIndex, 1);
|
|
|
- } else {
|
|
|
- classes.push(className);
|
|
|
- el.className = classes.join(' ');
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+ /**
|
|
|
+ * Default parsers.
|
|
|
+ *
|
|
|
+ * superagent.parse['application/xml'] = function(str){
|
|
|
+ * return { object parsed from str };
|
|
|
+ * };
|
|
|
+ *
|
|
|
+ */
|
|
|
|
|
|
-var DragDrop = (function (_TransloaditPlugin) {
|
|
|
- _inherits(DragDrop, _TransloaditPlugin);
|
|
|
+request.parse = {
|
|
|
+ 'application/x-www-form-urlencoded': parseString,
|
|
|
+ 'application/json': JSON.parse
|
|
|
+};
|
|
|
|
|
|
- function DragDrop(core, opts) {
|
|
|
- _classCallCheck(this, DragDrop);
|
|
|
+/**
|
|
|
+ * Parse the given header `str` into
|
|
|
+ * an object containing the mapped fields.
|
|
|
+ *
|
|
|
+ * @param {String} str
|
|
|
+ * @return {Object}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
- _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'selecter';
|
|
|
- this.opts = opts;
|
|
|
- console.log(this.opts);
|
|
|
+function parseHeader(str) {
|
|
|
+ var lines = str.split(/\r?\n/);
|
|
|
+ var fields = {};
|
|
|
+ var index;
|
|
|
+ var line;
|
|
|
+ var field;
|
|
|
+ var val;
|
|
|
|
|
|
- // get the element where Drag & Drop event will occur
|
|
|
- this.dropzone = document.querySelectorAll(this.opts.selector)[0];
|
|
|
+ lines.pop(); // trailing CRLF
|
|
|
|
|
|
- // crazy stuff so that ‘this’ will behave in class
|
|
|
- this.handleDragEnter = this.handleDragEnter.bind(this);
|
|
|
- this.handleDragOver = this.handleDragOver.bind(this);
|
|
|
- this.handleDrop = this.handleDrop.bind(this);
|
|
|
+ for (var i = 0, len = lines.length; i < len; ++i) {
|
|
|
+ line = lines[i];
|
|
|
+ index = line.indexOf(':');
|
|
|
+ field = line.slice(0, index).toLowerCase();
|
|
|
+ val = trim(line.slice(index + 1));
|
|
|
+ fields[field] = val;
|
|
|
}
|
|
|
|
|
|
- _createClass(DragDrop, [{
|
|
|
- key: 'listenForEvents',
|
|
|
- value: function listenForEvents() {
|
|
|
- this.dropzone.addEventListener('dragenter', this.handleDragEnter);
|
|
|
- this.dropzone.addEventListener('dragover', this.handleDragOver);
|
|
|
- this.dropzone.addEventListener('drop', this.handleDrop);
|
|
|
- console.log('waiting for some files to be dropped on ' + this.opts.selector);
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'handleDragEnter',
|
|
|
- value: function handleDragEnter(e) {
|
|
|
- event.stopPropagation();
|
|
|
- event.preventDefault();
|
|
|
- toggleClass(this.dropzone, 'is-dragover');
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'handleDragOver',
|
|
|
- value: function handleDragOver(e) {
|
|
|
- e.stopPropagation();
|
|
|
- e.preventDefault();
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'handleDrop',
|
|
|
- value: function handleDrop(e) {
|
|
|
- console.log('all right, someone dropped something here...');
|
|
|
- e.preventDefault();
|
|
|
- toggleClass(this.dropzone, 'is-dragover');
|
|
|
- var files = e.dataTransfer.files;
|
|
|
- console.log(files);
|
|
|
- this.handleFiles(files);
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'handleFiles',
|
|
|
- value: function handleFiles(files) {
|
|
|
- return files;
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'run',
|
|
|
- value: function run(files) {
|
|
|
- this.listenForEvents();
|
|
|
- // this.core.setProgress(this, 0);
|
|
|
- var selected = [{ name: 'lolcat.jpeg' }];
|
|
|
- // this.core.setProgress(this, 100);
|
|
|
-
|
|
|
- // return selected;
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return DragDrop;
|
|
|
-})(_TransloaditPlugin3['default']);
|
|
|
-
|
|
|
-exports['default'] = DragDrop;
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"./TransloaditPlugin":8}],6:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
-
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () {
|
|
|
- function defineProperties(target, props) {
|
|
|
- for (var i = 0; i < props.length; i++) {
|
|
|
- var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
|
|
|
- }
|
|
|
- }return function (Constructor, protoProps, staticProps) {
|
|
|
- if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
|
|
|
- };
|
|
|
-})();
|
|
|
-
|
|
|
-function _interopRequireDefault(obj) {
|
|
|
- return obj && obj.__esModule ? obj : { 'default': obj };
|
|
|
-}
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) {
|
|
|
- if (!(instance instanceof Constructor)) {
|
|
|
- throw new TypeError('Cannot call a class as a function');
|
|
|
- }
|
|
|
+ return fields;
|
|
|
}
|
|
|
|
|
|
-var _superagent = require('superagent');
|
|
|
-
|
|
|
-var _superagent2 = _interopRequireDefault(_superagent);
|
|
|
-
|
|
|
-var DropboxPlugin = (function () {
|
|
|
- function DropboxPlugin() {
|
|
|
- _classCallCheck(this, DropboxPlugin);
|
|
|
-
|
|
|
- this.authenticate = this.authenticate.bind(this);
|
|
|
- this.connect = this.connect.bind(this);
|
|
|
- this.render = this.render.bind(this);
|
|
|
- this.files = [];
|
|
|
- this.currentDir = '/';
|
|
|
- }
|
|
|
-
|
|
|
- _createClass(DropboxPlugin, [{
|
|
|
- key: 'connect',
|
|
|
- value: function connect(target) {
|
|
|
- this._target = document.getElementById(target);
|
|
|
-
|
|
|
- this.client = new Dropbox.Client({ key: 'b7dzc9ei5dv5hcv', token: '' });
|
|
|
- this.client.authDriver(new Dropbox.AuthDriver.Redirect());
|
|
|
- this.authenticate();
|
|
|
-
|
|
|
- if (this.client.credentials().token) {
|
|
|
- this.getDirectory();
|
|
|
- }
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'authenticate',
|
|
|
- value: function authenticate() {
|
|
|
- this.client.authenticate();
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'addFile',
|
|
|
- value: function addFile() {}
|
|
|
- }, {
|
|
|
- key: 'getDirectory',
|
|
|
- value: function getDirectory() {
|
|
|
- var _this = this;
|
|
|
-
|
|
|
- // request.get(`https://api18.dropbox.com/1/metadata/auto/`)
|
|
|
- // .query({
|
|
|
- // client_id: 'b7dzc9ei5dv5hcv',
|
|
|
- // token: this.client.credentials().token
|
|
|
- // })
|
|
|
- // .set('Content-Type', 'application/json')
|
|
|
- // .end((err, res) => {
|
|
|
- // console.log(res);
|
|
|
- // })
|
|
|
-
|
|
|
- return this.client.readdir(this.currentDir, function (error, entries, stat, statFiles) {
|
|
|
- if (error) {
|
|
|
- return showError(error); // Something went wrong.
|
|
|
- }
|
|
|
- return _this.render(statFiles);
|
|
|
- });
|
|
|
- }
|
|
|
- }, {
|
|
|
- key: 'run',
|
|
|
- value: function run() {}
|
|
|
- }, {
|
|
|
- key: 'render',
|
|
|
- value: function render(files) {
|
|
|
- var _this2 = this;
|
|
|
-
|
|
|
- // for each file in the directory, create a list item element
|
|
|
- var elems = files.map(function (file, i) {
|
|
|
- var icon = file.isFolder ? 'folder' : 'file';
|
|
|
- return '<li data-type="' + icon + '" data-name="' + file.name + '"><span>' + icon + ' : </span><span> ' + file.name + '</span></li>';
|
|
|
- });
|
|
|
-
|
|
|
- // appends the list items to the target
|
|
|
- this._target.innerHTML = elems.sort().join('');
|
|
|
-
|
|
|
- if (this.currentDir.length > 1) {
|
|
|
- var _parent = document.createElement('LI');
|
|
|
- _parent.setAttribute('data-type', 'parent');
|
|
|
- _parent.innerHTML = '<span>...</span>';
|
|
|
- this._target.appendChild(_parent);
|
|
|
- }
|
|
|
-
|
|
|
- // add an onClick to each list item
|
|
|
- var fileElems = this._target.querySelectorAll('li');
|
|
|
-
|
|
|
- Array.prototype.forEach.call(fileElems, function (element) {
|
|
|
- var type = element.getAttribute('data-type');
|
|
|
-
|
|
|
- if (type === 'file') {
|
|
|
- element.addEventListener('click', function () {
|
|
|
- _this2.files.push(element.getAttribute('data-name'));
|
|
|
- console.dir('files: ' + _this2.files);
|
|
|
- });
|
|
|
- } else {
|
|
|
- element.addEventListener('dblclick', function () {
|
|
|
- var length = _this2.currentDir.split('/').length;
|
|
|
-
|
|
|
- if (type === 'folder') {
|
|
|
- _this2.currentDir = '' + _this2.currentDir + element.getAttribute('data-name') + '/';
|
|
|
- } else if (type === 'parent') {
|
|
|
- _this2.currentDir = _this2.currentDir.split('/').slice(0, length - 2).join('/') + '/';
|
|
|
- }
|
|
|
- console.log(_this2.currentDir);
|
|
|
- _this2.getDirectory();
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }]);
|
|
|
-
|
|
|
- return DropboxPlugin;
|
|
|
-})();
|
|
|
-
|
|
|
-exports['default'] = new DropboxPlugin();
|
|
|
-module.exports = exports['default'];
|
|
|
-
|
|
|
-},{"superagent":11}],7:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
+/**
|
|
|
+ * Return the mime type for the given `str`.
|
|
|
+ *
|
|
|
+ * @param {String} str
|
|
|
+ * @return {String}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
-var _get = function get(_x, _x2, _x3) {
|
|
|
- var _again = true;_function: while (_again) {
|
|
|
- var object = _x,
|
|
|
- property = _x2,
|
|
|
- receiver = _x3;_again = false;if (object === null) object = Function.prototype;var desc = Object.getOwnPropertyDescriptor(object, property);if (desc === undefined) {
|
|
|
- var parent = Object.getPrototypeOf(object);if (parent === null) {
|
|
|
- return undefined;
|
|
|
- } else {
|
|
|
- _x = parent;_x2 = property;_x3 = receiver;_again = true;desc = parent = undefined;continue _function;
|
|
|
- }
|
|
|
- } else if ('value' in desc) {
|
|
|
- return desc.value;
|
|
|
- } else {
|
|
|
- var getter = desc.get;if (getter === undefined) {
|
|
|
- return undefined;
|
|
|
- }return getter.call(receiver);
|
|
|
- }
|
|
|
- }
|
|
|
+function type(str){
|
|
|
+ return str.split(/ *; */).shift();
|
|
|
};
|
|
|
|
|
|
-function _interopRequireDefault(obj) {
|
|
|
- return obj && obj.__esModule ? obj : { 'default': obj };
|
|
|
-}
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) {
|
|
|
- if (!(instance instanceof Constructor)) {
|
|
|
- throw new TypeError('Cannot call a class as a function');
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-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 _TransloaditPlugin2 = require('./TransloaditPlugin');
|
|
|
-
|
|
|
-var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
|
|
|
-
|
|
|
-var TransloaditBasic = (function (_TransloaditPlugin) {
|
|
|
- _inherits(TransloaditBasic, _TransloaditPlugin);
|
|
|
-
|
|
|
- function TransloaditBasic(core, opts) {
|
|
|
- _classCallCheck(this, TransloaditBasic);
|
|
|
-
|
|
|
- _get(Object.getPrototypeOf(TransloaditBasic.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'presetter';
|
|
|
- this.core.use(DragDrop, { modal: true, wait: true }).use(Tus10, { endpoint: 'http://master.tus.io:8080' });
|
|
|
- }
|
|
|
-
|
|
|
- return TransloaditBasic;
|
|
|
-})(_TransloaditPlugin3['default']);
|
|
|
-
|
|
|
-},{"./TransloaditPlugin":8}],8:[function(require,module,exports){
|
|
|
-"use strict";
|
|
|
-
|
|
|
-Object.defineProperty(exports, "__esModule", {
|
|
|
- value: true
|
|
|
-});
|
|
|
-
|
|
|
-var _createClass = (function () {
|
|
|
- function defineProperties(target, props) {
|
|
|
- for (var i = 0; i < props.length; i++) {
|
|
|
- var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
|
|
|
- }
|
|
|
- }return function (Constructor, protoProps, staticProps) {
|
|
|
- if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
|
|
|
- };
|
|
|
-})();
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) {
|
|
|
- if (!(instance instanceof Constructor)) {
|
|
|
- throw new TypeError("Cannot call a class as a function");
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-var TransloaditPlugin = (function () {
|
|
|
- // This contains boilerplate that all TransloaditPlugins share - and should not be used
|
|
|
- // directly. It also shows which methods final plugins should implement/override,
|
|
|
- // this deciding on structure.
|
|
|
-
|
|
|
- function TransloaditPlugin(core, opts) {
|
|
|
- _classCallCheck(this, TransloaditPlugin);
|
|
|
-
|
|
|
- this.core = core;
|
|
|
- this.opts = opts;
|
|
|
- this.name = this.constructor.name;
|
|
|
- }
|
|
|
-
|
|
|
- _createClass(TransloaditPlugin, [{
|
|
|
- key: "run",
|
|
|
- value: function run(files) {
|
|
|
- return files;
|
|
|
- }
|
|
|
- }]);
|
|
|
+/**
|
|
|
+ * Return header field parameters.
|
|
|
+ *
|
|
|
+ * @param {String} str
|
|
|
+ * @return {Object}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
- return TransloaditPlugin;
|
|
|
-})();
|
|
|
+function params(str){
|
|
|
+ return reduce(str.split(/ *; */), function(obj, str){
|
|
|
+ var parts = str.split(/ *= */)
|
|
|
+ , key = parts.shift()
|
|
|
+ , val = parts.shift();
|
|
|
|
|
|
-exports["default"] = TransloaditPlugin;
|
|
|
-module.exports = exports["default"];
|
|
|
+ if (key && val) obj[key] = val;
|
|
|
+ return obj;
|
|
|
+ }, {});
|
|
|
+};
|
|
|
|
|
|
-},{}],9:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
+/**
|
|
|
+ * Initialize a new `Response` with the given `xhr`.
|
|
|
+ *
|
|
|
+ * - set flags (.ok, .error, etc)
|
|
|
+ * - parse header
|
|
|
+ *
|
|
|
+ * Examples:
|
|
|
+ *
|
|
|
+ * Aliasing `superagent` as `request` is nice:
|
|
|
+ *
|
|
|
+ * request = superagent;
|
|
|
+ *
|
|
|
+ * We can use the promise-like API, or pass callbacks:
|
|
|
+ *
|
|
|
+ * request.get('/').end(function(res){});
|
|
|
+ * request.get('/', function(res){});
|
|
|
+ *
|
|
|
+ * Sending data can be chained:
|
|
|
+ *
|
|
|
+ * request
|
|
|
+ * .post('/user')
|
|
|
+ * .send({ name: 'tj' })
|
|
|
+ * .end(function(res){});
|
|
|
+ *
|
|
|
+ * Or passed to `.send()`:
|
|
|
+ *
|
|
|
+ * request
|
|
|
+ * .post('/user')
|
|
|
+ * .send({ name: 'tj' }, function(res){});
|
|
|
+ *
|
|
|
+ * Or passed to `.post()`:
|
|
|
+ *
|
|
|
+ * request
|
|
|
+ * .post('/user', { name: 'tj' })
|
|
|
+ * .end(function(res){});
|
|
|
+ *
|
|
|
+ * Or further reduced to a single call for simple cases:
|
|
|
+ *
|
|
|
+ * request
|
|
|
+ * .post('/user', { name: 'tj' }, function(res){});
|
|
|
+ *
|
|
|
+ * @param {XMLHTTPRequest} xhr
|
|
|
+ * @param {Object} options
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
+function Response(req, options) {
|
|
|
+ options = options || {};
|
|
|
+ this.req = req;
|
|
|
+ this.xhr = this.req.xhr;
|
|
|
+ // responseText is accessible only if responseType is '' or 'text' and on older browsers
|
|
|
+ this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined')
|
|
|
+ ? this.xhr.responseText
|
|
|
+ : null;
|
|
|
+ this.statusText = this.req.xhr.statusText;
|
|
|
+ this.setStatusProperties(this.xhr.status);
|
|
|
+ this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
|
|
+ // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
|
|
+ // getResponseHeader still works. so we get content-type even if getting
|
|
|
+ // other headers fails.
|
|
|
+ this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
|
|
+ this.setHeaderProperties(this.header);
|
|
|
+ this.body = this.req.method != 'HEAD'
|
|
|
+ ? this.parseBody(this.text ? this.text : this.xhr.response)
|
|
|
+ : null;
|
|
|
+}
|
|
|
|
|
|
-var _createClass = (function () {
|
|
|
- function defineProperties(target, props) {
|
|
|
- for (var i = 0; i < props.length; i++) {
|
|
|
- var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
|
|
|
- }
|
|
|
- }return function (Constructor, protoProps, staticProps) {
|
|
|
- if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
|
|
|
- };
|
|
|
-})();
|
|
|
+/**
|
|
|
+ * Get case-insensitive `field` value.
|
|
|
+ *
|
|
|
+ * @param {String} field
|
|
|
+ * @return {String}
|
|
|
+ * @api public
|
|
|
+ */
|
|
|
|
|
|
-var _get = function get(_x, _x2, _x3) {
|
|
|
- var _again = true;_function: while (_again) {
|
|
|
- var object = _x,
|
|
|
- property = _x2,
|
|
|
- receiver = _x3;_again = false;if (object === null) object = Function.prototype;var desc = Object.getOwnPropertyDescriptor(object, property);if (desc === undefined) {
|
|
|
- var parent = Object.getPrototypeOf(object);if (parent === null) {
|
|
|
- return undefined;
|
|
|
- } else {
|
|
|
- _x = parent;_x2 = property;_x3 = receiver;_again = true;desc = parent = undefined;continue _function;
|
|
|
- }
|
|
|
- } else if ('value' in desc) {
|
|
|
- return desc.value;
|
|
|
- } else {
|
|
|
- var getter = desc.get;if (getter === undefined) {
|
|
|
- return undefined;
|
|
|
- }return getter.call(receiver);
|
|
|
- }
|
|
|
- }
|
|
|
+Response.prototype.get = function(field){
|
|
|
+ return this.header[field.toLowerCase()];
|
|
|
};
|
|
|
|
|
|
-function _interopRequireDefault(obj) {
|
|
|
- return obj && obj.__esModule ? obj : { 'default': obj };
|
|
|
-}
|
|
|
-
|
|
|
-function _classCallCheck(instance, Constructor) {
|
|
|
- if (!(instance instanceof Constructor)) {
|
|
|
- throw new TypeError('Cannot call a class as a function');
|
|
|
- }
|
|
|
-}
|
|
|
+/**
|
|
|
+ * Set header related properties:
|
|
|
+ *
|
|
|
+ * - `.type` the content type without params
|
|
|
+ *
|
|
|
+ * A response of "Content-Type: text/plain; charset=utf-8"
|
|
|
+ * will provide you with a `.type` of "text/plain".
|
|
|
+ *
|
|
|
+ * @param {Object} header
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
-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;
|
|
|
-}
|
|
|
+Response.prototype.setHeaderProperties = function(header){
|
|
|
+ // content-type
|
|
|
+ var ct = this.header['content-type'] || '';
|
|
|
+ this.type = type(ct);
|
|
|
|
|
|
-var _TransloaditPlugin2 = require('./TransloaditPlugin');
|
|
|
+ // params
|
|
|
+ var obj = params(ct);
|
|
|
+ for (var key in obj) this[key] = obj[key];
|
|
|
+};
|
|
|
|
|
|
-var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
|
|
|
+/**
|
|
|
+ * Parse the given body `str`.
|
|
|
+ *
|
|
|
+ * Used for auto-parsing of bodies. Parsers
|
|
|
+ * are defined on the `superagent.parse` object.
|
|
|
+ *
|
|
|
+ * @param {String} str
|
|
|
+ * @return {Mixed}
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
-var Tus10 = (function (_TransloaditPlugin) {
|
|
|
- _inherits(Tus10, _TransloaditPlugin);
|
|
|
+Response.prototype.parseBody = function(str){
|
|
|
+ var parse = request.parse[this.type];
|
|
|
+ return parse && str && (str.length || str instanceof Object)
|
|
|
+ ? parse(str)
|
|
|
+ : null;
|
|
|
+};
|
|
|
|
|
|
- function Tus10(core, opts) {
|
|
|
- _classCallCheck(this, Tus10);
|
|
|
+/**
|
|
|
+ * Set flags such as `.ok` based on `status`.
|
|
|
+ *
|
|
|
+ * For example a 2xx response will give you a `.ok` of __true__
|
|
|
+ * whereas 5xx will be __false__ and `.error` will be __true__. The
|
|
|
+ * `.clientError` and `.serverError` are also available to be more
|
|
|
+ * specific, and `.statusType` is the class of error ranging from 1..5
|
|
|
+ * sometimes useful for mapping respond colors etc.
|
|
|
+ *
|
|
|
+ * "sugar" properties are also defined for common cases. Currently providing:
|
|
|
+ *
|
|
|
+ * - .noContent
|
|
|
+ * - .badRequest
|
|
|
+ * - .unauthorized
|
|
|
+ * - .notAcceptable
|
|
|
+ * - .notFound
|
|
|
+ *
|
|
|
+ * @param {Number} status
|
|
|
+ * @api private
|
|
|
+ */
|
|
|
|
|
|
- _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts);
|
|
|
- this.type = 'uploader';
|
|
|
+Response.prototype.setStatusProperties = function(status){
|
|
|
+ // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
|
|
+ if (status === 1223) {
|
|
|
+ status = 204;
|
|
|
}
|
|
|
|
|
|
- _createClass(Tus10, [{
|
|
|
- key: 'run',
|
|
|
- value: function run(files) {
|
|
|
- this.core.setProgress(this, 0);
|
|
|
- var uploaded = [];
|
|
|
- for (var i in files) {
|
|
|
- var file = files[i];
|
|
|
- this.core.setProgress(this, i * 1 + 1);
|
|
|
- uploaded[i] = file;
|
|
|
- uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name;
|
|
|
- }
|
|
|
- this.core.setProgress(this, 100);
|
|
|
+ var type = status / 100 | 0;
|
|
|
|
|
|
- return uploaded;
|
|
|
- }
|
|
|
- }]);
|
|
|
+ // status / class
|
|
|
+ this.status = this.statusCode = status;
|
|
|
+ this.statusType = type;
|
|
|
|
|
|
- return Tus10;
|
|
|
-})(_TransloaditPlugin3['default']);
|
|
|
+ // basics
|
|
|
+ this.info = 1 == type;
|
|
|
+ this.ok = 2 == type;
|
|
|
+ this.clientError = 4 == type;
|
|
|
+ this.serverError = 5 == type;
|
|
|
+ this.error = (4 == type || 5 == type)
|
|
|
+ ? this.toError()
|
|
|
+ : false;
|
|
|
|
|
|
-exports['default'] = Tus10;
|
|
|
-module.exports = exports['default'];
|
|
|
+ // sugar
|
|
|
+ this.accepted = 202 == status;
|
|
|
+ this.noContent = 204 == status;
|
|
|
+ this.badRequest = 400 == status;
|
|
|
+ this.unauthorized = 401 == status;
|
|
|
+ this.notAcceptable = 406 == status;
|
|
|
+ this.notFound = 404 == status;
|
|
|
+ this.forbidden = 403 == status;
|
|
|
+};
|
|
|
|
|
|
-},{"./TransloaditPlugin":8}],10:[function(require,module,exports){
|
|
|
-'use strict';
|
|
|
+/**
|
|
|
+ * Return an `Error` representative of this response.
|
|
|
+ *
|
|
|
+ * @return {Error}
|
|
|
+ * @api public
|
|
|
+ */
|
|
|
|
|
|
-Object.defineProperty(exports, '__esModule', {
|
|
|
- value: true
|
|
|
-});
|
|
|
+Response.prototype.toError = function(){
|
|
|
+ var req = this.req;
|
|
|
+ var method = req.method;
|
|
|
+ var url = req.url;
|
|
|
|
|
|
-function _interopRequireDefault(obj) {
|
|
|
- return obj && obj.__esModule ? obj : { 'default': obj };
|
|
|
-}
|
|
|
+ var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')';
|
|
|
+ var err = new Error(msg);
|
|
|
+ err.status = this.status;
|
|
|
+ err.method = method;
|
|
|
+ err.url = url;
|
|
|
|
|
|
-var _TransloaditPlugin = require('./TransloaditPlugin');
|
|
|
+ return err;
|
|
|
+};
|
|
|
|
|
|
-var _TransloaditPlugin2 = _interopRequireDefault(_TransloaditPlugin);
|
|
|
+/**
|
|
|
+ * Expose `Response`.
|
|
|
+ */
|
|
|
|
|
|
-var _DragDrop = require('./DragDrop');
|
|
|
+request.Response = Response;
|
|
|
|
|
|
-var _DragDrop2 = _interopRequireDefault(_DragDrop);
|
|
|
+/**
|
|
|
+ * Initialize a new `Request` with the given `method` and `url`.
|
|
|
+ *
|
|
|
+ * @param {String} method
|
|
|
+ * @param {String} url
|
|
|
+ * @api public
|
|
|
+ */
|
|
|
|
|
|
-var _Dropbox = require('./Dropbox');
|
|
|
+function Request(method, url) {
|
|
|
+ var self = this;
|
|
|
+ Emitter.call(this);
|
|
|
+ this._query = this._query || [];
|
|
|
+ this.method = method;
|
|
|
+ this.url = url;
|
|
|
+ this.header = {};
|
|
|
+ this._header = {};
|
|
|
+ this.on('end', function(){
|
|
|
+ var err = null;
|
|
|
+ var res = null;
|
|
|
|
|
|
-var _Dropbox2 = _interopRequireDefault(_Dropbox);
|
|
|
+ try {
|
|
|
+ res = new Response(self);
|
|
|
+ } catch(e) {
|
|
|
+ err = new Error('Parser is unable to parse the response');
|
|
|
+ err.parse = true;
|
|
|
+ err.original = e;
|
|
|
+ return self.callback(err);
|
|
|
+ }
|
|
|
|
|
|
-var _TransloaditBasic = require('./TransloaditBasic');
|
|
|
+ self.emit('response', res);
|
|
|
|
|
|
-var _TransloaditBasic2 = _interopRequireDefault(_TransloaditBasic);
|
|
|
+ if (err) {
|
|
|
+ return self.callback(err, res);
|
|
|
+ }
|
|
|
|
|
|
-var _Tus10 = require('./Tus10');
|
|
|
+ if (res.status >= 200 && res.status < 300) {
|
|
|
+ return self.callback(err, res);
|
|
|
+ }
|
|
|
|
|
|
-var _Tus102 = _interopRequireDefault(_Tus10);
|
|
|
+ var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
|
|
+ new_err.original = err;
|
|
|
+ new_err.response = res;
|
|
|
+ new_err.status = res.status;
|
|
|
|
|
|
-exports['default'] = {
|
|
|
- TransloaditPlugin: _TransloaditPlugin2['default'],
|
|
|
- DropboxPlugin: _Dropbox2['default'],
|
|
|
- DragDrop: _DragDrop2['default'],
|
|
|
- TransloaditBasic: _TransloaditBasic2['default'],
|
|
|
- Tus10: _Tus102['default']
|
|
|
-};
|
|
|
-module.exports = exports['default'];
|
|
|
+ self.callback(new_err, res);
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
-},{"./DragDrop":5,"./Dropbox":6,"./TransloaditBasic":7,"./TransloaditPlugin":8,"./Tus10":9}],11:[function(require,module,exports){
|
|
|
/**
|
|
|
- * Module dependencies.
|
|
|
+ * Mixin `Emitter`.
|
|
|
*/
|
|
|
|
|
|
-var Emitter = require('emitter');
|
|
|
-var reduce = require('reduce');
|
|
|
+Emitter(Request.prototype);
|
|
|
|
|
|
/**
|
|
|
- * Root reference for iframes.
|
|
|
+ * Allow for extension
|
|
|
*/
|
|
|
|
|
|
-var root;
|
|
|
-if (typeof window !== 'undefined') { // Browser window
|
|
|
- root = window;
|
|
|
-} else if (typeof self !== 'undefined') { // Web Worker
|
|
|
- root = self;
|
|
|
-} else { // Other environments
|
|
|
- root = this;
|
|
|
+Request.prototype.use = function(fn) {
|
|
|
+ fn(this);
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Noop.
|
|
|
+ * Set timeout to `ms`.
|
|
|
+ *
|
|
|
+ * @param {Number} ms
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-function noop(){};
|
|
|
+Request.prototype.timeout = function(ms){
|
|
|
+ this._timeout = ms;
|
|
|
+ return this;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Check if `obj` is a host object,
|
|
|
- * we don't want to serialize these :)
|
|
|
- *
|
|
|
- * TODO: future proof, move to compoent land
|
|
|
+ * Clear previous timeout.
|
|
|
*
|
|
|
- * @param {Object} obj
|
|
|
- * @return {Boolean}
|
|
|
- * @api private
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-function isHost(obj) {
|
|
|
- var str = {}.toString.call(obj);
|
|
|
-
|
|
|
- switch (str) {
|
|
|
- case '[object File]':
|
|
|
- case '[object Blob]':
|
|
|
- case '[object FormData]':
|
|
|
- return true;
|
|
|
- default:
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
+Request.prototype.clearTimeout = function(){
|
|
|
+ this._timeout = 0;
|
|
|
+ clearTimeout(this._timer);
|
|
|
+ return this;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Determine XHR.
|
|
|
+ * Abort the request, and clear potential timeout.
|
|
|
+ *
|
|
|
+ * @return {Request}
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-request.getXHR = function () {
|
|
|
- if (root.XMLHttpRequest
|
|
|
- && (!root.location || 'file:' != root.location.protocol
|
|
|
- || !root.ActiveXObject)) {
|
|
|
- return new XMLHttpRequest;
|
|
|
- } else {
|
|
|
- try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {}
|
|
|
- try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {}
|
|
|
- try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
|
|
|
- try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
|
|
|
- }
|
|
|
- return false;
|
|
|
+Request.prototype.abort = function(){
|
|
|
+ if (this.aborted) return;
|
|
|
+ this.aborted = true;
|
|
|
+ this.xhr.abort();
|
|
|
+ this.clearTimeout();
|
|
|
+ this.emit('abort');
|
|
|
+ return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Removes leading and trailing whitespace, added to support IE.
|
|
|
+ * Set header `field` to `val`, or multiple fields with one object.
|
|
|
*
|
|
|
- * @param {String} s
|
|
|
- * @return {String}
|
|
|
- * @api private
|
|
|
+ * Examples:
|
|
|
+ *
|
|
|
+ * req.get('/')
|
|
|
+ * .set('Accept', 'application/json')
|
|
|
+ * .set('X-API-Key', 'foobar')
|
|
|
+ * .end(callback);
|
|
|
+ *
|
|
|
+ * req.get('/')
|
|
|
+ * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
|
+ * .end(callback);
|
|
|
+ *
|
|
|
+ * @param {String|Object} field
|
|
|
+ * @param {String} val
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-var trim = ''.trim
|
|
|
- ? function(s) { return s.trim(); }
|
|
|
- : function(s) { return s.replace(/(^\s*|\s*$)/g, ''); };
|
|
|
+Request.prototype.set = function(field, val){
|
|
|
+ if (isObject(field)) {
|
|
|
+ for (var key in field) {
|
|
|
+ this.set(key, field[key]);
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ this._header[field.toLowerCase()] = val;
|
|
|
+ this.header[field] = val;
|
|
|
+ return this;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Check if `obj` is an object.
|
|
|
+ * Remove header `field`.
|
|
|
*
|
|
|
- * @param {Object} obj
|
|
|
- * @return {Boolean}
|
|
|
- * @api private
|
|
|
+ * Example:
|
|
|
+ *
|
|
|
+ * req.get('/')
|
|
|
+ * .unset('User-Agent')
|
|
|
+ * .end(callback);
|
|
|
+ *
|
|
|
+ * @param {String} field
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-function isObject(obj) {
|
|
|
- return obj === Object(obj);
|
|
|
-}
|
|
|
+Request.prototype.unset = function(field){
|
|
|
+ delete this._header[field.toLowerCase()];
|
|
|
+ delete this.header[field];
|
|
|
+ return this;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Serialize the given `obj`.
|
|
|
+ * Get case-insensitive header `field` value.
|
|
|
*
|
|
|
- * @param {Object} obj
|
|
|
+ * @param {String} field
|
|
|
* @return {String}
|
|
|
* @api private
|
|
|
*/
|
|
|
|
|
|
-function serialize(obj) {
|
|
|
- if (!isObject(obj)) return obj;
|
|
|
- var pairs = [];
|
|
|
- for (var key in obj) {
|
|
|
- if (null != obj[key]) {
|
|
|
- pairs.push(encodeURIComponent(key)
|
|
|
- + '=' + encodeURIComponent(obj[key]));
|
|
|
- }
|
|
|
- }
|
|
|
- return pairs.join('&');
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Expose serialization method.
|
|
|
- */
|
|
|
-
|
|
|
- request.serializeObject = serialize;
|
|
|
-
|
|
|
- /**
|
|
|
- * Parse the given x-www-form-urlencoded `str`.
|
|
|
- *
|
|
|
- * @param {String} str
|
|
|
- * @return {Object}
|
|
|
- * @api private
|
|
|
- */
|
|
|
-
|
|
|
-function parseString(str) {
|
|
|
- var obj = {};
|
|
|
- var pairs = str.split('&');
|
|
|
- var parts;
|
|
|
- var pair;
|
|
|
-
|
|
|
- for (var i = 0, len = pairs.length; i < len; ++i) {
|
|
|
- pair = pairs[i];
|
|
|
- parts = pair.split('=');
|
|
|
- obj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
|
|
|
- }
|
|
|
-
|
|
|
- return obj;
|
|
|
-}
|
|
|
+Request.prototype.getHeader = function(field){
|
|
|
+ return this._header[field.toLowerCase()];
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Expose parser.
|
|
|
+ * Set Content-Type to `type`, mapping values from `request.types`.
|
|
|
+ *
|
|
|
+ * Examples:
|
|
|
+ *
|
|
|
+ * superagent.types.xml = 'application/xml';
|
|
|
+ *
|
|
|
+ * request.post('/')
|
|
|
+ * .type('xml')
|
|
|
+ * .send(xmlstring)
|
|
|
+ * .end(callback);
|
|
|
+ *
|
|
|
+ * request.post('/')
|
|
|
+ * .type('application/xml')
|
|
|
+ * .send(xmlstring)
|
|
|
+ * .end(callback);
|
|
|
+ *
|
|
|
+ * @param {String} type
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-request.parseString = parseString;
|
|
|
+Request.prototype.type = function(type){
|
|
|
+ this.set('Content-Type', request.types[type] || type);
|
|
|
+ return this;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Default MIME type map.
|
|
|
+ * Force given parser
|
|
|
*
|
|
|
- * superagent.types.xml = 'application/xml';
|
|
|
+ * Sets the body parser no matter type.
|
|
|
*
|
|
|
+ * @param {Function}
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-request.types = {
|
|
|
- html: 'text/html',
|
|
|
- json: 'application/json',
|
|
|
- xml: 'application/xml',
|
|
|
- urlencoded: 'application/x-www-form-urlencoded',
|
|
|
- 'form': 'application/x-www-form-urlencoded',
|
|
|
- 'form-data': 'application/x-www-form-urlencoded'
|
|
|
+Request.prototype.parse = function(fn){
|
|
|
+ this._parser = fn;
|
|
|
+ return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Default serialization map.
|
|
|
+ * Set Accept to `type`, mapping values from `request.types`.
|
|
|
*
|
|
|
- * superagent.serialize['application/xml'] = function(obj){
|
|
|
- * return 'generated xml here';
|
|
|
- * };
|
|
|
+ * Examples:
|
|
|
+ *
|
|
|
+ * superagent.types.json = 'application/json';
|
|
|
+ *
|
|
|
+ * request.get('/agent')
|
|
|
+ * .accept('json')
|
|
|
+ * .end(callback);
|
|
|
+ *
|
|
|
+ * request.get('/agent')
|
|
|
+ * .accept('application/json')
|
|
|
+ * .end(callback);
|
|
|
*
|
|
|
+ * @param {String} accept
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
- request.serialize = {
|
|
|
- 'application/x-www-form-urlencoded': serialize,
|
|
|
- 'application/json': JSON.stringify
|
|
|
- };
|
|
|
-
|
|
|
- /**
|
|
|
- * Default parsers.
|
|
|
- *
|
|
|
- * superagent.parse['application/xml'] = function(str){
|
|
|
- * return { object parsed from str };
|
|
|
- * };
|
|
|
- *
|
|
|
- */
|
|
|
-
|
|
|
-request.parse = {
|
|
|
- 'application/x-www-form-urlencoded': parseString,
|
|
|
- 'application/json': JSON.parse
|
|
|
+Request.prototype.accept = function(type){
|
|
|
+ this.set('Accept', request.types[type] || type);
|
|
|
+ return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Parse the given header `str` into
|
|
|
- * an object containing the mapped fields.
|
|
|
+ * Set Authorization field value with `user` and `pass`.
|
|
|
*
|
|
|
- * @param {String} str
|
|
|
- * @return {Object}
|
|
|
- * @api private
|
|
|
+ * @param {String} user
|
|
|
+ * @param {String} pass
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-function parseHeader(str) {
|
|
|
- var lines = str.split(/\r?\n/);
|
|
|
- var fields = {};
|
|
|
- var index;
|
|
|
- var line;
|
|
|
- var field;
|
|
|
- var val;
|
|
|
-
|
|
|
- lines.pop(); // trailing CRLF
|
|
|
+Request.prototype.auth = function(user, pass){
|
|
|
+ var str = btoa(user + ':' + pass);
|
|
|
+ this.set('Authorization', 'Basic ' + str);
|
|
|
+ return this;
|
|
|
+};
|
|
|
|
|
|
- for (var i = 0, len = lines.length; i < len; ++i) {
|
|
|
- line = lines[i];
|
|
|
- index = line.indexOf(':');
|
|
|
- field = line.slice(0, index).toLowerCase();
|
|
|
- val = trim(line.slice(index + 1));
|
|
|
- fields[field] = val;
|
|
|
- }
|
|
|
+/**
|
|
|
+* Add query-string `val`.
|
|
|
+*
|
|
|
+* Examples:
|
|
|
+*
|
|
|
+* request.get('/shoes')
|
|
|
+* .query('size=10')
|
|
|
+* .query({ color: 'blue' })
|
|
|
+*
|
|
|
+* @param {Object|String} val
|
|
|
+* @return {Request} for chaining
|
|
|
+* @api public
|
|
|
+*/
|
|
|
|
|
|
- return fields;
|
|
|
-}
|
|
|
+Request.prototype.query = function(val){
|
|
|
+ if ('string' != typeof val) val = serialize(val);
|
|
|
+ if (val) this._query.push(val);
|
|
|
+ return this;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Return the mime type for the given `str`.
|
|
|
+ * Write the field `name` and `val` for "multipart/form-data"
|
|
|
+ * request bodies.
|
|
|
*
|
|
|
- * @param {String} str
|
|
|
- * @return {String}
|
|
|
- * @api private
|
|
|
+ * ``` js
|
|
|
+ * request.post('/upload')
|
|
|
+ * .field('foo', 'bar')
|
|
|
+ * .end(callback);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * @param {String} name
|
|
|
+ * @param {String|Blob|File} val
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-function type(str){
|
|
|
- return str.split(/ *; */).shift();
|
|
|
+Request.prototype.field = function(name, val){
|
|
|
+ if (!this._formData) this._formData = new root.FormData();
|
|
|
+ this._formData.append(name, val);
|
|
|
+ return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Return header field parameters.
|
|
|
+ * Queue the given `file` as an attachment to the specified `field`,
|
|
|
+ * with optional `filename`.
|
|
|
*
|
|
|
- * @param {String} str
|
|
|
- * @return {Object}
|
|
|
- * @api private
|
|
|
+ * ``` js
|
|
|
+ * request.post('/upload')
|
|
|
+ * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
|
+ * .end(callback);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * @param {String} field
|
|
|
+ * @param {Blob|File} file
|
|
|
+ * @param {String} filename
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-function params(str){
|
|
|
- return reduce(str.split(/ *; */), function(obj, str){
|
|
|
- var parts = str.split(/ *= */)
|
|
|
- , key = parts.shift()
|
|
|
- , val = parts.shift();
|
|
|
-
|
|
|
- if (key && val) obj[key] = val;
|
|
|
- return obj;
|
|
|
- }, {});
|
|
|
+Request.prototype.attach = function(field, file, filename){
|
|
|
+ if (!this._formData) this._formData = new root.FormData();
|
|
|
+ this._formData.append(field, file, filename);
|
|
|
+ return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Initialize a new `Response` with the given `xhr`.
|
|
|
- *
|
|
|
- * - set flags (.ok, .error, etc)
|
|
|
- * - parse header
|
|
|
+ * Send `data`, defaulting the `.type()` to "json" when
|
|
|
+ * an object is given.
|
|
|
*
|
|
|
* Examples:
|
|
|
*
|
|
|
- * Aliasing `superagent` as `request` is nice:
|
|
|
- *
|
|
|
- * request = superagent;
|
|
|
- *
|
|
|
- * We can use the promise-like API, or pass callbacks:
|
|
|
- *
|
|
|
- * request.get('/').end(function(res){});
|
|
|
- * request.get('/', function(res){});
|
|
|
- *
|
|
|
- * Sending data can be chained:
|
|
|
- *
|
|
|
- * request
|
|
|
- * .post('/user')
|
|
|
- * .send({ name: 'tj' })
|
|
|
- * .end(function(res){});
|
|
|
+ * // querystring
|
|
|
+ * request.get('/search')
|
|
|
+ * .end(callback)
|
|
|
*
|
|
|
- * Or passed to `.send()`:
|
|
|
+ * // multiple data "writes"
|
|
|
+ * request.get('/search')
|
|
|
+ * .send({ search: 'query' })
|
|
|
+ * .send({ range: '1..5' })
|
|
|
+ * .send({ order: 'desc' })
|
|
|
+ * .end(callback)
|
|
|
*
|
|
|
- * request
|
|
|
- * .post('/user')
|
|
|
- * .send({ name: 'tj' }, function(res){});
|
|
|
+ * // manual json
|
|
|
+ * request.post('/user')
|
|
|
+ * .type('json')
|
|
|
+ * .send('{"name":"tj"}')
|
|
|
+ * .end(callback)
|
|
|
*
|
|
|
- * Or passed to `.post()`:
|
|
|
+ * // auto json
|
|
|
+ * request.post('/user')
|
|
|
+ * .send({ name: 'tj' })
|
|
|
+ * .end(callback)
|
|
|
*
|
|
|
- * request
|
|
|
- * .post('/user', { name: 'tj' })
|
|
|
- * .end(function(res){});
|
|
|
+ * // manual x-www-form-urlencoded
|
|
|
+ * request.post('/user')
|
|
|
+ * .type('form')
|
|
|
+ * .send('name=tj')
|
|
|
+ * .end(callback)
|
|
|
*
|
|
|
- * Or further reduced to a single call for simple cases:
|
|
|
+ * // auto x-www-form-urlencoded
|
|
|
+ * request.post('/user')
|
|
|
+ * .type('form')
|
|
|
+ * .send({ name: 'tj' })
|
|
|
+ * .end(callback)
|
|
|
*
|
|
|
- * request
|
|
|
- * .post('/user', { name: 'tj' }, function(res){});
|
|
|
+ * // defaults to x-www-form-urlencoded
|
|
|
+ * request.post('/user')
|
|
|
+ * .send('name=tobi')
|
|
|
+ * .send('species=ferret')
|
|
|
+ * .end(callback)
|
|
|
*
|
|
|
- * @param {XMLHTTPRequest} xhr
|
|
|
- * @param {Object} options
|
|
|
- * @api private
|
|
|
+ * @param {String|Object} data
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-function Response(req, options) {
|
|
|
- options = options || {};
|
|
|
- this.req = req;
|
|
|
- this.xhr = this.req.xhr;
|
|
|
- // responseText is accessible only if responseType is '' or 'text' and on older browsers
|
|
|
- this.text = ((this.req.method !='HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text')) || typeof this.xhr.responseType === 'undefined')
|
|
|
- ? this.xhr.responseText
|
|
|
- : null;
|
|
|
- this.statusText = this.req.xhr.statusText;
|
|
|
- this.setStatusProperties(this.xhr.status);
|
|
|
- this.header = this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
|
|
- // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but
|
|
|
- // getResponseHeader still works. so we get content-type even if getting
|
|
|
- // other headers fails.
|
|
|
- this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
|
|
- this.setHeaderProperties(this.header);
|
|
|
- this.body = this.req.method != 'HEAD'
|
|
|
- ? this.parseBody(this.text ? this.text : this.xhr.response)
|
|
|
- : null;
|
|
|
-}
|
|
|
+Request.prototype.send = function(data){
|
|
|
+ var obj = isObject(data);
|
|
|
+ var type = this.getHeader('Content-Type');
|
|
|
+
|
|
|
+ // merge
|
|
|
+ if (obj && isObject(this._data)) {
|
|
|
+ for (var key in data) {
|
|
|
+ this._data[key] = data[key];
|
|
|
+ }
|
|
|
+ } else if ('string' == typeof data) {
|
|
|
+ if (!type) this.type('form');
|
|
|
+ type = this.getHeader('Content-Type');
|
|
|
+ if ('application/x-www-form-urlencoded' == type) {
|
|
|
+ this._data = this._data
|
|
|
+ ? this._data + '&' + data
|
|
|
+ : data;
|
|
|
+ } else {
|
|
|
+ this._data = (this._data || '') + data;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this._data = data;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!obj || isHost(data)) return this;
|
|
|
+ if (!type) this.type('json');
|
|
|
+ return this;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Get case-insensitive `field` value.
|
|
|
+ * Invoke the callback with `err` and `res`
|
|
|
+ * and handle arity check.
|
|
|
*
|
|
|
- * @param {String} field
|
|
|
- * @return {String}
|
|
|
- * @api public
|
|
|
+ * @param {Error} err
|
|
|
+ * @param {Response} res
|
|
|
+ * @api private
|
|
|
*/
|
|
|
|
|
|
-Response.prototype.get = function(field){
|
|
|
- return this.header[field.toLowerCase()];
|
|
|
+Request.prototype.callback = function(err, res){
|
|
|
+ var fn = this._callback;
|
|
|
+ this.clearTimeout();
|
|
|
+ fn(err, res);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Set header related properties:
|
|
|
- *
|
|
|
- * - `.type` the content type without params
|
|
|
- *
|
|
|
- * A response of "Content-Type: text/plain; charset=utf-8"
|
|
|
- * will provide you with a `.type` of "text/plain".
|
|
|
+ * Invoke callback with x-domain error.
|
|
|
*
|
|
|
- * @param {Object} header
|
|
|
* @api private
|
|
|
*/
|
|
|
|
|
|
-Response.prototype.setHeaderProperties = function(header){
|
|
|
- // content-type
|
|
|
- var ct = this.header['content-type'] || '';
|
|
|
- this.type = type(ct);
|
|
|
-
|
|
|
- // params
|
|
|
- var obj = params(ct);
|
|
|
- for (var key in obj) this[key] = obj[key];
|
|
|
+Request.prototype.crossDomainError = function(){
|
|
|
+ var err = new Error('Origin is not allowed by Access-Control-Allow-Origin');
|
|
|
+ err.crossDomain = true;
|
|
|
+ this.callback(err);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Force given parser
|
|
|
- *
|
|
|
- * Sets the body parser no matter type.
|
|
|
- *
|
|
|
- * @param {Function}
|
|
|
- * @api public
|
|
|
+ * Invoke callback with timeout error.
|
|
|
+ *
|
|
|
+ * @api private
|
|
|
*/
|
|
|
|
|
|
-Response.prototype.parse = function(fn){
|
|
|
- this.parser = fn;
|
|
|
- return this;
|
|
|
+Request.prototype.timeoutError = function(){
|
|
|
+ var timeout = this._timeout;
|
|
|
+ var err = new Error('timeout of ' + timeout + 'ms exceeded');
|
|
|
+ err.timeout = timeout;
|
|
|
+ this.callback(err);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Parse the given body `str`.
|
|
|
+ * Enable transmission of cookies with x-domain requests.
|
|
|
*
|
|
|
- * Used for auto-parsing of bodies. Parsers
|
|
|
- * are defined on the `superagent.parse` object.
|
|
|
+ * Note that for this to work the origin must not be
|
|
|
+ * using "Access-Control-Allow-Origin" with a wildcard,
|
|
|
+ * and also must set "Access-Control-Allow-Credentials"
|
|
|
+ * to "true".
|
|
|
*
|
|
|
- * @param {String} str
|
|
|
- * @return {Mixed}
|
|
|
- * @api private
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-Response.prototype.parseBody = function(str){
|
|
|
- var parse = this.parser || request.parse[this.type];
|
|
|
- return parse && str && (str.length || str instanceof Object)
|
|
|
- ? parse(str)
|
|
|
- : null;
|
|
|
+Request.prototype.withCredentials = function(){
|
|
|
+ this._withCredentials = true;
|
|
|
+ return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Set flags such as `.ok` based on `status`.
|
|
|
- *
|
|
|
- * For example a 2xx response will give you a `.ok` of __true__
|
|
|
- * whereas 5xx will be __false__ and `.error` will be __true__. The
|
|
|
- * `.clientError` and `.serverError` are also available to be more
|
|
|
- * specific, and `.statusType` is the class of error ranging from 1..5
|
|
|
- * sometimes useful for mapping respond colors etc.
|
|
|
- *
|
|
|
- * "sugar" properties are also defined for common cases. Currently providing:
|
|
|
- *
|
|
|
- * - .noContent
|
|
|
- * - .badRequest
|
|
|
- * - .unauthorized
|
|
|
- * - .notAcceptable
|
|
|
- * - .notFound
|
|
|
+ * Initiate request, invoking callback `fn(res)`
|
|
|
+ * with an instanceof `Response`.
|
|
|
*
|
|
|
- * @param {Number} status
|
|
|
- * @api private
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Request} for chaining
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-Response.prototype.setStatusProperties = function(status){
|
|
|
- // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request
|
|
|
- if (status === 1223) {
|
|
|
- status = 204;
|
|
|
+Request.prototype.end = function(fn){
|
|
|
+ var self = this;
|
|
|
+ var xhr = this.xhr = request.getXHR();
|
|
|
+ var query = this._query.join('&');
|
|
|
+ var timeout = this._timeout;
|
|
|
+ var data = this._formData || this._data;
|
|
|
+
|
|
|
+ // store callback
|
|
|
+ this._callback = fn || noop;
|
|
|
+
|
|
|
+ // state change
|
|
|
+ xhr.onreadystatechange = function(){
|
|
|
+ if (4 != xhr.readyState) return;
|
|
|
+
|
|
|
+ // In IE9, reads to any property (e.g. status) off of an aborted XHR will
|
|
|
+ // result in the error "Could not complete the operation due to error c00c023f"
|
|
|
+ var status;
|
|
|
+ try { status = xhr.status } catch(e) { status = 0; }
|
|
|
+
|
|
|
+ if (0 == status) {
|
|
|
+ if (self.timedout) return self.timeoutError();
|
|
|
+ if (self.aborted) return;
|
|
|
+ return self.crossDomainError();
|
|
|
+ }
|
|
|
+ self.emit('end');
|
|
|
+ };
|
|
|
+
|
|
|
+ // progress
|
|
|
+ var handleProgress = function(e){
|
|
|
+ if (e.total > 0) {
|
|
|
+ e.percent = e.loaded / e.total * 100;
|
|
|
+ }
|
|
|
+ self.emit('progress', e);
|
|
|
+ };
|
|
|
+ if (this.hasListeners('progress')) {
|
|
|
+ xhr.onprogress = handleProgress;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (xhr.upload && this.hasListeners('progress')) {
|
|
|
+ xhr.upload.onprogress = handleProgress;
|
|
|
+ }
|
|
|
+ } catch(e) {
|
|
|
+ // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist.
|
|
|
+ // Reported here:
|
|
|
+ // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context
|
|
|
}
|
|
|
|
|
|
- var type = status / 100 | 0;
|
|
|
+ // timeout
|
|
|
+ if (timeout && !this._timer) {
|
|
|
+ this._timer = setTimeout(function(){
|
|
|
+ self.timedout = true;
|
|
|
+ self.abort();
|
|
|
+ }, timeout);
|
|
|
+ }
|
|
|
|
|
|
- // status / class
|
|
|
- this.status = this.statusCode = status;
|
|
|
- this.statusType = type;
|
|
|
+ // querystring
|
|
|
+ if (query) {
|
|
|
+ query = request.serializeObject(query);
|
|
|
+ this.url += ~this.url.indexOf('?')
|
|
|
+ ? '&' + query
|
|
|
+ : '?' + query;
|
|
|
+ }
|
|
|
|
|
|
- // basics
|
|
|
- this.info = 1 == type;
|
|
|
- this.ok = 2 == type;
|
|
|
- this.clientError = 4 == type;
|
|
|
- this.serverError = 5 == type;
|
|
|
- this.error = (4 == type || 5 == type)
|
|
|
- ? this.toError()
|
|
|
- : false;
|
|
|
+ // initiate request
|
|
|
+ xhr.open(this.method, this.url, true);
|
|
|
|
|
|
- // sugar
|
|
|
- this.accepted = 202 == status;
|
|
|
- this.noContent = 204 == status;
|
|
|
- this.badRequest = 400 == status;
|
|
|
- this.unauthorized = 401 == status;
|
|
|
- this.notAcceptable = 406 == status;
|
|
|
- this.notFound = 404 == status;
|
|
|
- this.forbidden = 403 == status;
|
|
|
+ // CORS
|
|
|
+ if (this._withCredentials) xhr.withCredentials = true;
|
|
|
+
|
|
|
+ // body
|
|
|
+ if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
|
|
|
+ // serialize stuff
|
|
|
+ var contentType = this.getHeader('Content-Type');
|
|
|
+ var serialize = this._parser || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
|
|
+ if (serialize) data = serialize(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // set header fields
|
|
|
+ for (var field in this.header) {
|
|
|
+ if (null == this.header[field]) continue;
|
|
|
+ xhr.setRequestHeader(field, this.header[field]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // send stuff
|
|
|
+ this.emit('request', this);
|
|
|
+
|
|
|
+ // IE11 xhr.send(undefined) sends 'undefined' string as POST payload (instead of nothing)
|
|
|
+ // We need null here if data is undefined
|
|
|
+ xhr.send(typeof data !== 'undefined' ? data : null);
|
|
|
+ return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Return an `Error` representative of this response.
|
|
|
+ * Faux promise support
|
|
|
*
|
|
|
- * @return {Error}
|
|
|
- * @api public
|
|
|
+ * @param {Function} fulfill
|
|
|
+ * @param {Function} reject
|
|
|
+ * @return {Request}
|
|
|
*/
|
|
|
|
|
|
-Response.prototype.toError = function(){
|
|
|
- var req = this.req;
|
|
|
- var method = req.method;
|
|
|
- var url = req.url;
|
|
|
-
|
|
|
- var msg = 'cannot ' + method + ' ' + url + ' (' + this.status + ')';
|
|
|
- var err = new Error(msg);
|
|
|
- err.status = this.status;
|
|
|
- err.method = method;
|
|
|
- err.url = url;
|
|
|
-
|
|
|
- return err;
|
|
|
-};
|
|
|
+Request.prototype.then = function (fulfill, reject) {
|
|
|
+ return this.end(function(err, res) {
|
|
|
+ err ? reject(err) : fulfill(res);
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
- * Expose `Response`.
|
|
|
+ * Expose `Request`.
|
|
|
*/
|
|
|
|
|
|
-request.Response = Response;
|
|
|
+request.Request = Request;
|
|
|
|
|
|
/**
|
|
|
- * Initialize a new `Request` with the given `method` and `url`.
|
|
|
+ * Issue a request:
|
|
|
+ *
|
|
|
+ * Examples:
|
|
|
+ *
|
|
|
+ * request('GET', '/users').end(callback)
|
|
|
+ * request('/users').end(callback)
|
|
|
+ * request('/users', callback)
|
|
|
*
|
|
|
* @param {String} method
|
|
|
- * @param {String} url
|
|
|
+ * @param {String|Function} url or callback
|
|
|
+ * @return {Request}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-function Request(method, url) {
|
|
|
- var self = this;
|
|
|
- Emitter.call(this);
|
|
|
- this._query = this._query || [];
|
|
|
- this.method = method;
|
|
|
- this.url = url;
|
|
|
- this.header = {};
|
|
|
- this._header = {};
|
|
|
- this.on('end', function(){
|
|
|
- var err = null;
|
|
|
- var res = null;
|
|
|
-
|
|
|
- try {
|
|
|
- res = new Response(self);
|
|
|
- } catch(e) {
|
|
|
- err = new Error('Parser is unable to parse the response');
|
|
|
- err.parse = true;
|
|
|
- err.original = e;
|
|
|
- return self.callback(err);
|
|
|
- }
|
|
|
-
|
|
|
- self.emit('response', res);
|
|
|
-
|
|
|
- if (err) {
|
|
|
- return self.callback(err, res);
|
|
|
- }
|
|
|
-
|
|
|
- if (res.status >= 200 && res.status < 300) {
|
|
|
- return self.callback(err, res);
|
|
|
- }
|
|
|
+function request(method, url) {
|
|
|
+ // callback
|
|
|
+ if ('function' == typeof url) {
|
|
|
+ return new Request('GET', method).end(url);
|
|
|
+ }
|
|
|
|
|
|
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
|
|
- new_err.original = err;
|
|
|
- new_err.response = res;
|
|
|
- new_err.status = res.status;
|
|
|
+ // url first
|
|
|
+ if (1 == arguments.length) {
|
|
|
+ return new Request('GET', method);
|
|
|
+ }
|
|
|
|
|
|
- self.callback(new_err, res);
|
|
|
- });
|
|
|
+ return new Request(method, url);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Mixin `Emitter`.
|
|
|
+ * GET `url` with optional callback `fn(res)`.
|
|
|
+ *
|
|
|
+ * @param {String} url
|
|
|
+ * @param {Mixed|Function} data or fn
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Request}
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-Emitter(Request.prototype);
|
|
|
+request.get = function(url, data, fn){
|
|
|
+ var req = request('GET', url);
|
|
|
+ if ('function' == typeof data) fn = data, data = null;
|
|
|
+ if (data) req.query(data);
|
|
|
+ if (fn) req.end(fn);
|
|
|
+ return req;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Allow for extension
|
|
|
+ * HEAD `url` with optional callback `fn(res)`.
|
|
|
+ *
|
|
|
+ * @param {String} url
|
|
|
+ * @param {Mixed|Function} data or fn
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Request}
|
|
|
+ * @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.use = function(fn) {
|
|
|
- fn(this);
|
|
|
- return this;
|
|
|
-}
|
|
|
+request.head = function(url, data, fn){
|
|
|
+ var req = request('HEAD', url);
|
|
|
+ if ('function' == typeof data) fn = data, data = null;
|
|
|
+ if (data) req.send(data);
|
|
|
+ if (fn) req.end(fn);
|
|
|
+ return req;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- * Set timeout to `ms`.
|
|
|
+ * DELETE `url` with optional callback `fn(res)`.
|
|
|
*
|
|
|
- * @param {Number} ms
|
|
|
- * @return {Request} for chaining
|
|
|
+ * @param {String} url
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Request}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.timeout = function(ms){
|
|
|
- this._timeout = ms;
|
|
|
- return this;
|
|
|
+function del(url, fn){
|
|
|
+ var req = request('DELETE', url);
|
|
|
+ if (fn) req.end(fn);
|
|
|
+ return req;
|
|
|
};
|
|
|
|
|
|
+request.del = del;
|
|
|
+request.delete = del;
|
|
|
+
|
|
|
/**
|
|
|
- * Clear previous timeout.
|
|
|
+ * PATCH `url` with optional `data` and callback `fn(res)`.
|
|
|
*
|
|
|
- * @return {Request} for chaining
|
|
|
+ * @param {String} url
|
|
|
+ * @param {Mixed} data
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Request}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.clearTimeout = function(){
|
|
|
- this._timeout = 0;
|
|
|
- clearTimeout(this._timer);
|
|
|
- return this;
|
|
|
+request.patch = function(url, data, fn){
|
|
|
+ var req = request('PATCH', url);
|
|
|
+ if ('function' == typeof data) fn = data, data = null;
|
|
|
+ if (data) req.send(data);
|
|
|
+ if (fn) req.end(fn);
|
|
|
+ return req;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Abort the request, and clear potential timeout.
|
|
|
+ * POST `url` with optional `data` and callback `fn(res)`.
|
|
|
*
|
|
|
+ * @param {String} url
|
|
|
+ * @param {Mixed} data
|
|
|
+ * @param {Function} fn
|
|
|
* @return {Request}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.abort = function(){
|
|
|
- if (this.aborted) return;
|
|
|
- this.aborted = true;
|
|
|
- this.xhr.abort();
|
|
|
- this.clearTimeout();
|
|
|
- this.emit('abort');
|
|
|
- return this;
|
|
|
+request.post = function(url, data, fn){
|
|
|
+ var req = request('POST', url);
|
|
|
+ if ('function' == typeof data) fn = data, data = null;
|
|
|
+ if (data) req.send(data);
|
|
|
+ if (fn) req.end(fn);
|
|
|
+ return req;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Set header `field` to `val`, or multiple fields with one object.
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * req.get('/')
|
|
|
- * .set('Accept', 'application/json')
|
|
|
- * .set('X-API-Key', 'foobar')
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * req.get('/')
|
|
|
- * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' })
|
|
|
- * .end(callback);
|
|
|
+ * PUT `url` with optional `data` and callback `fn(res)`.
|
|
|
*
|
|
|
- * @param {String|Object} field
|
|
|
- * @param {String} val
|
|
|
- * @return {Request} for chaining
|
|
|
+ * @param {String} url
|
|
|
+ * @param {Mixed|Function} data or fn
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Request}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.set = function(field, val){
|
|
|
- if (isObject(field)) {
|
|
|
- for (var key in field) {
|
|
|
- this.set(key, field[key]);
|
|
|
- }
|
|
|
- return this;
|
|
|
- }
|
|
|
- this._header[field.toLowerCase()] = val;
|
|
|
- this.header[field] = val;
|
|
|
- return this;
|
|
|
+request.put = function(url, data, fn){
|
|
|
+ var req = request('PUT', url);
|
|
|
+ if ('function' == typeof data) fn = data, data = null;
|
|
|
+ if (data) req.send(data);
|
|
|
+ if (fn) req.end(fn);
|
|
|
+ return req;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Remove header `field`.
|
|
|
- *
|
|
|
- * Example:
|
|
|
- *
|
|
|
- * req.get('/')
|
|
|
- * .unset('User-Agent')
|
|
|
- * .end(callback);
|
|
|
+ * Expose `request`.
|
|
|
+ */
|
|
|
+
|
|
|
+module.exports = request;
|
|
|
+
|
|
|
+},{"emitter":2,"reduce":3}],2:[function(require,module,exports){
|
|
|
+
|
|
|
+/**
|
|
|
+ * Expose `Emitter`.
|
|
|
+ */
|
|
|
+
|
|
|
+module.exports = Emitter;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Initialize a new `Emitter`.
|
|
|
*
|
|
|
- * @param {String} field
|
|
|
- * @return {Request} for chaining
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.unset = function(field){
|
|
|
- delete this._header[field.toLowerCase()];
|
|
|
- delete this.header[field];
|
|
|
- return this;
|
|
|
+function Emitter(obj) {
|
|
|
+ if (obj) return mixin(obj);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Get case-insensitive header `field` value.
|
|
|
+ * Mixin the emitter properties.
|
|
|
*
|
|
|
- * @param {String} field
|
|
|
- * @return {String}
|
|
|
+ * @param {Object} obj
|
|
|
+ * @return {Object}
|
|
|
* @api private
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.getHeader = function(field){
|
|
|
- return this._header[field.toLowerCase()];
|
|
|
-};
|
|
|
+function mixin(obj) {
|
|
|
+ for (var key in Emitter.prototype) {
|
|
|
+ obj[key] = Emitter.prototype[key];
|
|
|
+ }
|
|
|
+ return obj;
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
- * Set Content-Type to `type`, mapping values from `request.types`.
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * superagent.types.xml = 'application/xml';
|
|
|
- *
|
|
|
- * request.post('/')
|
|
|
- * .type('xml')
|
|
|
- * .send(xmlstring)
|
|
|
- * .end(callback);
|
|
|
- *
|
|
|
- * request.post('/')
|
|
|
- * .type('application/xml')
|
|
|
- * .send(xmlstring)
|
|
|
- * .end(callback);
|
|
|
+ * Listen on the given `event` with `fn`.
|
|
|
*
|
|
|
- * @param {String} type
|
|
|
- * @return {Request} for chaining
|
|
|
+ * @param {String} event
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Emitter}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.type = function(type){
|
|
|
- this.set('Content-Type', request.types[type] || type);
|
|
|
+Emitter.prototype.on =
|
|
|
+Emitter.prototype.addEventListener = function(event, fn){
|
|
|
+ this._callbacks = this._callbacks || {};
|
|
|
+ (this._callbacks[event] = this._callbacks[event] || [])
|
|
|
+ .push(fn);
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Set Accept to `type`, mapping values from `request.types`.
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * superagent.types.json = 'application/json';
|
|
|
- *
|
|
|
- * request.get('/agent')
|
|
|
- * .accept('json')
|
|
|
- * .end(callback);
|
|
|
+ * Adds an `event` listener that will be invoked a single
|
|
|
+ * time then automatically removed.
|
|
|
*
|
|
|
- * request.get('/agent')
|
|
|
- * .accept('application/json')
|
|
|
- * .end(callback);
|
|
|
+ * @param {String} event
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Emitter}
|
|
|
+ * @api public
|
|
|
+ */
|
|
|
+
|
|
|
+Emitter.prototype.once = function(event, fn){
|
|
|
+ var self = this;
|
|
|
+ this._callbacks = this._callbacks || {};
|
|
|
+
|
|
|
+ function on() {
|
|
|
+ self.off(event, on);
|
|
|
+ fn.apply(this, arguments);
|
|
|
+ }
|
|
|
+
|
|
|
+ on.fn = fn;
|
|
|
+ this.on(event, on);
|
|
|
+ return this;
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * Remove the given callback for `event` or all
|
|
|
+ * registered callbacks.
|
|
|
*
|
|
|
- * @param {String} accept
|
|
|
- * @return {Request} for chaining
|
|
|
+ * @param {String} event
|
|
|
+ * @param {Function} fn
|
|
|
+ * @return {Emitter}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.accept = function(type){
|
|
|
- this.set('Accept', request.types[type] || type);
|
|
|
+Emitter.prototype.off =
|
|
|
+Emitter.prototype.removeListener =
|
|
|
+Emitter.prototype.removeAllListeners =
|
|
|
+Emitter.prototype.removeEventListener = function(event, fn){
|
|
|
+ this._callbacks = this._callbacks || {};
|
|
|
+
|
|
|
+ // all
|
|
|
+ if (0 == arguments.length) {
|
|
|
+ this._callbacks = {};
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ // specific event
|
|
|
+ var callbacks = this._callbacks[event];
|
|
|
+ if (!callbacks) return this;
|
|
|
+
|
|
|
+ // remove all handlers
|
|
|
+ if (1 == arguments.length) {
|
|
|
+ delete this._callbacks[event];
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ // remove specific handler
|
|
|
+ var cb;
|
|
|
+ for (var i = 0; i < callbacks.length; i++) {
|
|
|
+ cb = callbacks[i];
|
|
|
+ if (cb === fn || cb.fn === fn) {
|
|
|
+ callbacks.splice(i, 1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Set Authorization field value with `user` and `pass`.
|
|
|
+ * Emit `event` with the given args.
|
|
|
*
|
|
|
- * @param {String} user
|
|
|
- * @param {String} pass
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
+ * @param {String} event
|
|
|
+ * @param {Mixed} ...
|
|
|
+ * @return {Emitter}
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.auth = function(user, pass){
|
|
|
- var str = btoa(user + ':' + pass);
|
|
|
- this.set('Authorization', 'Basic ' + str);
|
|
|
- return this;
|
|
|
-};
|
|
|
+Emitter.prototype.emit = function(event){
|
|
|
+ this._callbacks = this._callbacks || {};
|
|
|
+ var args = [].slice.call(arguments, 1)
|
|
|
+ , callbacks = this._callbacks[event];
|
|
|
|
|
|
-/**
|
|
|
-* Add query-string `val`.
|
|
|
-*
|
|
|
-* Examples:
|
|
|
-*
|
|
|
-* request.get('/shoes')
|
|
|
-* .query('size=10')
|
|
|
-* .query({ color: 'blue' })
|
|
|
-*
|
|
|
-* @param {Object|String} val
|
|
|
-* @return {Request} for chaining
|
|
|
-* @api public
|
|
|
-*/
|
|
|
+ if (callbacks) {
|
|
|
+ callbacks = callbacks.slice(0);
|
|
|
+ for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
|
+ callbacks[i].apply(this, args);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-Request.prototype.query = function(val){
|
|
|
- if ('string' != typeof val) val = serialize(val);
|
|
|
- if (val) this._query.push(val);
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Write the field `name` and `val` for "multipart/form-data"
|
|
|
- * request bodies.
|
|
|
- *
|
|
|
- * ``` js
|
|
|
- * request.post('/upload')
|
|
|
- * .field('foo', 'bar')
|
|
|
- * .end(callback);
|
|
|
- * ```
|
|
|
+ * Return array of callbacks for `event`.
|
|
|
*
|
|
|
- * @param {String} name
|
|
|
- * @param {String|Blob|File} val
|
|
|
- * @return {Request} for chaining
|
|
|
+ * @param {String} event
|
|
|
+ * @return {Array}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.field = function(name, val){
|
|
|
- if (!this._formData) this._formData = new root.FormData();
|
|
|
- this._formData.append(name, val);
|
|
|
- return this;
|
|
|
+Emitter.prototype.listeners = function(event){
|
|
|
+ this._callbacks = this._callbacks || {};
|
|
|
+ return this._callbacks[event] || [];
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Queue the given `file` as an attachment to the specified `field`,
|
|
|
- * with optional `filename`.
|
|
|
- *
|
|
|
- * ``` js
|
|
|
- * request.post('/upload')
|
|
|
- * .attach(new Blob(['<a id="a"><b id="b">hey!</b></a>'], { type: "text/html"}))
|
|
|
- * .end(callback);
|
|
|
- * ```
|
|
|
+ * Check if this emitter has `event` handlers.
|
|
|
*
|
|
|
- * @param {String} field
|
|
|
- * @param {Blob|File} file
|
|
|
- * @param {String} filename
|
|
|
- * @return {Request} for chaining
|
|
|
+ * @param {String} event
|
|
|
+ * @return {Boolean}
|
|
|
* @api public
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.attach = function(field, file, filename){
|
|
|
- if (!this._formData) this._formData = new root.FormData();
|
|
|
- this._formData.append(field, file, filename);
|
|
|
- return this;
|
|
|
+Emitter.prototype.hasListeners = function(event){
|
|
|
+ return !! this.listeners(event).length;
|
|
|
};
|
|
|
|
|
|
+},{}],3:[function(require,module,exports){
|
|
|
+
|
|
|
/**
|
|
|
- * Send `data`, defaulting the `.type()` to "json" when
|
|
|
- * an object is given.
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * // querystring
|
|
|
- * request.get('/search')
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // multiple data "writes"
|
|
|
- * request.get('/search')
|
|
|
- * .send({ search: 'query' })
|
|
|
- * .send({ range: '1..5' })
|
|
|
- * .send({ order: 'desc' })
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // manual json
|
|
|
- * request.post('/user')
|
|
|
- * .type('json')
|
|
|
- * .send('{"name":"tj"})
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // auto json
|
|
|
- * request.post('/user')
|
|
|
- * .send({ name: 'tj' })
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // manual x-www-form-urlencoded
|
|
|
- * request.post('/user')
|
|
|
- * .type('form')
|
|
|
- * .send('name=tj')
|
|
|
- * .end(callback)
|
|
|
- *
|
|
|
- * // auto x-www-form-urlencoded
|
|
|
- * request.post('/user')
|
|
|
- * .type('form')
|
|
|
- * .send({ name: 'tj' })
|
|
|
- * .end(callback)
|
|
|
+ * Reduce `arr` with `fn`.
|
|
|
*
|
|
|
- * // defaults to x-www-form-urlencoded
|
|
|
- * request.post('/user')
|
|
|
- * .send('name=tobi')
|
|
|
- * .send('species=ferret')
|
|
|
- * .end(callback)
|
|
|
+ * @param {Array} arr
|
|
|
+ * @param {Function} fn
|
|
|
+ * @param {Mixed} initial
|
|
|
*
|
|
|
- * @param {String|Object} data
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
+ * TODO: combatible error handling?
|
|
|
*/
|
|
|
|
|
|
-Request.prototype.send = function(data){
|
|
|
- var obj = isObject(data);
|
|
|
- var type = this.getHeader('Content-Type');
|
|
|
+module.exports = function(arr, fn, initial){
|
|
|
+ var idx = 0;
|
|
|
+ var len = arr.length;
|
|
|
+ var curr = arguments.length == 3
|
|
|
+ ? initial
|
|
|
+ : arr[idx++];
|
|
|
+
|
|
|
+ while (idx < len) {
|
|
|
+ curr = fn.call(null, curr, arr[idx], ++idx, arr);
|
|
|
+ }
|
|
|
+
|
|
|
+ return curr;
|
|
|
+};
|
|
|
+},{}],4:[function(require,module,exports){
|
|
|
+'use strict';
|
|
|
+
|
|
|
+Object.defineProperty(exports, '__esModule', {
|
|
|
+ value: true
|
|
|
+});
|
|
|
+
|
|
|
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
+
|
|
|
+function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
|
|
|
+
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
+
|
|
|
+function promiseWaterfall(_ref) {
|
|
|
+ var _ref2 = _toArray(_ref);
|
|
|
+
|
|
|
+ var resolvedPromise = _ref2[0];
|
|
|
+
|
|
|
+ var tasks = _ref2.slice(1);
|
|
|
+
|
|
|
+ var finalTaskPromise = tasks.reduce(function (prevTaskPromise, task) {
|
|
|
+ return prevTaskPromise.then(task);
|
|
|
+ }, resolvedPromise(1)); // initial value
|
|
|
+
|
|
|
+ return finalTaskPromise;
|
|
|
+}
|
|
|
+
|
|
|
+var _default = (function () {
|
|
|
+ function _default(opts) {
|
|
|
+ _classCallCheck(this, _default);
|
|
|
+
|
|
|
+ // Dictates in what order different plugin types are ran:
|
|
|
+ this.types = ['presetter', 'selecter', 'uploader'];
|
|
|
+
|
|
|
+ // Container for different types of plugins
|
|
|
+ this.plugins = {};
|
|
|
+ }
|
|
|
+
|
|
|
+ _createClass(_default, [{
|
|
|
+ key: 'use',
|
|
|
+ value: function use(Plugin, opts) {
|
|
|
+ // Instantiate
|
|
|
+ var plugin = new Plugin(this, opts);
|
|
|
+ this.plugins[plugin.type] = this.plugins[plugin.type] || [];
|
|
|
+ this.plugins[plugin.type].push(plugin);
|
|
|
+
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'setProgress',
|
|
|
+ value: function setProgress(plugin, percentage) {
|
|
|
+ // Any plugin can call this via `this.core.setProgress(this, precentage)`
|
|
|
+ console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Runs all plugins of the same type in parallel
|
|
|
+ }, {
|
|
|
+ key: 'runType',
|
|
|
+ value: function runType(type, files) {
|
|
|
+ console.dir({
|
|
|
+ method: 'Transloadit.runType',
|
|
|
+ type: type,
|
|
|
+ files: files
|
|
|
+ // cb : cb
|
|
|
+ });
|
|
|
+
|
|
|
+ var methods = [];
|
|
|
+ for (var p in this.plugins[type]) {
|
|
|
+ var plugin = this.plugins[type][p];
|
|
|
+ methods.push(plugin.run.call(plugin, files));
|
|
|
+ }
|
|
|
+
|
|
|
+ return Promise.all(methods);
|
|
|
+
|
|
|
+ // const methods = this.plugins[type].map(plugin => plugin.run.bind(plugin, files));
|
|
|
+
|
|
|
+ // async.parallel(methods, cb);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Runs a waterfall of runType plugin packs, like so:
|
|
|
+ // All preseters(data) --> All selecters(data) --> All uploaders(data) --> done
|
|
|
+ }, {
|
|
|
+ key: 'run',
|
|
|
+ value: function run() {
|
|
|
+ var _this = this;
|
|
|
+
|
|
|
+ console.dir({
|
|
|
+ method: 'Transloadit.run'
|
|
|
+ });
|
|
|
+
|
|
|
+ var typeMethods = [];
|
|
|
+ // typeMethods.push(async.constant([]));
|
|
|
+
|
|
|
+ // for (let t in this.types) {
|
|
|
+ // const type = this.types[t];
|
|
|
+ // typeMethods.push(this.runType.bind(this, type));
|
|
|
+ // }
|
|
|
+
|
|
|
+ this.types.forEach(function (type) {
|
|
|
+ if (_this.plugins[type]) {
|
|
|
+ typeMethods.push(_this.runType.bind(_this, type));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ promiseWaterfall(typeMethods).then(function (result) {
|
|
|
+ return console.log(result);
|
|
|
+ })['catch'](function (error) {
|
|
|
+ return console.error(error);
|
|
|
+ });
|
|
|
+
|
|
|
+ // async.waterfall(typeMethods, function (err, finalFiles) {
|
|
|
+ // console.dir({
|
|
|
+ // err : err ,
|
|
|
+ // finalFiles: finalFiles
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+
|
|
|
+ return _default;
|
|
|
+})();
|
|
|
+
|
|
|
+exports['default'] = _default;
|
|
|
+module.exports = exports['default'];
|
|
|
+
|
|
|
+},{}],5:[function(require,module,exports){
|
|
|
+// This is how we roll $('.element').toggleClass in non-jQuery world
|
|
|
+'use strict';
|
|
|
+
|
|
|
+Object.defineProperty(exports, '__esModule', {
|
|
|
+ value: true
|
|
|
+});
|
|
|
+function toggleClass(el, className) {
|
|
|
+ if (el.classList) {
|
|
|
+ el.classList.toggle(className);
|
|
|
+ } else {
|
|
|
+ var classes = el.className.split(' ');
|
|
|
+ var existingIndex = classes.indexOf(className);
|
|
|
|
|
|
- // merge
|
|
|
- if (obj && isObject(this._data)) {
|
|
|
- for (var key in data) {
|
|
|
- this._data[key] = data[key];
|
|
|
- }
|
|
|
- } else if ('string' == typeof data) {
|
|
|
- if (!type) this.type('form');
|
|
|
- type = this.getHeader('Content-Type');
|
|
|
- if ('application/x-www-form-urlencoded' == type) {
|
|
|
- this._data = this._data
|
|
|
- ? this._data + '&' + data
|
|
|
- : data;
|
|
|
+ if (existingIndex >= 0) {
|
|
|
+ classes.splice(existingIndex, 1);
|
|
|
} else {
|
|
|
- this._data = (this._data || '') + data;
|
|
|
+ classes.push(className);
|
|
|
+ el.className = classes.join(' ');
|
|
|
}
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function addClass(el, className) {
|
|
|
+ if (el.classList) {
|
|
|
+ el.classList.add(className);
|
|
|
} else {
|
|
|
- this._data = data;
|
|
|
+ el.className += ' ' + className;
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- if (!obj || isHost(data)) return this;
|
|
|
- if (!type) this.type('json');
|
|
|
- return this;
|
|
|
-};
|
|
|
+function removeClass(el, className) {
|
|
|
+ if (el.classList) {
|
|
|
+ el.classList.remove(className);
|
|
|
+ } else {
|
|
|
+ el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-/**
|
|
|
- * Invoke the callback with `err` and `res`
|
|
|
- * and handle arity check.
|
|
|
- *
|
|
|
- * @param {Error} err
|
|
|
- * @param {Response} res
|
|
|
- * @api private
|
|
|
- */
|
|
|
+// $form.on('drag dragstart dragend dragover dragenter dragleave drop');
|
|
|
+function addListenerMulti(el, events, func) {
|
|
|
+ var eventsArray = events.split(' ');
|
|
|
+ for (var _event in eventsArray) {
|
|
|
+ el.addEventListener(eventsArray[_event], func, false);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-Request.prototype.callback = function(err, res){
|
|
|
- var fn = this._callback;
|
|
|
- this.clearTimeout();
|
|
|
- fn(err, res);
|
|
|
+exports['default'] = {
|
|
|
+ toggleClass: toggleClass,
|
|
|
+ addClass: addClass,
|
|
|
+ removeClass: removeClass,
|
|
|
+ addListenerMulti: addListenerMulti
|
|
|
};
|
|
|
+module.exports = exports['default'];
|
|
|
|
|
|
-/**
|
|
|
- * Invoke callback with x-domain error.
|
|
|
- *
|
|
|
- * @api private
|
|
|
- */
|
|
|
+},{}],6:[function(require,module,exports){
|
|
|
+'use strict';
|
|
|
|
|
|
-Request.prototype.crossDomainError = function(){
|
|
|
- var err = new Error('Origin is not allowed by Access-Control-Allow-Origin');
|
|
|
- err.crossDomain = true;
|
|
|
- this.callback(err);
|
|
|
-};
|
|
|
+Object.defineProperty(exports, '__esModule', {
|
|
|
+ value: true
|
|
|
+});
|
|
|
|
|
|
-/**
|
|
|
- * Invoke callback with timeout error.
|
|
|
- *
|
|
|
- * @api private
|
|
|
- */
|
|
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
-Request.prototype.timeoutError = function(){
|
|
|
- var timeout = this._timeout;
|
|
|
- var err = new Error('timeout of ' + timeout + 'ms exceeded');
|
|
|
- err.timeout = timeout;
|
|
|
- this.callback(err);
|
|
|
-};
|
|
|
+var _Transloadit = require('./Transloadit');
|
|
|
|
|
|
-/**
|
|
|
- * Enable transmission of cookies with x-domain requests.
|
|
|
- *
|
|
|
- * Note that for this to work the origin must not be
|
|
|
- * using "Access-Control-Allow-Origin" with a wildcard,
|
|
|
- * and also must set "Access-Control-Allow-Credentials"
|
|
|
- * to "true".
|
|
|
- *
|
|
|
- * @api public
|
|
|
- */
|
|
|
+var _Transloadit2 = _interopRequireDefault(_Transloadit);
|
|
|
|
|
|
-Request.prototype.withCredentials = function(){
|
|
|
- this._withCredentials = true;
|
|
|
- return this;
|
|
|
-};
|
|
|
+exports['default'] = _Transloadit2['default'];
|
|
|
+module.exports = exports['default'];
|
|
|
|
|
|
-/**
|
|
|
- * Initiate request, invoking callback `fn(res)`
|
|
|
- * with an instanceof `Response`.
|
|
|
- *
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request} for chaining
|
|
|
- * @api public
|
|
|
- */
|
|
|
+},{"./Transloadit":4}],7:[function(require,module,exports){
|
|
|
+'use strict';
|
|
|
|
|
|
-Request.prototype.end = function(fn){
|
|
|
- var self = this;
|
|
|
- var xhr = this.xhr = request.getXHR();
|
|
|
- var query = this._query.join('&');
|
|
|
- var timeout = this._timeout;
|
|
|
- var data = this._formData || this._data;
|
|
|
+Object.defineProperty(exports, '__esModule', {
|
|
|
+ value: true
|
|
|
+});
|
|
|
|
|
|
- // store callback
|
|
|
- this._callback = fn || noop;
|
|
|
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
|
|
|
- // state change
|
|
|
- xhr.onreadystatechange = function(){
|
|
|
- if (4 != xhr.readyState) return;
|
|
|
+var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
|
|
|
- // In IE9, reads to any property (e.g. status) off of an aborted XHR will
|
|
|
- // result in the error "Could not complete the operation due to error c00c023f"
|
|
|
- var status;
|
|
|
- try { status = xhr.status } catch(e) { status = 0; }
|
|
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
- if (0 == status) {
|
|
|
- if (self.timedout) return self.timeoutError();
|
|
|
- if (self.aborted) return;
|
|
|
- return self.crossDomainError();
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
+
|
|
|
+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 _coreUtils = require('../core/Utils');
|
|
|
+
|
|
|
+var _coreUtils2 = _interopRequireDefault(_coreUtils);
|
|
|
+
|
|
|
+var _TransloaditPlugin2 = require('./TransloaditPlugin');
|
|
|
+
|
|
|
+var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
|
|
|
+
|
|
|
+// import Tus from 'tus-js-client';
|
|
|
+// console.log('pizza', Tus);
|
|
|
+
|
|
|
+var DragDrop = (function (_TransloaditPlugin) {
|
|
|
+ _inherits(DragDrop, _TransloaditPlugin);
|
|
|
+
|
|
|
+ function DragDrop(core, opts) {
|
|
|
+ _classCallCheck(this, DragDrop);
|
|
|
+
|
|
|
+ _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts);
|
|
|
+ this.type = 'selecter';
|
|
|
+
|
|
|
+ // set default options
|
|
|
+ var defaultOptions = {
|
|
|
+ bla: 'blabla',
|
|
|
+ autoSubmit: true,
|
|
|
+ modal: true
|
|
|
+ };
|
|
|
+
|
|
|
+ // merge default options with the ones set by user
|
|
|
+ this.opts = defaultOptions;
|
|
|
+ Object.assign(this.opts, opts);
|
|
|
+
|
|
|
+ console.log(this.opts);
|
|
|
+
|
|
|
+ // get the element where Drag & Drop event will occur
|
|
|
+ this.dropzone = document.querySelectorAll(this.opts.selector)[0];
|
|
|
+ this.dropzoneInput = document.querySelectorAll('.UppyDragDrop-input')[0];
|
|
|
+
|
|
|
+ this.status = document.querySelectorAll('.UppyDragDrop-status')[0];
|
|
|
+
|
|
|
+ this.isDragDropSupported = this.checkDragDropSupport();
|
|
|
+
|
|
|
+ // crazy stuff so that ‘this’ will behave in class
|
|
|
+ this.listenForEvents = this.listenForEvents.bind(this);
|
|
|
+ this.handleDrop = this.handleDrop.bind(this);
|
|
|
+ this.checkDragDropSupport = this.checkDragDropSupport.bind(this);
|
|
|
+ this.upload = this.upload.bind(this);
|
|
|
+ this.handleInputChange = this.handleInputChange.bind(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Checks if the browser supports Drag & Drop
|
|
|
+ */
|
|
|
+
|
|
|
+ _createClass(DragDrop, [{
|
|
|
+ key: 'checkDragDropSupport',
|
|
|
+ value: function checkDragDropSupport() {
|
|
|
+ var div = document.createElement('div');
|
|
|
+ return ('draggable' in div || 'ondragstart' in div && 'ondrop' in div) && 'FormData' in window && 'FileReader' in window;
|
|
|
}
|
|
|
- self.emit('end');
|
|
|
- };
|
|
|
+ }, {
|
|
|
+ key: 'listenForEvents',
|
|
|
+ value: function listenForEvents() {
|
|
|
+ var _this = this;
|
|
|
|
|
|
- // progress
|
|
|
- var handleProgress = function(e){
|
|
|
- if (e.total > 0) {
|
|
|
- e.percent = e.loaded / e.total * 100;
|
|
|
+ if (this.isDragDropSupported) {
|
|
|
+ _coreUtils2['default'].addClass(this.dropzone, 'is-dragdrop-supported');
|
|
|
+ }
|
|
|
+
|
|
|
+ // prevent default actions for all drag & drop events
|
|
|
+ _coreUtils2['default'].addListenerMulti(this.dropzone, 'drag dragstart dragend dragover dragenter dragleave drop', function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ e.stopPropagation();
|
|
|
+ });
|
|
|
+
|
|
|
+ // Toggle is-dragover state when files are dragged over or dropped
|
|
|
+ _coreUtils2['default'].addListenerMulti(this.dropzone, 'dragover dragenter', function () {
|
|
|
+ _coreUtils2['default'].addClass(_this.dropzone, 'is-dragover');
|
|
|
+ });
|
|
|
+
|
|
|
+ _coreUtils2['default'].addListenerMulti(this.dropzone, 'dragleave dragend drop', function () {
|
|
|
+ _coreUtils2['default'].removeClass(_this.dropzone, 'is-dragover');
|
|
|
+ });
|
|
|
+
|
|
|
+ this.dropzone.addEventListener('drop', this.handleDrop);
|
|
|
+
|
|
|
+ this.dropzoneInput.addEventListener('change', this.handleInputChange);
|
|
|
+
|
|
|
+ console.log('waiting for some files to be dropped on ' + this.opts.selector);
|
|
|
}
|
|
|
- self.emit('progress', e);
|
|
|
- };
|
|
|
- if (this.hasListeners('progress')) {
|
|
|
- xhr.onprogress = handleProgress;
|
|
|
- }
|
|
|
- try {
|
|
|
- if (xhr.upload && this.hasListeners('progress')) {
|
|
|
- xhr.upload.onprogress = handleProgress;
|
|
|
+
|
|
|
+ // Toggle is-dragover state when files are dragged over or dropped
|
|
|
+ // in this case — add/remove 'is-dragover' class
|
|
|
+ // toggleDragoverState(e) {
|
|
|
+ // toggleClass(this.dropzone, 'is-dragover');
|
|
|
+ // }
|
|
|
+
|
|
|
+ }, {
|
|
|
+ key: 'displayStatus',
|
|
|
+ value: function displayStatus(status) {
|
|
|
+ this.status.innerHTML = status;
|
|
|
}
|
|
|
- } catch(e) {
|
|
|
- // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist.
|
|
|
- // Reported here:
|
|
|
- // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context
|
|
|
- }
|
|
|
+ }, {
|
|
|
+ key: 'handleDrop',
|
|
|
+ value: function handleDrop(e) {
|
|
|
+ console.log('all right, someone dropped something here...');
|
|
|
+ var files = e.dataTransfer.files;
|
|
|
+ var formData = new FormData(this.dropzone);
|
|
|
+ // console.log('pizza', formData);
|
|
|
+
|
|
|
+ for (var i = 0; i < files.length; i++) {
|
|
|
+ formData.append('file', files[i]);
|
|
|
+ console.log('pizza', files[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.upload(formData);
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'handleInputChange',
|
|
|
+ value: function handleInputChange() {
|
|
|
+ // const fileInput = document.querySelectorAll('.UppyDragDrop-input')[0];
|
|
|
+ var formData = new FormData(this.dropzone);
|
|
|
+ console.log('pizza', formData);
|
|
|
+
|
|
|
+ this.upload(formData);
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'upload',
|
|
|
+ value: function upload(data) {
|
|
|
+ var _this2 = this;
|
|
|
+
|
|
|
+ this.displayStatus('Uploading...');
|
|
|
+
|
|
|
+ var request = new XMLHttpRequest();
|
|
|
+ request.open('POST', 'http://api2.transloadit.com', true);
|
|
|
+ request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
|
|
+
|
|
|
+ request.addEventListener('load', function () {
|
|
|
+ console.log('fucking done!');
|
|
|
+ _this2.displayStatus('Done.');
|
|
|
+ });
|
|
|
+
|
|
|
+ request.addEventListener('load', function () {
|
|
|
+ _this2.displayStatus('Done.');
|
|
|
+ });
|
|
|
+
|
|
|
+ request.addEventListener('error', function () {
|
|
|
+ console.log('fucking error!');
|
|
|
+ });
|
|
|
+
|
|
|
+ request.send(data);
|
|
|
+
|
|
|
+ // Create a new tus upload
|
|
|
+ // const upload = new Tus.Upload(data, {
|
|
|
+ // endpoint: 'http://master.tus.io:8080',
|
|
|
+ // onError: function(error) {
|
|
|
+ // console.log('Failed because: ' + error);
|
|
|
+ // },
|
|
|
+ // onProgress: function(bytesUploaded, bytesTotal) {
|
|
|
+ // var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
|
|
|
+ // console.log(bytesUploaded, bytesTotal, percentage + '%');
|
|
|
+ // },
|
|
|
+ // onSuccess: function() {
|
|
|
+ // console.log('Download %s from %s', upload.file.name, upload.url);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ //
|
|
|
+ // // Start the upload
|
|
|
+ // upload.start();
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'run',
|
|
|
+ value: function run(files) {
|
|
|
+ console.dir({
|
|
|
+ method: 'DragDrop.run',
|
|
|
+ files: files
|
|
|
+ // done : done
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log('DragDrop running!');
|
|
|
+ // console.log(files);
|
|
|
+ this.listenForEvents();
|
|
|
+ this.core.setProgress(this, 0);
|
|
|
+ var selected = [{ name: 'lolcat.jpeg' }];
|
|
|
+ this.core.setProgress(this, 100);
|
|
|
+ // return selected;
|
|
|
+ // done(null, 'done with DragDrop');
|
|
|
+ return Promise.resolve(files);
|
|
|
+ }
|
|
|
+ }]);
|
|
|
+
|
|
|
+ return DragDrop;
|
|
|
+})(_TransloaditPlugin3['default']);
|
|
|
+
|
|
|
+exports['default'] = DragDrop;
|
|
|
+module.exports = exports['default'];
|
|
|
+
|
|
|
+},{"../core/Utils":5,"./TransloaditPlugin":10}],8:[function(require,module,exports){
|
|
|
+'use strict';
|
|
|
+
|
|
|
+Object.defineProperty(exports, '__esModule', {
|
|
|
+ value: true
|
|
|
+});
|
|
|
+
|
|
|
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
+
|
|
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
+
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
+
|
|
|
+var _superagent = require('superagent');
|
|
|
|
|
|
- // timeout
|
|
|
- if (timeout && !this._timer) {
|
|
|
- this._timer = setTimeout(function(){
|
|
|
- self.timedout = true;
|
|
|
- self.abort();
|
|
|
- }, timeout);
|
|
|
- }
|
|
|
+var _superagent2 = _interopRequireDefault(_superagent);
|
|
|
|
|
|
- // querystring
|
|
|
- if (query) {
|
|
|
- query = request.serializeObject(query);
|
|
|
- this.url += ~this.url.indexOf('?')
|
|
|
- ? '&' + query
|
|
|
- : '?' + query;
|
|
|
+var DropboxPlugin = (function () {
|
|
|
+ function DropboxPlugin() {
|
|
|
+ _classCallCheck(this, DropboxPlugin);
|
|
|
+
|
|
|
+ this.authenticate = this.authenticate.bind(this);
|
|
|
+ this.connect = this.connect.bind(this);
|
|
|
+ this.render = this.render.bind(this);
|
|
|
+ this.files = [];
|
|
|
+ this.currentDir = '/';
|
|
|
}
|
|
|
|
|
|
- // initiate request
|
|
|
- xhr.open(this.method, this.url, true);
|
|
|
+ _createClass(DropboxPlugin, [{
|
|
|
+ key: 'connect',
|
|
|
+ value: function connect(target) {
|
|
|
+ this._target = document.getElementById(target);
|
|
|
|
|
|
- // CORS
|
|
|
- if (this._withCredentials) xhr.withCredentials = true;
|
|
|
+ this.client = new Dropbox.Client({ key: 'b7dzc9ei5dv5hcv', token: '' });
|
|
|
+ this.client.authDriver(new Dropbox.AuthDriver.Redirect());
|
|
|
+ this.authenticate();
|
|
|
|
|
|
- // body
|
|
|
- if ('GET' != this.method && 'HEAD' != this.method && 'string' != typeof data && !isHost(data)) {
|
|
|
- // serialize stuff
|
|
|
- var contentType = this.getHeader('Content-Type');
|
|
|
- var serialize = request.serialize[contentType ? contentType.split(';')[0] : ''];
|
|
|
- if (serialize) data = serialize(data);
|
|
|
- }
|
|
|
+ if (this.client.credentials().token) {
|
|
|
+ this.getDirectory();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'authenticate',
|
|
|
+ value: function authenticate() {
|
|
|
+ this.client.authenticate();
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'addFile',
|
|
|
+ value: function addFile() {}
|
|
|
+ }, {
|
|
|
+ key: 'getDirectory',
|
|
|
+ value: function getDirectory() {
|
|
|
+ var _this = this;
|
|
|
|
|
|
- // set header fields
|
|
|
- for (var field in this.header) {
|
|
|
- if (null == this.header[field]) continue;
|
|
|
- xhr.setRequestHeader(field, this.header[field]);
|
|
|
- }
|
|
|
+ _superagent2['default'].get('https://api18.dropbox.com/1/metadata/auto').query({
|
|
|
+ client_id: 'b7dzc9ei5dv5hcv',
|
|
|
+ token: this.client.credentials().token
|
|
|
+ }).set('Content-Type', 'application/json').end(function (err, res) {
|
|
|
+ console.log(res);
|
|
|
+ });
|
|
|
|
|
|
- // send stuff
|
|
|
- this.emit('request', this);
|
|
|
- xhr.send(data);
|
|
|
- return this;
|
|
|
-};
|
|
|
+ return this.client.readdir(this.currentDir, function (error, entries, stat, statFiles) {
|
|
|
+ if (error) {
|
|
|
+ return showError(error); // Something went wrong.
|
|
|
+ }
|
|
|
+ return _this.render(statFiles);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, {
|
|
|
+ key: 'run',
|
|
|
+ value: function run() {}
|
|
|
+ }, {
|
|
|
+ key: 'render',
|
|
|
+ value: function render(files) {
|
|
|
+ var _this2 = this;
|
|
|
|
|
|
-/**
|
|
|
- * Faux promise support
|
|
|
- *
|
|
|
- * @param {Function} fulfill
|
|
|
- * @param {Function} reject
|
|
|
- * @return {Request}
|
|
|
- */
|
|
|
+ // for each file in the directory, create a list item element
|
|
|
+ var elems = files.map(function (file, i) {
|
|
|
+ var icon = file.isFolder ? 'folder' : 'file';
|
|
|
+ return '<li data-type="' + icon + '" data-name="' + file.name + '"><span>' + icon + ' : </span><span> ' + file.name + '</span></li>';
|
|
|
+ });
|
|
|
|
|
|
-Request.prototype.then = function (fulfill, reject) {
|
|
|
- return this.end(function(err, res) {
|
|
|
- err ? reject(err) : fulfill(res);
|
|
|
- });
|
|
|
-}
|
|
|
+ // appends the list items to the target
|
|
|
+ this._target.innerHTML = elems.sort().join('');
|
|
|
|
|
|
-/**
|
|
|
- * Expose `Request`.
|
|
|
- */
|
|
|
+ if (this.currentDir.length > 1) {
|
|
|
+ var _parent = document.createElement('LI');
|
|
|
+ _parent.setAttribute('data-type', 'parent');
|
|
|
+ _parent.innerHTML = '<span>...</span>';
|
|
|
+ this._target.appendChild(_parent);
|
|
|
+ }
|
|
|
|
|
|
-request.Request = Request;
|
|
|
+ // add an onClick to each list item
|
|
|
+ var fileElems = this._target.querySelectorAll('li');
|
|
|
|
|
|
-/**
|
|
|
- * Issue a request:
|
|
|
- *
|
|
|
- * Examples:
|
|
|
- *
|
|
|
- * request('GET', '/users').end(callback)
|
|
|
- * request('/users').end(callback)
|
|
|
- * request('/users', callback)
|
|
|
- *
|
|
|
- * @param {String} method
|
|
|
- * @param {String|Function} url or callback
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+ Array.prototype.forEach.call(fileElems, function (element) {
|
|
|
+ var type = element.getAttribute('data-type');
|
|
|
|
|
|
-function request(method, url) {
|
|
|
- // callback
|
|
|
- if ('function' == typeof url) {
|
|
|
- return new Request('GET', method).end(url);
|
|
|
- }
|
|
|
+ if (type === 'file') {
|
|
|
+ element.addEventListener('click', function () {
|
|
|
+ _this2.files.push(element.getAttribute('data-name'));
|
|
|
+ console.dir('files: ' + _this2.files);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ element.addEventListener('dblclick', function () {
|
|
|
+ var length = _this2.currentDir.split('/').length;
|
|
|
|
|
|
- // url first
|
|
|
- if (1 == arguments.length) {
|
|
|
- return new Request('GET', method);
|
|
|
- }
|
|
|
+ if (type === 'folder') {
|
|
|
+ _this2.currentDir = '' + _this2.currentDir + element.getAttribute('data-name') + '/';
|
|
|
+ } else if (type === 'parent') {
|
|
|
+ _this2.currentDir = _this2.currentDir.split('/').slice(0, length - 2).join('/') + '/';
|
|
|
+ }
|
|
|
+ console.log(_this2.currentDir);
|
|
|
+ _this2.getDirectory();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }]);
|
|
|
|
|
|
- return new Request(method, url);
|
|
|
-}
|
|
|
+ return DropboxPlugin;
|
|
|
+})();
|
|
|
|
|
|
-/**
|
|
|
- * GET `url` with optional callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed|Function} data or fn
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+exports['default'] = new DropboxPlugin();
|
|
|
+module.exports = exports['default'];
|
|
|
|
|
|
-request.get = function(url, data, fn){
|
|
|
- var req = request('GET', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.query(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
+},{"superagent":1}],9:[function(require,module,exports){
|
|
|
+'use strict';
|
|
|
|
|
|
-/**
|
|
|
- * HEAD `url` with optional callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed|Function} data or fn
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
|
|
|
-request.head = function(url, data, fn){
|
|
|
- var req = request('HEAD', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.send(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
-/**
|
|
|
- * DELETE `url` with optional callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
|
|
|
-request.del = function(url, fn){
|
|
|
- var req = request('DELETE', url);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
+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; }
|
|
|
|
|
|
-/**
|
|
|
- * PATCH `url` with optional `data` and callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed} data
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+var _TransloaditPlugin2 = require('./TransloaditPlugin');
|
|
|
|
|
|
-request.patch = function(url, data, fn){
|
|
|
- var req = request('PATCH', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.send(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
+var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
|
|
|
|
|
|
-/**
|
|
|
- * POST `url` with optional `data` and callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed} data
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+var TransloaditBasic = (function (_TransloaditPlugin) {
|
|
|
+ _inherits(TransloaditBasic, _TransloaditPlugin);
|
|
|
|
|
|
-request.post = function(url, data, fn){
|
|
|
- var req = request('POST', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.send(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
+ function TransloaditBasic(core, opts) {
|
|
|
+ _classCallCheck(this, TransloaditBasic);
|
|
|
+
|
|
|
+ _get(Object.getPrototypeOf(TransloaditBasic.prototype), 'constructor', this).call(this, core, opts);
|
|
|
+ this.type = 'presetter';
|
|
|
+ this.core.use(DragDrop, { modal: true, wait: true }).use(Tus10, { endpoint: 'http://master.tus.io:8080' });
|
|
|
+ }
|
|
|
+
|
|
|
+ return TransloaditBasic;
|
|
|
+})(_TransloaditPlugin3['default']);
|
|
|
+
|
|
|
+},{"./TransloaditPlugin":10}],10:[function(require,module,exports){
|
|
|
+"use strict";
|
|
|
|
|
|
-/**
|
|
|
- * PUT `url` with optional `data` and callback `fn(res)`.
|
|
|
- *
|
|
|
- * @param {String} url
|
|
|
- * @param {Mixed|Function} data or fn
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Request}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+Object.defineProperty(exports, "__esModule", {
|
|
|
+ value: true
|
|
|
+});
|
|
|
|
|
|
-request.put = function(url, data, fn){
|
|
|
- var req = request('PUT', url);
|
|
|
- if ('function' == typeof data) fn = data, data = null;
|
|
|
- if (data) req.send(data);
|
|
|
- if (fn) req.end(fn);
|
|
|
- return req;
|
|
|
-};
|
|
|
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
|
|
|
-/**
|
|
|
- * Expose `request`.
|
|
|
- */
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
|
|
|
-module.exports = request;
|
|
|
+var TransloaditPlugin = (function () {
|
|
|
+ // This contains boilerplate that all TransloaditPlugins share - and should not be used
|
|
|
+ // directly. It also shows which methods final plugins should implement/override,
|
|
|
+ // this deciding on structure.
|
|
|
|
|
|
-},{"emitter":12,"reduce":13}],12:[function(require,module,exports){
|
|
|
+ function TransloaditPlugin(core, opts) {
|
|
|
+ _classCallCheck(this, TransloaditPlugin);
|
|
|
|
|
|
-/**
|
|
|
- * Expose `Emitter`.
|
|
|
- */
|
|
|
+ this.core = core;
|
|
|
+ this.opts = opts;
|
|
|
+ this.name = this.constructor.name;
|
|
|
+ }
|
|
|
|
|
|
-module.exports = Emitter;
|
|
|
+ _createClass(TransloaditPlugin, [{
|
|
|
+ key: "run",
|
|
|
+ value: function run(files) {
|
|
|
+ return files;
|
|
|
+ }
|
|
|
+ }]);
|
|
|
|
|
|
-/**
|
|
|
- * Initialize a new `Emitter`.
|
|
|
- *
|
|
|
- * @api public
|
|
|
- */
|
|
|
+ return TransloaditPlugin;
|
|
|
+})();
|
|
|
|
|
|
-function Emitter(obj) {
|
|
|
- if (obj) return mixin(obj);
|
|
|
-};
|
|
|
+exports["default"] = TransloaditPlugin;
|
|
|
+module.exports = exports["default"];
|
|
|
|
|
|
-/**
|
|
|
- * Mixin the emitter properties.
|
|
|
- *
|
|
|
- * @param {Object} obj
|
|
|
- * @return {Object}
|
|
|
- * @api private
|
|
|
- */
|
|
|
+},{}],11:[function(require,module,exports){
|
|
|
+'use strict';
|
|
|
|
|
|
-function mixin(obj) {
|
|
|
- for (var key in Emitter.prototype) {
|
|
|
- obj[key] = Emitter.prototype[key];
|
|
|
- }
|
|
|
- return obj;
|
|
|
-}
|
|
|
+Object.defineProperty(exports, '__esModule', {
|
|
|
+ value: true
|
|
|
+});
|
|
|
|
|
|
-/**
|
|
|
- * Listen on the given `event` with `fn`.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Emitter}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
|
|
|
|
|
-Emitter.prototype.on =
|
|
|
-Emitter.prototype.addEventListener = function(event, fn){
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
- (this._callbacks[event] = this._callbacks[event] || [])
|
|
|
- .push(fn);
|
|
|
- return this;
|
|
|
-};
|
|
|
+var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
|
|
|
|
|
-/**
|
|
|
- * Adds an `event` listener that will be invoked a single
|
|
|
- * time then automatically removed.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Emitter}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
-Emitter.prototype.once = function(event, fn){
|
|
|
- var self = this;
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
|
|
|
|
|
- function on() {
|
|
|
- self.off(event, on);
|
|
|
- fn.apply(this, arguments);
|
|
|
- }
|
|
|
+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; }
|
|
|
|
|
|
- on.fn = fn;
|
|
|
- this.on(event, on);
|
|
|
- return this;
|
|
|
-};
|
|
|
+var _TransloaditPlugin2 = require('./TransloaditPlugin');
|
|
|
|
|
|
-/**
|
|
|
- * Remove the given callback for `event` or all
|
|
|
- * registered callbacks.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @param {Function} fn
|
|
|
- * @return {Emitter}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
|
|
|
|
|
|
-Emitter.prototype.off =
|
|
|
-Emitter.prototype.removeListener =
|
|
|
-Emitter.prototype.removeAllListeners =
|
|
|
-Emitter.prototype.removeEventListener = function(event, fn){
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
+var Tus10 = (function (_TransloaditPlugin) {
|
|
|
+ _inherits(Tus10, _TransloaditPlugin);
|
|
|
|
|
|
- // all
|
|
|
- if (0 == arguments.length) {
|
|
|
- this._callbacks = {};
|
|
|
- return this;
|
|
|
+ function Tus10(core, opts) {
|
|
|
+ _classCallCheck(this, Tus10);
|
|
|
+
|
|
|
+ _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts);
|
|
|
+ this.type = 'uploader';
|
|
|
}
|
|
|
|
|
|
- // specific event
|
|
|
- var callbacks = this._callbacks[event];
|
|
|
- if (!callbacks) return this;
|
|
|
+ _createClass(Tus10, [{
|
|
|
+ key: 'run',
|
|
|
+ value: function run(files) {
|
|
|
+ // console.log(files);
|
|
|
+ this.core.setProgress(this, 0);
|
|
|
+ var uploaded = [];
|
|
|
+ // for (var i in files) {
|
|
|
+ // var file = files[i];
|
|
|
+ // this.core.setProgress(this, (i * 1) + 1);
|
|
|
+ // uploaded[i] = file;
|
|
|
+ // uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name;
|
|
|
+ // }
|
|
|
+ this.core.setProgress(this, 100);
|
|
|
|
|
|
- // remove all handlers
|
|
|
- if (1 == arguments.length) {
|
|
|
- delete this._callbacks[event];
|
|
|
- return this;
|
|
|
- }
|
|
|
+ // done(null, 'done with Tus');
|
|
|
+ return Promise.resolve(files);
|
|
|
|
|
|
- // remove specific handler
|
|
|
- var cb;
|
|
|
- for (var i = 0; i < callbacks.length; i++) {
|
|
|
- cb = callbacks[i];
|
|
|
- if (cb === fn || cb.fn === fn) {
|
|
|
- callbacks.splice(i, 1);
|
|
|
- break;
|
|
|
+ // return uploaded;
|
|
|
}
|
|
|
- }
|
|
|
- return this;
|
|
|
-};
|
|
|
+ }]);
|
|
|
|
|
|
-/**
|
|
|
- * Emit `event` with the given args.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @param {Mixed} ...
|
|
|
- * @return {Emitter}
|
|
|
- */
|
|
|
+ return Tus10;
|
|
|
+})(_TransloaditPlugin3['default']);
|
|
|
|
|
|
-Emitter.prototype.emit = function(event){
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
- var args = [].slice.call(arguments, 1)
|
|
|
- , callbacks = this._callbacks[event];
|
|
|
+exports['default'] = Tus10;
|
|
|
+module.exports = exports['default'];
|
|
|
|
|
|
- if (callbacks) {
|
|
|
- callbacks = callbacks.slice(0);
|
|
|
- for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
|
- callbacks[i].apply(this, args);
|
|
|
- }
|
|
|
- }
|
|
|
+},{"./TransloaditPlugin":10}],12:[function(require,module,exports){
|
|
|
+'use strict';
|
|
|
|
|
|
- return this;
|
|
|
-};
|
|
|
+Object.defineProperty(exports, '__esModule', {
|
|
|
+ value: true
|
|
|
+});
|
|
|
|
|
|
-/**
|
|
|
- * Return array of callbacks for `event`.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @return {Array}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
|
|
|
-Emitter.prototype.listeners = function(event){
|
|
|
- this._callbacks = this._callbacks || {};
|
|
|
- return this._callbacks[event] || [];
|
|
|
-};
|
|
|
+var _TransloaditPlugin = require('./TransloaditPlugin');
|
|
|
|
|
|
-/**
|
|
|
- * Check if this emitter has `event` handlers.
|
|
|
- *
|
|
|
- * @param {String} event
|
|
|
- * @return {Boolean}
|
|
|
- * @api public
|
|
|
- */
|
|
|
+var _TransloaditPlugin2 = _interopRequireDefault(_TransloaditPlugin);
|
|
|
|
|
|
-Emitter.prototype.hasListeners = function(event){
|
|
|
- return !! this.listeners(event).length;
|
|
|
-};
|
|
|
+var _DragDrop = require('./DragDrop');
|
|
|
|
|
|
-},{}],13:[function(require,module,exports){
|
|
|
+var _DragDrop2 = _interopRequireDefault(_DragDrop);
|
|
|
|
|
|
-/**
|
|
|
- * Reduce `arr` with `fn`.
|
|
|
- *
|
|
|
- * @param {Array} arr
|
|
|
- * @param {Function} fn
|
|
|
- * @param {Mixed} initial
|
|
|
- *
|
|
|
- * TODO: combatible error handling?
|
|
|
- */
|
|
|
+var _Dropbox = require('./Dropbox');
|
|
|
|
|
|
-module.exports = function(arr, fn, initial){
|
|
|
- var idx = 0;
|
|
|
- var len = arr.length;
|
|
|
- var curr = arguments.length == 3
|
|
|
- ? initial
|
|
|
- : arr[idx++];
|
|
|
+var _Dropbox2 = _interopRequireDefault(_Dropbox);
|
|
|
|
|
|
- while (idx < len) {
|
|
|
- curr = fn.call(null, curr, arr[idx], ++idx, arr);
|
|
|
- }
|
|
|
-
|
|
|
- return curr;
|
|
|
+var _TransloaditBasic = require('./TransloaditBasic');
|
|
|
+
|
|
|
+var _TransloaditBasic2 = _interopRequireDefault(_TransloaditBasic);
|
|
|
+
|
|
|
+var _Tus10 = require('./Tus10');
|
|
|
+
|
|
|
+var _Tus102 = _interopRequireDefault(_Tus10);
|
|
|
+
|
|
|
+exports['default'] = {
|
|
|
+ TransloaditPlugin: _TransloaditPlugin2['default'],
|
|
|
+ DropboxPlugin: _Dropbox2['default'],
|
|
|
+ DragDrop: _DragDrop2['default'],
|
|
|
+ TransloaditBasic: _TransloaditBasic2['default'],
|
|
|
+ Tus10: _Tus102['default']
|
|
|
};
|
|
|
-},{}],14:[function(require,module,exports){
|
|
|
+module.exports = exports['default'];
|
|
|
+
|
|
|
+},{"./DragDrop":7,"./Dropbox":8,"./TransloaditBasic":9,"./TransloaditPlugin":10,"./Tus10":11}],13:[function(require,module,exports){
|
|
|
'use strict';
|
|
|
|
|
|
-module.exports = require('./lib/plugins');
|
|
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
|
+
|
|
|
+var _srcCore = require('../../../../../../src/core');
|
|
|
+
|
|
|
+var _srcCore2 = _interopRequireDefault(_srcCore);
|
|
|
+
|
|
|
+var _srcPlugins = require('../../../../../../src/plugins');
|
|
|
+
|
|
|
+var uppy = new _srcCore2['default']({ wait: false });
|
|
|
+var files = uppy.use(_srcPlugins.DragDrop, { selector: '#upload-target' }).use(_srcPlugins.Tus10, { endpoint: 'http://master.tus.io:8080' }).run();
|
|
|
|
|
|
-},{"./lib/plugins":10}]},{},[2]);
|
|
|
+},{"../../../../../../src/core":6,"../../../../../../src/plugins":12}]},{},[13]);
|