transloadit-js-client.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. (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){
  2. 'use strict';
  3. Object.defineProperty(exports, '__esModule', {
  4. value: true
  5. });
  6. 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; }; })();
  7. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  8. var Transloadit = (function () {
  9. function Transloadit(opts) {
  10. _classCallCheck(this, Transloadit);
  11. // Dictates in what order different plugin types are ran:
  12. this.types = ['presetter', 'selecter', 'uploader'];
  13. // Container for different types of plugins
  14. this.plugins = {};
  15. }
  16. _createClass(Transloadit, [{
  17. key: 'use',
  18. value: function use(Plugin, opts) {
  19. // Instantiate
  20. var plugin = new Plugin(this, opts);
  21. // Save in plugin container
  22. if (!this.plugins[plugin.type]) {
  23. this.plugins[plugin.type] = [];
  24. }
  25. this.plugins[plugin.type].push(plugin);
  26. return this;
  27. }
  28. }, {
  29. key: 'setProgress',
  30. value: function setProgress(plugin, percentage) {
  31. // Any plugin can call this via `this.core.setProgress(this, precentage)`
  32. console.log(plugin.type + ' plugin ' + plugin.name + ' set the progress to ' + percentage);
  33. return this;
  34. }
  35. }, {
  36. key: 'run',
  37. value: function run() {
  38. // Walk over plugins in the order as defined by this.types.
  39. var files = [];
  40. for (var j in this.types) {
  41. var type = this.types[j];
  42. // Walk over all plugins of this type, passing & modifying the files array as we go
  43. for (var i in this.plugins[type]) {
  44. var plugin = this.plugins[type][i];
  45. console.log('--> Now running ' + plugin.type + ' plugin ' + plugin.name + ': ');
  46. files = plugin.run(files);
  47. console.dir(files);
  48. console.log('');
  49. }
  50. }
  51. // core.run is the final step and retuns the results (vs every other method, returning `this`)
  52. // for chainability
  53. return files;
  54. }
  55. }]);
  56. return Transloadit;
  57. })();
  58. exports['default'] = Transloadit;
  59. module.exports = exports['default'];
  60. },{}],2:[function(require,module,exports){
  61. 'use strict';
  62. Object.defineProperty(exports, '__esModule', {
  63. value: true
  64. });
  65. 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; }; })();
  66. 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); } } };
  67. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  68. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  69. 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; }
  70. var _pluginsTransloaditPlugin = require('../plugins/TransloaditPlugin');
  71. var _pluginsTransloaditPlugin2 = _interopRequireDefault(_pluginsTransloaditPlugin);
  72. var DragDrop = (function (_TransloaditPlugin) {
  73. _inherits(DragDrop, _TransloaditPlugin);
  74. function DragDrop(core, opts) {
  75. _classCallCheck(this, DragDrop);
  76. _get(Object.getPrototypeOf(DragDrop.prototype), 'constructor', this).call(this, core, opts);
  77. this.type = 'selecter';
  78. }
  79. _createClass(DragDrop, [{
  80. key: 'run',
  81. value: function run(files) {
  82. this.core.setProgress(this, 0);
  83. var selected = [{ name: 'lolcat.jpeg' }];
  84. this.core.setProgress(this, 100);
  85. return selected;
  86. }
  87. }]);
  88. return DragDrop;
  89. })(_pluginsTransloaditPlugin2['default']);
  90. exports['default'] = DragDrop;
  91. module.exports = exports['default'];
  92. },{"../plugins/TransloaditPlugin":4}],3:[function(require,module,exports){
  93. 'use strict';
  94. 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); } } };
  95. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  96. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  97. 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; }
  98. var _TransloaditPlugin2 = require('./TransloaditPlugin');
  99. var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
  100. var TransloaditBasic = (function (_TransloaditPlugin) {
  101. _inherits(TransloaditBasic, _TransloaditPlugin);
  102. function TransloaditBasic(core, opts) {
  103. _classCallCheck(this, TransloaditBasic);
  104. _get(Object.getPrototypeOf(TransloaditBasic.prototype), 'constructor', this).call(this, core, opts);
  105. this.type = 'presetter';
  106. this.core.use(DragDrop, { modal: true, wait: true }).use(Tus10, { endpoint: 'http://master.tus.io:8080' });
  107. }
  108. return TransloaditBasic;
  109. })(_TransloaditPlugin3['default']);
  110. },{"./TransloaditPlugin":4}],4:[function(require,module,exports){
  111. "use strict";
  112. Object.defineProperty(exports, "__esModule", {
  113. value: true
  114. });
  115. 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; }; })();
  116. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  117. var TransloaditPlugin = (function () {
  118. // This contains boilerplate that all TransloaditPlugins share - and should not be used
  119. // directly. It also shows which methods final plugins should implement/override,
  120. // this deciding on structure.
  121. function TransloaditPlugin(core, opts) {
  122. _classCallCheck(this, TransloaditPlugin);
  123. this.core = core;
  124. this.opts = opts;
  125. this.name = this.constructor.name;
  126. }
  127. _createClass(TransloaditPlugin, [{
  128. key: "run",
  129. value: function run(files) {
  130. return files;
  131. }
  132. }]);
  133. return TransloaditPlugin;
  134. })();
  135. exports["default"] = TransloaditPlugin;
  136. module.exports = exports["default"];
  137. },{}],5:[function(require,module,exports){
  138. 'use strict';
  139. Object.defineProperty(exports, '__esModule', {
  140. value: true
  141. });
  142. 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; }; })();
  143. 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); } } };
  144. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  145. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  146. 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; }
  147. var _TransloaditPlugin2 = require('./TransloaditPlugin');
  148. var _TransloaditPlugin3 = _interopRequireDefault(_TransloaditPlugin2);
  149. var Tus10 = (function (_TransloaditPlugin) {
  150. _inherits(Tus10, _TransloaditPlugin);
  151. function Tus10(core, opts) {
  152. _classCallCheck(this, Tus10);
  153. _get(Object.getPrototypeOf(Tus10.prototype), 'constructor', this).call(this, core, opts);
  154. this.type = 'uploader';
  155. }
  156. _createClass(Tus10, [{
  157. key: 'run',
  158. value: function run(files) {
  159. this.core.setProgress(this, 0);
  160. var uploaded = [];
  161. for (var i in files) {
  162. var file = files[i];
  163. this.core.setProgress(this, i * 1 + 1);
  164. uploaded[i] = file;
  165. uploaded[i].url = this.opts.endpoint + '/uploaded/' + file.name;
  166. }
  167. this.core.setProgress(this, 100);
  168. return uploaded;
  169. }
  170. }]);
  171. return Tus10;
  172. })(_TransloaditPlugin3['default']);
  173. exports['default'] = Tus10;
  174. module.exports = exports['default'];
  175. },{"./TransloaditPlugin":4}]},{},[1,2,3,4,5]);