@corellium/corellium-cli 1.0.3 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (490) hide show
  1. package/README.md +5 -17
  2. package/docs/OVERVIEW.md +1 -1
  3. package/jenkinsbuild/build.sh +1 -1
  4. package/package.json +3 -3
  5. package/src/TrialAccount.js +76 -0
  6. package/src/commands/Client.js +2 -2
  7. package/src/commands/agent/Agent.js +10 -19
  8. package/src/commands/agent/apps.js +2 -1
  9. package/src/commands/agent/file.js +2 -1
  10. package/src/commands/agent/index.js +1 -0
  11. package/src/commands/agent/ready.js +43 -0
  12. package/src/commands/extensions/delete.js +2 -1
  13. package/src/commands/extensions/list.js +2 -1
  14. package/src/commands/extensions/load.js +2 -1
  15. package/src/commands/extensions/validate.js +2 -1
  16. package/src/commands/firmware/list.js +2 -1
  17. package/src/commands/firmware/load.js +2 -1
  18. package/src/commands/images/create.js +2 -1
  19. package/src/commands/images/delete.js +2 -1
  20. package/src/commands/images/list.js +2 -1
  21. package/src/commands/instances/Instance.js +27 -0
  22. package/src/commands/instances/create.js +11 -4
  23. package/src/commands/instances/delete.js +20 -5
  24. package/src/commands/instances/index.js +2 -1
  25. package/src/commands/instances/list.js +11 -5
  26. package/src/commands/instances/start.js +2 -1
  27. package/src/commands/instances/stop.js +2 -1
  28. package/src/commands/instances/upgrade.js +90 -0
  29. package/src/commands/login.js +14 -2
  30. package/src/commands/logout.js +2 -1
  31. package/src/commands/projects/create.js +2 -1
  32. package/src/commands/projects/delete.js +2 -1
  33. package/src/commands/projects/list.js +2 -1
  34. package/src/commands/signup.js +14 -5
  35. package/src/commands/webplayer/WebPlayer.js +2 -1
  36. package/src/commands/webplayer/create.js +8 -1
  37. package/src/commands/webplayer/destroy.js +2 -1
  38. package/src/commands/webplayer/list.js +19 -17
  39. package/src/commands/webplayer/login.js +2 -1
  40. package/src/error.js +14 -1
  41. package/src/logging.js +1 -1
  42. package/src/profile.js +12 -9
  43. package/src/resumable.js +1314 -0
  44. package/src/table.js +7 -2
  45. package/src/upload.js +64 -2
  46. package/src/utils.js +11 -4
  47. package/test/test.js +89 -0
  48. package/example/WebPlayerSample.js +0 -263
  49. package/node_modules/@corellium/corellium-api/README.md +0 -1210
  50. package/node_modules/@corellium/corellium-api/node_modules/form-data/License +0 -19
  51. package/node_modules/@corellium/corellium-api/node_modules/form-data/README.md.bak +0 -356
  52. package/node_modules/@corellium/corellium-api/node_modules/form-data/Readme.md +0 -356
  53. package/node_modules/@corellium/corellium-api/node_modules/form-data/index.d.ts +0 -62
  54. package/node_modules/@corellium/corellium-api/node_modules/form-data/lib/browser.js +0 -2
  55. package/node_modules/@corellium/corellium-api/node_modules/form-data/lib/form_data.js +0 -498
  56. package/node_modules/@corellium/corellium-api/node_modules/form-data/lib/populate.js +0 -10
  57. package/node_modules/@corellium/corellium-api/node_modules/form-data/package.json +0 -104
  58. package/node_modules/@corellium/corellium-api/node_modules/uuid/AUTHORS +0 -5
  59. package/node_modules/@corellium/corellium-api/node_modules/uuid/CHANGELOG.md +0 -119
  60. package/node_modules/@corellium/corellium-api/node_modules/uuid/LICENSE.md +0 -21
  61. package/node_modules/@corellium/corellium-api/node_modules/uuid/README.md +0 -276
  62. package/node_modules/@corellium/corellium-api/node_modules/uuid/bin/uuid +0 -65
  63. package/node_modules/@corellium/corellium-api/node_modules/uuid/index.js +0 -8
  64. package/node_modules/@corellium/corellium-api/node_modules/uuid/lib/bytesToUuid.js +0 -26
  65. package/node_modules/@corellium/corellium-api/node_modules/uuid/lib/md5-browser.js +0 -216
  66. package/node_modules/@corellium/corellium-api/node_modules/uuid/lib/md5.js +0 -25
  67. package/node_modules/@corellium/corellium-api/node_modules/uuid/lib/rng-browser.js +0 -34
  68. package/node_modules/@corellium/corellium-api/node_modules/uuid/lib/rng.js +0 -8
  69. package/node_modules/@corellium/corellium-api/node_modules/uuid/lib/sha1-browser.js +0 -89
  70. package/node_modules/@corellium/corellium-api/node_modules/uuid/lib/sha1.js +0 -25
  71. package/node_modules/@corellium/corellium-api/node_modules/uuid/lib/v35.js +0 -57
  72. package/node_modules/@corellium/corellium-api/node_modules/uuid/package.json +0 -103
  73. package/node_modules/@corellium/corellium-api/node_modules/uuid/v1.js +0 -109
  74. package/node_modules/@corellium/corellium-api/node_modules/uuid/v3.js +0 -4
  75. package/node_modules/@corellium/corellium-api/node_modules/uuid/v4.js +0 -29
  76. package/node_modules/@corellium/corellium-api/node_modules/uuid/v5.js +0 -3
  77. package/node_modules/@corellium/corellium-api/package.json +0 -106
  78. package/node_modules/@corellium/corellium-api/resumable.js +0 -1312
  79. package/node_modules/@corellium/corellium-api/src/agent.js +0 -962
  80. package/node_modules/@corellium/corellium-api/src/corellium.js +0 -444
  81. package/node_modules/@corellium/corellium-api/src/images.js +0 -131
  82. package/node_modules/@corellium/corellium-api/src/input.js +0 -178
  83. package/node_modules/@corellium/corellium-api/src/instance-updater.js +0 -56
  84. package/node_modules/@corellium/corellium-api/src/instance.js +0 -1031
  85. package/node_modules/@corellium/corellium-api/src/netmon.js +0 -308
  86. package/node_modules/@corellium/corellium-api/src/project.js +0 -393
  87. package/node_modules/@corellium/corellium-api/src/role.js +0 -65
  88. package/node_modules/@corellium/corellium-api/src/snapshot.js +0 -77
  89. package/node_modules/@corellium/corellium-api/src/team.js +0 -29
  90. package/node_modules/@corellium/corellium-api/src/user.js +0 -51
  91. package/node_modules/@corellium/corellium-api/src/util/fetch.js +0 -62
  92. package/node_modules/@corellium/corellium-api/src/util/sleep.js +0 -7
  93. package/node_modules/@corellium/corellium-api/test/integration-tests.js +0 -1292
  94. package/node_modules/@corellium/corellium-api/test/root-hook-set-flag-if-test-failed.js +0 -7
  95. package/node_modules/async-limiter/.eslintignore +0 -2
  96. package/node_modules/async-limiter/.nycrc +0 -10
  97. package/node_modules/async-limiter/.travis.yml +0 -9
  98. package/node_modules/async-limiter/LICENSE +0 -8
  99. package/node_modules/async-limiter/index.js +0 -67
  100. package/node_modules/async-limiter/package.json +0 -72
  101. package/node_modules/async-limiter/readme.md +0 -132
  102. package/node_modules/buffer-crc32/LICENSE +0 -19
  103. package/node_modules/buffer-crc32/README.md +0 -47
  104. package/node_modules/buffer-crc32/index.js +0 -111
  105. package/node_modules/buffer-crc32/package.json +0 -72
  106. package/node_modules/cross-fetch/LICENSE +0 -21
  107. package/node_modules/cross-fetch/README.md +0 -169
  108. package/node_modules/cross-fetch/dist/browser-polyfill.js +0 -532
  109. package/node_modules/cross-fetch/dist/browser-ponyfill.js +0 -554
  110. package/node_modules/cross-fetch/dist/cross-fetch.js +0 -2
  111. package/node_modules/cross-fetch/dist/cross-fetch.js.map +0 -1
  112. package/node_modules/cross-fetch/dist/node-polyfill.js +0 -11
  113. package/node_modules/cross-fetch/dist/node-ponyfill.js +0 -22
  114. package/node_modules/cross-fetch/dist/react-native-polyfill.js +0 -12
  115. package/node_modules/cross-fetch/dist/react-native-ponyfill.js +0 -6
  116. package/node_modules/cross-fetch/index.d.ts +0 -14
  117. package/node_modules/cross-fetch/package.json +0 -160
  118. package/node_modules/cross-fetch/polyfill/package.json +0 -8
  119. package/node_modules/duplexify/.travis.yml +0 -6
  120. package/node_modules/duplexify/LICENSE +0 -21
  121. package/node_modules/duplexify/README.md +0 -97
  122. package/node_modules/duplexify/example.js +0 -21
  123. package/node_modules/duplexify/index.js +0 -234
  124. package/node_modules/duplexify/package.json +0 -69
  125. package/node_modules/duplexify/test.js +0 -295
  126. package/node_modules/end-of-stream/LICENSE +0 -21
  127. package/node_modules/end-of-stream/README.md +0 -54
  128. package/node_modules/end-of-stream/index.js +0 -94
  129. package/node_modules/end-of-stream/package.json +0 -69
  130. package/node_modules/fast-stable-stringify/.npmignore +0 -4
  131. package/node_modules/fast-stable-stringify/.travis.yml +0 -10
  132. package/node_modules/fast-stable-stringify/LICENSE +0 -21
  133. package/node_modules/fast-stable-stringify/README.md +0 -81
  134. package/node_modules/fast-stable-stringify/cli/files-to-comparison-results.js +0 -67
  135. package/node_modules/fast-stable-stringify/cli/format-table.js +0 -70
  136. package/node_modules/fast-stable-stringify/cli/index.js +0 -19
  137. package/node_modules/fast-stable-stringify/fixtures/index.js +0 -5
  138. package/node_modules/fast-stable-stringify/fixtures/input-data-types.js +0 -191
  139. package/node_modules/fast-stable-stringify/fixtures/log-result.json +0 -22
  140. package/node_modules/fast-stable-stringify/fixtures/log.txt +0 -24
  141. package/node_modules/fast-stable-stringify/index.js +0 -73
  142. package/node_modules/fast-stable-stringify/karma.conf.js +0 -124
  143. package/node_modules/fast-stable-stringify/karma.conf.travis.js +0 -95
  144. package/node_modules/fast-stable-stringify/package.json +0 -77
  145. package/node_modules/fast-stable-stringify/results/escape-long/Chrome 60.0.3112 (Windows 7 0.0.0).json +0 -57
  146. package/node_modules/fast-stable-stringify/results/escape-long/Chrome Mobile 55.0.2883 (Android 6.0.0).json +0 -57
  147. package/node_modules/fast-stable-stringify/results/escape-long/Edge 14.14393.0 (Windows 10 0.0.0).json +0 -57
  148. package/node_modules/fast-stable-stringify/results/escape-long/Firefox 54.0.0 (Windows 7 0.0.0).json +0 -57
  149. package/node_modules/fast-stable-stringify/results/escape-long/IE 10.0.0 (Windows 7 0.0.0).json +0 -57
  150. package/node_modules/fast-stable-stringify/results/escape-long/IE 11.0.0 (Windows 7 0.0.0).json +0 -57
  151. package/node_modules/fast-stable-stringify/results/escape-long/IE 9.0.0 (Windows 7 0.0.0).json +0 -57
  152. package/node_modules/fast-stable-stringify/results/escape-long/Mobile Safari 10.0.0 (iOS 10.3.0).json +0 -57
  153. package/node_modules/fast-stable-stringify/results/escape-long/Safari 10.0.1 (Mac OS X 10.12.1).json +0 -57
  154. package/node_modules/fast-stable-stringify/results/escape-short/Chrome 60.0.3112 (Windows 7 0.0.0).json +0 -57
  155. package/node_modules/fast-stable-stringify/results/escape-short/Chrome Mobile 55.0.2883 (Android 6.0.0).json +0 -57
  156. package/node_modules/fast-stable-stringify/results/escape-short/Edge 14.14393.0 (Windows 10 0.0.0).json +0 -57
  157. package/node_modules/fast-stable-stringify/results/escape-short/Firefox 54.0.0 (Windows 7 0.0.0).json +0 -57
  158. package/node_modules/fast-stable-stringify/results/escape-short/IE 10.0.0 (Windows 7 0.0.0).json +0 -57
  159. package/node_modules/fast-stable-stringify/results/escape-short/IE 11.0.0 (Windows 7 0.0.0).json +0 -57
  160. package/node_modules/fast-stable-stringify/results/escape-short/IE 9.0.0 (Windows 7 0.0.0).json +0 -57
  161. package/node_modules/fast-stable-stringify/results/escape-short/Mobile Safari 10.0.0 (iOS 10.3.0).json +0 -57
  162. package/node_modules/fast-stable-stringify/results/escape-short/Safari 10.0.1 (Mac OS X 10.12.1).json +0 -57
  163. package/node_modules/fast-stable-stringify/results/escape.md +0 -20
  164. package/node_modules/fast-stable-stringify/results/itar-long/Chrome 60.0.3112 (Windows 7 0.0.0).json +0 -35
  165. package/node_modules/fast-stable-stringify/results/itar-long/Chrome Mobile 55.0.2883 (Android 6.0.0).json +0 -35
  166. package/node_modules/fast-stable-stringify/results/itar-long/Edge 14.14393.0 (Windows 10 0.0.0).json +0 -35
  167. package/node_modules/fast-stable-stringify/results/itar-long/Firefox 54.0.0 (Windows 7 0.0.0).json +0 -35
  168. package/node_modules/fast-stable-stringify/results/itar-long/IE 10.0.0 (Windows 7 0.0.0).json +0 -35
  169. package/node_modules/fast-stable-stringify/results/itar-long/IE 11.0.0 (Windows 7 0.0.0).json +0 -35
  170. package/node_modules/fast-stable-stringify/results/itar-long/IE 9.0.0 (Windows 7 0.0.0).json +0 -35
  171. package/node_modules/fast-stable-stringify/results/itar-long/Mobile Safari 10.0.0 (iOS 10.3.0).json +0 -35
  172. package/node_modules/fast-stable-stringify/results/itar-long/Safari 10.0.1 (Mac OS X 10.12.1).json +0 -35
  173. package/node_modules/fast-stable-stringify/results/itar-short/Chrome 60.0.3112 (Windows 7 0.0.0).json +0 -35
  174. package/node_modules/fast-stable-stringify/results/itar-short/Chrome Mobile 55.0.2883 (Android 6.0.0).json +0 -35
  175. package/node_modules/fast-stable-stringify/results/itar-short/Edge 14.14393.0 (Windows 10 0.0.0).json +0 -35
  176. package/node_modules/fast-stable-stringify/results/itar-short/Firefox 54.0.0 (Windows 7 0.0.0).json +0 -35
  177. package/node_modules/fast-stable-stringify/results/itar-short/IE 10.0.0 (Windows 7 0.0.0).json +0 -35
  178. package/node_modules/fast-stable-stringify/results/itar-short/IE 11.0.0 (Windows 7 0.0.0).json +0 -35
  179. package/node_modules/fast-stable-stringify/results/itar-short/IE 9.0.0 (Windows 7 0.0.0).json +0 -35
  180. package/node_modules/fast-stable-stringify/results/itar-short/Mobile Safari 10.0.0 (iOS 10.3.0).json +0 -35
  181. package/node_modules/fast-stable-stringify/results/itar-short/Safari 10.0.1 (Mac OS X 10.12.1).json +0 -35
  182. package/node_modules/fast-stable-stringify/results/itar.md +0 -20
  183. package/node_modules/fast-stable-stringify/results/iter/Chrome 60.0.3112 (Windows 7 0.0.0).json +0 -35
  184. package/node_modules/fast-stable-stringify/results/iter/Chrome Mobile 39.0.0 (Android 5.1.1).json +0 -35
  185. package/node_modules/fast-stable-stringify/results/iter/Chrome Mobile 55.0.2883 (Android 6.0.0).json +0 -35
  186. package/node_modules/fast-stable-stringify/results/iter/Edge 14.14393.0 (Windows 10 0.0.0).json +0 -35
  187. package/node_modules/fast-stable-stringify/results/iter/Firefox 54.0.0 (Windows 7 0.0.0).json +0 -35
  188. package/node_modules/fast-stable-stringify/results/iter/IE 10.0.0 (Windows 7 0.0.0).json +0 -35
  189. package/node_modules/fast-stable-stringify/results/iter/IE 11.0.0 (Windows 7 0.0.0).json +0 -35
  190. package/node_modules/fast-stable-stringify/results/iter/IE 9.0.0 (Windows 7 0.0.0).json +0 -35
  191. package/node_modules/fast-stable-stringify/results/iter/Mobile Safari 10.0.0 (iOS 10.3.0).json +0 -35
  192. package/node_modules/fast-stable-stringify/results/iter/Mobile Safari 9.0.0 (iOS 9.2.0).json +0 -35
  193. package/node_modules/fast-stable-stringify/results/iter/Safari 10.0.1 (Mac OS X 10.12.1).json +0 -35
  194. package/node_modules/fast-stable-stringify/results/iter/Safari 9.1.2 (Mac OS X 10.11.6).json +0 -35
  195. package/node_modules/fast-stable-stringify/results/iter.md +0 -14
  196. package/node_modules/fast-stable-stringify/results/libs/Chrome 60.0.3112 (Windows 7 0.0.0).json +0 -46
  197. package/node_modules/fast-stable-stringify/results/libs/Chrome Mobile 55.0.2883 (Android 6.0.0).json +0 -46
  198. package/node_modules/fast-stable-stringify/results/libs/Edge 14.14393.0 (Windows 10 0.0.0).json +0 -46
  199. package/node_modules/fast-stable-stringify/results/libs/Firefox 54.0.0 (Windows 7 0.0.0).json +0 -46
  200. package/node_modules/fast-stable-stringify/results/libs/IE 10.0.0 (Windows 7 0.0.0).json +0 -35
  201. package/node_modules/fast-stable-stringify/results/libs/IE 11.0.0 (Windows 7 0.0.0).json +0 -35
  202. package/node_modules/fast-stable-stringify/results/libs/IE 9.0.0 (Windows 7 0.0.0).json +0 -35
  203. package/node_modules/fast-stable-stringify/results/libs/Mobile Safari 10.0.0 (iOS 10.3.0).json +0 -46
  204. package/node_modules/fast-stable-stringify/results/libs/Safari 10.0.1 (Mac OS X 10.12.1).json +0 -46
  205. package/node_modules/fast-stable-stringify/results/libs.md +0 -15
  206. package/node_modules/fast-stable-stringify/test/escape-long.js +0 -147
  207. package/node_modules/fast-stable-stringify/test/escape-short.js +0 -147
  208. package/node_modules/fast-stable-stringify/test/index.js +0 -6
  209. package/node_modules/fast-stable-stringify/test/itar-long.js +0 -52
  210. package/node_modules/fast-stable-stringify/test/itar-short.js +0 -52
  211. package/node_modules/fast-stable-stringify/test/iter.js +0 -84
  212. package/node_modules/fast-stable-stringify/test/libs.js +0 -57
  213. package/node_modules/fast-stable-stringify/test/travis.js +0 -43
  214. package/node_modules/fast-stable-stringify/test/validate.js +0 -24
  215. package/node_modules/fast-stable-stringify/util/eachRecursive.js +0 -9
  216. package/node_modules/fast-stable-stringify/util/get-git-hash-sync.js +0 -21
  217. package/node_modules/fast-stable-stringify/util/get-lib-info.js +0 -22
  218. package/node_modules/fast-stable-stringify/util/object-path.js +0 -47
  219. package/node_modules/fast-stable-stringify/v8-profile/bench.js +0 -8
  220. package/node_modules/fast-stable-stringify/v8-profile/run.sh +0 -2
  221. package/node_modules/fast-stable-stringify/zuul-local.sh +0 -2
  222. package/node_modules/hkdf/.npmignore +0 -2
  223. package/node_modules/hkdf/README.md +0 -23
  224. package/node_modules/hkdf/hkdf.py +0 -171
  225. package/node_modules/hkdf/hkdf.pyc +0 -0
  226. package/node_modules/hkdf/index.js +0 -1
  227. package/node_modules/hkdf/lib/hkdf.js +0 -55
  228. package/node_modules/hkdf/package.json +0 -55
  229. package/node_modules/hkdf/scripts/run_all_tests.sh +0 -19
  230. package/node_modules/hkdf/test/all-test.js +0 -79
  231. package/node_modules/hkdf/test.py +0 -11
  232. package/node_modules/immediate/LICENSE.txt +0 -20
  233. package/node_modules/immediate/README.md +0 -93
  234. package/node_modules/immediate/dist/immediate.js +0 -75
  235. package/node_modules/immediate/dist/immediate.min.js +0 -1
  236. package/node_modules/immediate/lib/browser.js +0 -69
  237. package/node_modules/immediate/lib/index.js +0 -73
  238. package/node_modules/immediate/package.json +0 -86
  239. package/node_modules/isarray/.npmignore +0 -1
  240. package/node_modules/isarray/.travis.yml +0 -4
  241. package/node_modules/isarray/Makefile +0 -6
  242. package/node_modules/isarray/README.md +0 -60
  243. package/node_modules/isarray/component.json +0 -19
  244. package/node_modules/isarray/index.js +0 -5
  245. package/node_modules/isarray/package.json +0 -77
  246. package/node_modules/isarray/test.js +0 -20
  247. package/node_modules/jszip/.codeclimate.yml +0 -16
  248. package/node_modules/jszip/.editorconfig +0 -8
  249. package/node_modules/jszip/.github/workflows/pr.yaml +0 -41
  250. package/node_modules/jszip/.jshintignore +0 -1
  251. package/node_modules/jszip/.jshintrc +0 -21
  252. package/node_modules/jszip/.travis.yml +0 -17
  253. package/node_modules/jszip/CHANGES.md +0 -192
  254. package/node_modules/jszip/LICENSE.markdown +0 -651
  255. package/node_modules/jszip/README.markdown +0 -33
  256. package/node_modules/jszip/dist/jszip.js +0 -11583
  257. package/node_modules/jszip/dist/jszip.min.js +0 -13
  258. package/node_modules/jszip/index.d.ts +0 -335
  259. package/node_modules/jszip/lib/base64.js +0 -106
  260. package/node_modules/jszip/lib/compressedObject.js +0 -74
  261. package/node_modules/jszip/lib/compressions.js +0 -14
  262. package/node_modules/jszip/lib/crc32.js +0 -77
  263. package/node_modules/jszip/lib/defaults.js +0 -11
  264. package/node_modules/jszip/lib/external.js +0 -19
  265. package/node_modules/jszip/lib/flate.js +0 -85
  266. package/node_modules/jszip/lib/generate/ZipFileWorker.js +0 -540
  267. package/node_modules/jszip/lib/generate/index.js +0 -57
  268. package/node_modules/jszip/lib/index.js +0 -55
  269. package/node_modules/jszip/lib/license_header.js +0 -11
  270. package/node_modules/jszip/lib/load.js +0 -88
  271. package/node_modules/jszip/lib/nodejs/NodejsStreamInputAdapter.js +0 -74
  272. package/node_modules/jszip/lib/nodejs/NodejsStreamOutputAdapter.js +0 -42
  273. package/node_modules/jszip/lib/nodejsUtils.js +0 -57
  274. package/node_modules/jszip/lib/object.js +0 -389
  275. package/node_modules/jszip/lib/readable-stream-browser.js +0 -9
  276. package/node_modules/jszip/lib/reader/ArrayReader.js +0 -57
  277. package/node_modules/jszip/lib/reader/DataReader.js +0 -116
  278. package/node_modules/jszip/lib/reader/NodeBufferReader.js +0 -19
  279. package/node_modules/jszip/lib/reader/StringReader.js +0 -38
  280. package/node_modules/jszip/lib/reader/Uint8ArrayReader.js +0 -22
  281. package/node_modules/jszip/lib/reader/readerFor.js +0 -28
  282. package/node_modules/jszip/lib/signature.js +0 -7
  283. package/node_modules/jszip/lib/stream/ConvertWorker.js +0 -26
  284. package/node_modules/jszip/lib/stream/Crc32Probe.js +0 -24
  285. package/node_modules/jszip/lib/stream/DataLengthProbe.js +0 -29
  286. package/node_modules/jszip/lib/stream/DataWorker.js +0 -116
  287. package/node_modules/jszip/lib/stream/GenericWorker.js +0 -263
  288. package/node_modules/jszip/lib/stream/StreamHelper.js +0 -212
  289. package/node_modules/jszip/lib/support.js +0 -38
  290. package/node_modules/jszip/lib/utf8.js +0 -275
  291. package/node_modules/jszip/lib/utils.js +0 -501
  292. package/node_modules/jszip/lib/zipEntries.js +0 -262
  293. package/node_modules/jszip/lib/zipEntry.js +0 -294
  294. package/node_modules/jszip/lib/zipObject.js +0 -133
  295. package/node_modules/jszip/package.json +0 -99
  296. package/node_modules/jszip/tsconfig.json +0 -101
  297. package/node_modules/jszip/vendor/FileSaver.js +0 -247
  298. package/node_modules/lie/README.md +0 -62
  299. package/node_modules/lie/dist/lie.js +0 -350
  300. package/node_modules/lie/dist/lie.min.js +0 -1
  301. package/node_modules/lie/dist/lie.polyfill.js +0 -358
  302. package/node_modules/lie/dist/lie.polyfill.min.js +0 -1
  303. package/node_modules/lie/lib/browser.js +0 -273
  304. package/node_modules/lie/lib/index.js +0 -298
  305. package/node_modules/lie/license.md +0 -7
  306. package/node_modules/lie/lie.d.ts +0 -244
  307. package/node_modules/lie/package.json +0 -98
  308. package/node_modules/lie/polyfill.js +0 -4
  309. package/node_modules/p-finally/index.js +0 -15
  310. package/node_modules/p-finally/license +0 -21
  311. package/node_modules/p-finally/package.json +0 -77
  312. package/node_modules/p-finally/readme.md +0 -47
  313. package/node_modules/p-retry/index.js +0 -52
  314. package/node_modules/p-retry/license +0 -9
  315. package/node_modules/p-retry/package.json +0 -83
  316. package/node_modules/p-retry/readme.md +0 -109
  317. package/node_modules/p-timeout/index.d.ts +0 -72
  318. package/node_modules/p-timeout/index.js +0 -57
  319. package/node_modules/p-timeout/license +0 -9
  320. package/node_modules/p-timeout/package.json +0 -80
  321. package/node_modules/p-timeout/readme.md +0 -87
  322. package/node_modules/pako/CHANGELOG.md +0 -164
  323. package/node_modules/pako/LICENSE +0 -21
  324. package/node_modules/pako/README.md +0 -191
  325. package/node_modules/pako/dist/pako.js +0 -6818
  326. package/node_modules/pako/dist/pako.min.js +0 -1
  327. package/node_modules/pako/dist/pako_deflate.js +0 -3997
  328. package/node_modules/pako/dist/pako_deflate.min.js +0 -1
  329. package/node_modules/pako/dist/pako_inflate.js +0 -3300
  330. package/node_modules/pako/dist/pako_inflate.min.js +0 -1
  331. package/node_modules/pako/index.js +0 -14
  332. package/node_modules/pako/lib/deflate.js +0 -400
  333. package/node_modules/pako/lib/inflate.js +0 -423
  334. package/node_modules/pako/lib/utils/common.js +0 -105
  335. package/node_modules/pako/lib/utils/strings.js +0 -187
  336. package/node_modules/pako/lib/zlib/README +0 -59
  337. package/node_modules/pako/lib/zlib/adler32.js +0 -51
  338. package/node_modules/pako/lib/zlib/constants.js +0 -68
  339. package/node_modules/pako/lib/zlib/crc32.js +0 -59
  340. package/node_modules/pako/lib/zlib/deflate.js +0 -1874
  341. package/node_modules/pako/lib/zlib/gzheader.js +0 -58
  342. package/node_modules/pako/lib/zlib/inffast.js +0 -345
  343. package/node_modules/pako/lib/zlib/inflate.js +0 -1556
  344. package/node_modules/pako/lib/zlib/inftrees.js +0 -343
  345. package/node_modules/pako/lib/zlib/messages.js +0 -32
  346. package/node_modules/pako/lib/zlib/trees.js +0 -1222
  347. package/node_modules/pako/lib/zlib/zstream.js +0 -47
  348. package/node_modules/pako/package.json +0 -94
  349. package/node_modules/process-nextick-args/index.js +0 -45
  350. package/node_modules/process-nextick-args/license.md +0 -19
  351. package/node_modules/process-nextick-args/package.json +0 -53
  352. package/node_modules/process-nextick-args/readme.md +0 -18
  353. package/node_modules/readable-stream/.travis.yml +0 -34
  354. package/node_modules/readable-stream/CONTRIBUTING.md +0 -38
  355. package/node_modules/readable-stream/GOVERNANCE.md +0 -136
  356. package/node_modules/readable-stream/LICENSE +0 -47
  357. package/node_modules/readable-stream/README.md +0 -58
  358. package/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +0 -60
  359. package/node_modules/readable-stream/duplex-browser.js +0 -1
  360. package/node_modules/readable-stream/duplex.js +0 -1
  361. package/node_modules/readable-stream/lib/_stream_duplex.js +0 -131
  362. package/node_modules/readable-stream/lib/_stream_passthrough.js +0 -47
  363. package/node_modules/readable-stream/lib/_stream_readable.js +0 -1019
  364. package/node_modules/readable-stream/lib/_stream_transform.js +0 -214
  365. package/node_modules/readable-stream/lib/_stream_writable.js +0 -687
  366. package/node_modules/readable-stream/lib/internal/streams/BufferList.js +0 -79
  367. package/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -74
  368. package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
  369. package/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
  370. package/node_modules/readable-stream/package.json +0 -86
  371. package/node_modules/readable-stream/passthrough.js +0 -1
  372. package/node_modules/readable-stream/readable-browser.js +0 -7
  373. package/node_modules/readable-stream/readable.js +0 -19
  374. package/node_modules/readable-stream/transform.js +0 -1
  375. package/node_modules/readable-stream/writable-browser.js +0 -1
  376. package/node_modules/readable-stream/writable.js +0 -8
  377. package/node_modules/retry/.npmignore +0 -3
  378. package/node_modules/retry/.travis.yml +0 -15
  379. package/node_modules/retry/License +0 -21
  380. package/node_modules/retry/Makefile +0 -18
  381. package/node_modules/retry/README.md +0 -227
  382. package/node_modules/retry/equation.gif +0 -0
  383. package/node_modules/retry/example/dns.js +0 -31
  384. package/node_modules/retry/example/stop.js +0 -40
  385. package/node_modules/retry/index.js +0 -1
  386. package/node_modules/retry/lib/retry.js +0 -100
  387. package/node_modules/retry/lib/retry_operation.js +0 -158
  388. package/node_modules/retry/package.json +0 -67
  389. package/node_modules/retry/test/common.js +0 -10
  390. package/node_modules/retry/test/integration/test-forever.js +0 -24
  391. package/node_modules/retry/test/integration/test-retry-operation.js +0 -258
  392. package/node_modules/retry/test/integration/test-retry-wrap.js +0 -101
  393. package/node_modules/retry/test/integration/test-timeouts.js +0 -69
  394. package/node_modules/setimmediate/LICENSE.txt +0 -20
  395. package/node_modules/setimmediate/package.json +0 -77
  396. package/node_modules/setimmediate/setImmediate.js +0 -186
  397. package/node_modules/split/.npmignore +0 -3
  398. package/node_modules/split/.travis.yml +0 -3
  399. package/node_modules/split/LICENCE +0 -22
  400. package/node_modules/split/examples/pretty.js +0 -26
  401. package/node_modules/split/index.js +0 -63
  402. package/node_modules/split/package.json +0 -65
  403. package/node_modules/split/readme.markdown +0 -72
  404. package/node_modules/split/test/options.asynct.js +0 -46
  405. package/node_modules/split/test/partitioned_unicode.js +0 -34
  406. package/node_modules/split/test/split.asynct.js +0 -137
  407. package/node_modules/split/test/try_catch.asynct.js +0 -51
  408. package/node_modules/stream-shift/.travis.yml +0 -6
  409. package/node_modules/stream-shift/LICENSE +0 -21
  410. package/node_modules/stream-shift/README.md +0 -25
  411. package/node_modules/stream-shift/index.js +0 -20
  412. package/node_modules/stream-shift/package.json +0 -56
  413. package/node_modules/stream-shift/test.js +0 -48
  414. package/node_modules/ultron/LICENSE +0 -22
  415. package/node_modules/ultron/README.md +0 -113
  416. package/node_modules/ultron/index.js +0 -136
  417. package/node_modules/ultron/package.json +0 -71
  418. package/node_modules/websocket-stream/LICENSE +0 -8
  419. package/node_modules/websocket-stream/collaborators.md +0 -11
  420. package/node_modules/websocket-stream/echo-server.js +0 -51
  421. package/node_modules/websocket-stream/index.d.ts +0 -27
  422. package/node_modules/websocket-stream/index.js +0 -6
  423. package/node_modules/websocket-stream/package.json +0 -82
  424. package/node_modules/websocket-stream/readme.md +0 -148
  425. package/node_modules/websocket-stream/server.js +0 -29
  426. package/node_modules/websocket-stream/stream.js +0 -189
  427. package/node_modules/websocket-stream/test-client.js +0 -74
  428. package/node_modules/websocket-stream/test-server.js +0 -56
  429. package/node_modules/websocket-stream/test.js +0 -338
  430. package/node_modules/websocket-stream/ts-tests.ts +0 -69
  431. package/node_modules/websocket-stream/ws-fallback.js +0 -12
  432. package/node_modules/ws/LICENSE +0 -21
  433. package/node_modules/ws/README.md +0 -341
  434. package/node_modules/ws/index.js +0 -15
  435. package/node_modules/ws/lib/.DS_Store +0 -0
  436. package/node_modules/ws/lib/BufferUtil.js +0 -71
  437. package/node_modules/ws/lib/Constants.js +0 -10
  438. package/node_modules/ws/lib/ErrorCodes.js +0 -28
  439. package/node_modules/ws/lib/EventTarget.js +0 -151
  440. package/node_modules/ws/lib/Extensions.js +0 -203
  441. package/node_modules/ws/lib/PerMessageDeflate.js +0 -507
  442. package/node_modules/ws/lib/Receiver.js +0 -553
  443. package/node_modules/ws/lib/Sender.js +0 -412
  444. package/node_modules/ws/lib/Validation.js +0 -17
  445. package/node_modules/ws/lib/WebSocket.js +0 -717
  446. package/node_modules/ws/lib/WebSocketServer.js +0 -326
  447. package/node_modules/ws/package.json +0 -83
  448. package/node_modules/xhr2/CONTRIBUTING.md +0 -33
  449. package/node_modules/xhr2/Cakefile +0 -131
  450. package/node_modules/xhr2/LICENSE.txt +0 -19
  451. package/node_modules/xhr2/README.md +0 -142
  452. package/node_modules/xhr2/lib/browser.js +0 -1
  453. package/node_modules/xhr2/lib/xhr2.js +0 -1244
  454. package/node_modules/xhr2/package.json +0 -103
  455. package/node_modules/xhr2/src/000-xml_http_request_event_target.coffee +0 -89
  456. package/node_modules/xhr2/src/001-xml_http_request.coffee +0 -781
  457. package/node_modules/xhr2/src/errors.coffee +0 -31
  458. package/node_modules/xhr2/src/progress_event.coffee +0 -39
  459. package/node_modules/xhr2/src/xml_http_request_upload.coffee +0 -95
  460. package/node_modules/xhr2/test/fixtures/hello.json +0 -1
  461. package/node_modules/xhr2/test/fixtures/hello.txt +0 -1
  462. package/node_modules/xhr2/test/fixtures/xhr2.png +0 -0
  463. package/node_modules/xhr2/test/html/browser_test.html +0 -30
  464. package/node_modules/xhr2/test/src/event_target_test.coffee +0 -85
  465. package/node_modules/xhr2/test/src/events_test.coffee +0 -204
  466. package/node_modules/xhr2/test/src/headers_test.coffee +0 -168
  467. package/node_modules/xhr2/test/src/helpers/browser_mocha_runner.coffee +0 -10
  468. package/node_modules/xhr2/test/src/helpers/browser_mocha_setup.coffee +0 -1
  469. package/node_modules/xhr2/test/src/helpers/setup.coffee +0 -38
  470. package/node_modules/xhr2/test/src/helpers/xhr_server.coffee +0 -156
  471. package/node_modules/xhr2/test/src/nodejs_set_test.coffee +0 -162
  472. package/node_modules/xhr2/test/src/redirect_test.coffee +0 -57
  473. package/node_modules/xhr2/test/src/response_type_test.coffee +0 -88
  474. package/node_modules/xhr2/test/src/responseurl_test.coffee +0 -18
  475. package/node_modules/xhr2/test/src/send_test.coffee +0 -89
  476. package/node_modules/xhr2/test/src/status_test.coffee +0 -47
  477. package/node_modules/xhr2/test/src/xhr_test.coffee +0 -102
  478. package/node_modules/xtend/.jshintrc +0 -30
  479. package/node_modules/xtend/LICENSE +0 -20
  480. package/node_modules/xtend/README.md +0 -32
  481. package/node_modules/xtend/immutable.js +0 -19
  482. package/node_modules/xtend/mutable.js +0 -17
  483. package/node_modules/xtend/package.json +0 -89
  484. package/node_modules/xtend/test.js +0 -103
  485. package/node_modules/yazl/LICENSE +0 -21
  486. package/node_modules/yazl/README.md +0 -389
  487. package/node_modules/yazl/index.js +0 -749
  488. package/node_modules/yazl/package.json +0 -69
  489. package/src/commands/CorelliumAPI.js +0 -76
  490. package/src/subscriberInvite.js +0 -140
@@ -0,0 +1,1314 @@
1
+ /*
2
+ * MIT Licensed
3
+ * http://www.23developer.com/opensource
4
+ * http://github.com/23/resumable.js
5
+ * Steffen Tiedemann Christensen, steffen@23company.com
6
+ */
7
+
8
+ /* eslint-disable */
9
+
10
+ const XMLHttpRequest = require('xhr2').XMLHttpRequest;
11
+
12
+ (function () {
13
+ 'use strict'
14
+
15
+ var Resumable = function (opts) {
16
+ if (!(this instanceof Resumable)) {
17
+ return new Resumable(opts)
18
+ }
19
+ this.version = 1.0
20
+ // SUPPORTED BY BROWSER?
21
+ // Check if these features are support by the browser:
22
+ // - File object type
23
+ // - Blob object type
24
+ // - FileList object type
25
+ // - slicing files
26
+ this.support = true
27
+ if (!this.support) return false
28
+ const window = { setTimeout }
29
+
30
+ // PROPERTIES
31
+ const $ = this
32
+ $.files = []
33
+ $.defaults = {
34
+ chunkSize: 1 * 1024 * 1024,
35
+ forceChunkSize: false,
36
+ simultaneousUploads: 3,
37
+ fileParameterName: 'file',
38
+ chunkNumberParameterName: 'resumableChunkNumber',
39
+ chunkSizeParameterName: 'resumableChunkSize',
40
+ currentChunkSizeParameterName: 'resumableCurrentChunkSize',
41
+ totalSizeParameterName: 'resumableTotalSize',
42
+ typeParameterName: 'resumableType',
43
+ identifierParameterName: 'resumableIdentifier',
44
+ fileNameParameterName: 'resumableFilename',
45
+ relativePathParameterName: 'resumableRelativePath',
46
+ totalChunksParameterName: 'resumableTotalChunks',
47
+ dragOverClass: 'dragover',
48
+ throttleProgressCallbacks: 0.5,
49
+ query: {},
50
+ headers: {},
51
+ preprocess: null,
52
+ preprocessFile: null,
53
+ method: 'multipart',
54
+ uploadMethod: 'POST',
55
+ testMethod: 'GET',
56
+ prioritizeFirstAndLastChunk: false,
57
+ target: '/',
58
+ testTarget: null,
59
+ parameterNamespace: '',
60
+ testChunks: true,
61
+ generateUniqueIdentifier: null,
62
+ getTarget: null,
63
+ maxChunkRetries: 100,
64
+ chunkRetryInterval: undefined,
65
+ permanentErrors: [400, 401, 403, 404, 409, 415, 500, 501],
66
+ maxFiles: undefined,
67
+ withCredentials: false,
68
+ xhrTimeout: 0,
69
+ clearInput: true,
70
+ chunkFormat: 'blob',
71
+ setChunkTypeFromFile: false,
72
+ maxFilesErrorCallback: function (files, errorCount) {
73
+ const maxFiles = $.getOpt('maxFiles')
74
+ alert(
75
+ 'Please upload no more than ' +
76
+ maxFiles +
77
+ ' file' +
78
+ (maxFiles === 1 ? '' : 's') +
79
+ ' at a time.'
80
+ )
81
+ },
82
+ minFileSize: 1,
83
+ minFileSizeErrorCallback: function (file, errorCount) {
84
+ alert(
85
+ file.fileName ||
86
+ file.name +
87
+ ' is too small, please upload files larger than ' +
88
+ $h.formatSize($.getOpt('minFileSize')) +
89
+ '.'
90
+ )
91
+ },
92
+ maxFileSize: undefined,
93
+ maxFileSizeErrorCallback: function (file, errorCount) {
94
+ alert(
95
+ file.fileName ||
96
+ file.name +
97
+ ' is too large, please upload files less than ' +
98
+ $h.formatSize($.getOpt('maxFileSize')) +
99
+ '.'
100
+ )
101
+ },
102
+ fileType: [],
103
+ fileTypeErrorCallback: function (file, errorCount) {
104
+ alert(
105
+ file.fileName ||
106
+ file.name +
107
+ ' has type not allowed, please upload files of type ' +
108
+ $.getOpt('fileType') +
109
+ '.'
110
+ )
111
+ }
112
+ }
113
+ $.opts = opts || {}
114
+ $.getOpt = function (o) {
115
+ let $opt = this
116
+ // Get multiple option if passed an array
117
+ if (o instanceof Array) {
118
+ const options = {}
119
+ $h.each(o, function (option) {
120
+ options[option] = $opt.getOpt(option)
121
+ })
122
+ return options
123
+ }
124
+ // Otherwise, just return a simple option
125
+ if ($opt instanceof ResumableChunk) {
126
+ if (typeof $opt.opts[o] !== 'undefined') {
127
+ return $opt.opts[o]
128
+ } else {
129
+ $opt = $opt.fileObj
130
+ }
131
+ }
132
+ if ($opt instanceof ResumableFile) {
133
+ if (typeof $opt.opts[o] !== 'undefined') {
134
+ return $opt.opts[o]
135
+ } else {
136
+ $opt = $opt.resumableObj
137
+ }
138
+ }
139
+ if ($opt instanceof Resumable) {
140
+ if (typeof $opt.opts[o] !== 'undefined') {
141
+ return $opt.opts[o]
142
+ } else {
143
+ return $opt.defaults[o]
144
+ }
145
+ }
146
+ }
147
+ $.indexOf = function (array, obj) {
148
+ if (array.indexOf) {
149
+ return array.indexOf(obj)
150
+ }
151
+ for (let i = 0; i < array.length; i++) {
152
+ if (array[i] === obj) {
153
+ return i
154
+ }
155
+ }
156
+ return -1
157
+ }
158
+
159
+ // EVENTS
160
+ // catchAll(event, ...)
161
+ // fileSuccess(file), fileProgress(file), fileAdded(file, event), filesAdded(files, filesSkipped), fileRetry(file),
162
+ // fileError(file, message), complete(), progress(), error(message, file), pause()
163
+ $.events = []
164
+ $.on = function (event, callback) {
165
+ $.events.push(event.toLowerCase(), callback)
166
+ }
167
+ $.fire = function () {
168
+ // `arguments` is an object, not array, in FF, so:
169
+ const args = []
170
+ for (var i = 0; i < arguments.length; i++) args.push(arguments[i])
171
+ // Find event listeners, and support pseudo-event `catchAll`
172
+ const event = args[0].toLowerCase()
173
+ for (var i = 0; i <= $.events.length; i += 2) {
174
+ if ($.events[i] == event) $.events[i + 1].apply($, args.slice(1))
175
+ if ($.events[i] == 'catchall') $.events[i + 1].apply(null, args)
176
+ }
177
+ if (event == 'fileerror') $.fire('error', args[2], args[1])
178
+ if (event == 'fileprogress') $.fire('progress')
179
+ }
180
+
181
+ // INTERNAL HELPER METHODS (handy, but ultimately not part of uploading)
182
+ var $h = {
183
+ stopEvent: function (e) {
184
+ e.stopPropagation()
185
+ e.preventDefault()
186
+ },
187
+ each: function (o, callback) {
188
+ if (typeof o.length !== 'undefined') {
189
+ for (var i = 0; i < o.length; i++) {
190
+ // Array or FileList
191
+ if (callback(o[i]) === false) return
192
+ }
193
+ } else {
194
+ for (i in o) {
195
+ // Object
196
+ if (callback(i, o[i]) === false) return
197
+ }
198
+ }
199
+ },
200
+ generateUniqueIdentifier: function (file, event) {
201
+ const custom = $.getOpt('generateUniqueIdentifier')
202
+ if (typeof custom === 'function') {
203
+ return custom(file, event)
204
+ }
205
+ const relativePath =
206
+ file.webkitRelativePath || file.relativePath || file.fileName || file.name // Some confusion in different versions of Firefox
207
+ const size = file.size
208
+ return size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/gim, '')
209
+ },
210
+ contains: function (array, test) {
211
+ let result = false
212
+
213
+ $h.each(array, function (value) {
214
+ if (value == test) {
215
+ result = true
216
+ return false
217
+ }
218
+ return true
219
+ })
220
+
221
+ return result
222
+ },
223
+ formatSize: function (size) {
224
+ if (size < 1024) {
225
+ return size + ' bytes'
226
+ } else if (size < 1024 * 1024) {
227
+ return (size / 1024.0).toFixed(0) + ' KB'
228
+ } else if (size < 1024 * 1024 * 1024) {
229
+ return (size / 1024.0 / 1024.0).toFixed(1) + ' MB'
230
+ } else {
231
+ return (size / 1024.0 / 1024.0 / 1024.0).toFixed(1) + ' GB'
232
+ }
233
+ },
234
+ getTarget: function (request, params) {
235
+ let target = $.getOpt('target')
236
+
237
+ if (request === 'test' && $.getOpt('testTarget')) {
238
+ target =
239
+ $.getOpt('testTarget') === '/'
240
+ ? $.getOpt('target')
241
+ : $.getOpt('testTarget')
242
+ }
243
+
244
+ if (typeof target === 'function') {
245
+ return target(params)
246
+ }
247
+
248
+ const separator = target.indexOf('?') < 0 ? '?' : '&'
249
+ const joinedParams = params.join('&')
250
+
251
+ if (joinedParams) target = target + separator + joinedParams
252
+
253
+ return target
254
+ }
255
+ }
256
+
257
+ const onDrop = function (e) {
258
+ e.currentTarget.classList.remove($.getOpt('dragOverClass'))
259
+ $h.stopEvent(e)
260
+
261
+ // handle dropped things as items if we can (this lets us deal with folders nicer in some cases)
262
+ if (e.dataTransfer && e.dataTransfer.items) {
263
+ loadFiles(e.dataTransfer.items, e)
264
+ }
265
+ // else handle them as files
266
+ else if (e.dataTransfer && e.dataTransfer.files) {
267
+ loadFiles(e.dataTransfer.files, e)
268
+ }
269
+ }
270
+ const onDragLeave = function (e) {
271
+ e.currentTarget.classList.remove($.getOpt('dragOverClass'))
272
+ }
273
+ const onDragOverEnter = function (e) {
274
+ e.preventDefault()
275
+ const dt = e.dataTransfer
276
+ if ($.indexOf(dt.types, 'Files') >= 0) {
277
+ // only for file drop
278
+ e.stopPropagation()
279
+ dt.dropEffect = 'copy'
280
+ dt.effectAllowed = 'copy'
281
+ e.currentTarget.classList.add($.getOpt('dragOverClass'))
282
+ } else {
283
+ // not work on IE/Edge....
284
+ dt.dropEffect = 'none'
285
+ dt.effectAllowed = 'none'
286
+ }
287
+ }
288
+
289
+ /**
290
+ * processes a single upload item (file or directory)
291
+ * @param {Object} item item to upload, may be file or directory entry
292
+ * @param {string} path current file path
293
+ * @param {File[]} items list of files to append new items to
294
+ * @param {Function} cb callback invoked when item is processed
295
+ */
296
+ function processItem (item, path, items, cb) {
297
+ let entry
298
+ if (item.isFile) {
299
+ // file provided
300
+ return item.file(function (file) {
301
+ file.relativePath = path + file.name
302
+ items.push(file)
303
+ cb()
304
+ })
305
+ } else if (item.isDirectory) {
306
+ // item is already a directory entry, just assign
307
+ entry = item
308
+ } else if (item instanceof File) {
309
+ items.push(item)
310
+ }
311
+ if (typeof item.webkitGetAsEntry === 'function') {
312
+ // get entry from file object
313
+ entry = item.webkitGetAsEntry()
314
+ }
315
+ if (entry && entry.isDirectory) {
316
+ // directory provided, process it
317
+ return processDirectory(entry, path + entry.name + '/', items, cb)
318
+ }
319
+ if (typeof item.getAsFile === 'function') {
320
+ // item represents a File object, convert it
321
+ item = item.getAsFile()
322
+ if (item instanceof File) {
323
+ item.relativePath = path + item.name
324
+ items.push(item)
325
+ }
326
+ }
327
+ cb() // indicate processing is done
328
+ }
329
+
330
+ /**
331
+ * cps-style list iteration.
332
+ * invokes all functions in list and waits for their callback to be
333
+ * triggered.
334
+ * @param {Function[]} items list of functions expecting callback parameter
335
+ * @param {Function} cb callback to trigger after the last callback has been invoked
336
+ */
337
+ function processCallbacks (items, cb) {
338
+ if (!items || items.length === 0) {
339
+ // empty or no list, invoke callback
340
+ return cb()
341
+ }
342
+ // invoke current function, pass the next part as continuation
343
+ items[0](function () {
344
+ processCallbacks(items.slice(1), cb)
345
+ })
346
+ }
347
+
348
+ /**
349
+ * recursively traverse directory and collect files to upload
350
+ * @param {Object} directory directory to process
351
+ * @param {string} path current path
352
+ * @param {File[]} items target list of items
353
+ * @param {Function} cb callback invoked after traversing directory
354
+ */
355
+ function processDirectory (directory, path, items, cb) {
356
+ const dirReader = directory.createReader()
357
+ let allEntries = []
358
+
359
+ function readEntries () {
360
+ dirReader.readEntries(function (entries) {
361
+ if (entries.length) {
362
+ allEntries = allEntries.concat(entries)
363
+ return readEntries()
364
+ }
365
+
366
+ // process all conversion callbacks, finally invoke own one
367
+ processCallbacks(
368
+ allEntries.map(function (entry) {
369
+ // bind all properties except for callback
370
+ return processItem.bind(null, entry, path, items)
371
+ }),
372
+ cb
373
+ )
374
+ })
375
+ }
376
+
377
+ readEntries()
378
+ }
379
+
380
+ /**
381
+ * process items to extract files to be uploaded
382
+ * @param {File[]} items items to process
383
+ * @param {Event} event event that led to upload
384
+ */
385
+ function loadFiles (items, event) {
386
+ if (!items.length) {
387
+ return // nothing to do
388
+ }
389
+ $.fire('beforeAdd')
390
+ const files = []
391
+ processCallbacks(
392
+ Array.prototype.map.call(items, function (item) {
393
+ // bind all properties except for callback
394
+ let entry = item
395
+ if (typeof item.webkitGetAsEntry === 'function') {
396
+ entry = item.webkitGetAsEntry()
397
+ }
398
+ return processItem.bind(null, entry, '', files)
399
+ }),
400
+ function () {
401
+ if (files.length) {
402
+ // at least one file found
403
+ appendFilesFromFileList(files, event)
404
+ }
405
+ }
406
+ )
407
+ }
408
+
409
+ var appendFilesFromFileList = function (fileList, event) {
410
+ // check for uploading too many files
411
+ let errorCount = 0
412
+ const o = $.getOpt([
413
+ 'maxFiles',
414
+ 'minFileSize',
415
+ 'maxFileSize',
416
+ 'maxFilesErrorCallback',
417
+ 'minFileSizeErrorCallback',
418
+ 'maxFileSizeErrorCallback',
419
+ 'fileType',
420
+ 'fileTypeErrorCallback'
421
+ ])
422
+ if (
423
+ typeof o.maxFiles !== 'undefined' &&
424
+ o.maxFiles < fileList.length + $.files.length
425
+ ) {
426
+ // if single-file upload, file is already added, and trying to add 1 new file, simply replace the already-added file
427
+ if (o.maxFiles === 1 && $.files.length === 1 && fileList.length === 1) {
428
+ $.removeFile($.files[0])
429
+ } else {
430
+ o.maxFilesErrorCallback(fileList, errorCount++)
431
+ return false
432
+ }
433
+ }
434
+ const files = []
435
+ const filesSkipped = []
436
+ let remaining = fileList.length
437
+ const decreaseReamining = function () {
438
+ if (!--remaining) {
439
+ // all files processed, trigger event
440
+ if (!files.length && !filesSkipped.length) {
441
+ // no succeeded files, just skip
442
+ return
443
+ }
444
+ window.setTimeout(function () {
445
+ $.fire('filesAdded', files, filesSkipped)
446
+ }, 0)
447
+ }
448
+ }
449
+ $h.each(fileList, function (file) {
450
+ const fileName = file.name
451
+ const fileType = file.type // e.g video/mp4
452
+ if (o.fileType.length > 0) {
453
+ let fileTypeFound = false
454
+ for (const index in o.fileType) {
455
+ // For good behaviour we do some inital sanitizing. Remove spaces and lowercase all
456
+ o.fileType[index] = o.fileType[index].replace(/\s/g, '').toLowerCase()
457
+
458
+ // Allowing for both [extension, .extension, mime/type, mime/*]
459
+ const extension =
460
+ (o.fileType[index].match(/^[^.][^/]+$/) ? '.' : '') + o.fileType[index]
461
+
462
+ if (
463
+ fileName.substr(-1 * extension.length).toLowerCase() === extension ||
464
+ // If MIME type, check for wildcard or if extension matches the files tiletype
465
+ (extension.indexOf('/') !== -1 &&
466
+ ((extension.indexOf('*') !== -1 &&
467
+ fileType.substr(0, extension.indexOf('*')) ===
468
+ extension.substr(0, extension.indexOf('*'))) ||
469
+ fileType === extension))
470
+ ) {
471
+ fileTypeFound = true
472
+ break
473
+ }
474
+ }
475
+ if (!fileTypeFound) {
476
+ o.fileTypeErrorCallback(file, errorCount++)
477
+ return true
478
+ }
479
+ }
480
+
481
+ if (typeof o.minFileSize !== 'undefined' && file.size < o.minFileSize) {
482
+ o.minFileSizeErrorCallback(file, errorCount++)
483
+ return true
484
+ }
485
+ if (typeof o.maxFileSize !== 'undefined' && file.size > o.maxFileSize) {
486
+ o.maxFileSizeErrorCallback(file, errorCount++)
487
+ return true
488
+ }
489
+
490
+ function addFile (uniqueIdentifier) {
491
+ if (!$.getFromUniqueIdentifier(uniqueIdentifier)) {
492
+ (function () {
493
+ file.uniqueIdentifier = uniqueIdentifier
494
+ const f = new ResumableFile($, file, uniqueIdentifier)
495
+ $.files.push(f)
496
+ files.push(f)
497
+ f.container = typeof event !== 'undefined' ? event.srcElement : null
498
+ window.setTimeout(function () {
499
+ $.fire('fileAdded', f, event)
500
+ }, 0)
501
+ })()
502
+ } else {
503
+ filesSkipped.push(file)
504
+ }
505
+ decreaseReamining()
506
+ }
507
+ // directories have size == 0
508
+ const uniqueIdentifier = $h.generateUniqueIdentifier(file, event)
509
+ if (uniqueIdentifier && typeof uniqueIdentifier.then === 'function') {
510
+ // Promise or Promise-like object provided as unique identifier
511
+ uniqueIdentifier.then(
512
+ function (uniqueIdentifier) {
513
+ // unique identifier generation succeeded
514
+ addFile(uniqueIdentifier)
515
+ },
516
+ function () {
517
+ // unique identifier generation failed
518
+ // skip further processing, only decrease file count
519
+ decreaseReamining()
520
+ }
521
+ )
522
+ } else {
523
+ // non-Promise provided as unique identifier, process synchronously
524
+ addFile(uniqueIdentifier)
525
+ }
526
+ })
527
+ }
528
+
529
+ // INTERNAL OBJECT TYPES
530
+ function ResumableFile (resumableObj, file, uniqueIdentifier) {
531
+ const $ = this
532
+ $.opts = {}
533
+ $.getOpt = resumableObj.getOpt
534
+ $._prevProgress = 0
535
+ $.resumableObj = resumableObj
536
+ $.file = file
537
+ $.fileName = file.fileName || file.name // Some confusion in different versions of Firefox
538
+ $.size = file.size
539
+ $.relativePath = file.relativePath || file.webkitRelativePath || $.fileName
540
+ $.uniqueIdentifier = uniqueIdentifier
541
+ $._pause = false
542
+ $.container = ''
543
+ $.preprocessState = 0 // 0 = unprocessed, 1 = processing, 2 = finished
544
+ let _error = uniqueIdentifier !== undefined
545
+
546
+ // Callback when something happens within the chunk
547
+ const chunkEvent = function (event, message) {
548
+ // event can be 'progress', 'success', 'error' or 'retry'
549
+ switch (event) {
550
+ case 'progress':
551
+ $.resumableObj.fire('fileProgress', $, message)
552
+ break
553
+ case 'error':
554
+ $.abort()
555
+ _error = true
556
+ $.chunks = []
557
+ $.resumableObj.fire('fileError', $, message)
558
+ break
559
+ case 'success':
560
+ if (_error) return
561
+ $.resumableObj.fire('fileProgress', $, message) // it's at least progress
562
+ if ($.isComplete()) {
563
+ $.resumableObj.fire('fileSuccess', $, message)
564
+ }
565
+ break
566
+ case 'retry':
567
+ $.resumableObj.fire('fileRetry', $)
568
+ break
569
+ }
570
+ }
571
+
572
+ // Main code to set up a file object with chunks,
573
+ // packaged to be able to handle retries if needed.
574
+ $.chunks = []
575
+ $.abort = function () {
576
+ // Stop current uploads
577
+ let abortCount = 0
578
+ $h.each($.chunks, function (c) {
579
+ if (c.status() == 'uploading') {
580
+ c.abort()
581
+ abortCount++
582
+ }
583
+ })
584
+ if (abortCount > 0) $.resumableObj.fire('fileProgress', $)
585
+ }
586
+ $.cancel = function () {
587
+ // Reset this file to be void
588
+ const _chunks = $.chunks
589
+ $.chunks = []
590
+ // Stop current uploads
591
+ $h.each(_chunks, function (c) {
592
+ if (c.status() == 'uploading') {
593
+ c.abort()
594
+ $.resumableObj.uploadNextChunk()
595
+ }
596
+ })
597
+ $.resumableObj.removeFile($)
598
+ $.resumableObj.fire('fileProgress', $)
599
+ }
600
+ $.retry = function () {
601
+ $.bootstrap()
602
+ let firedRetry = false
603
+ $.resumableObj.on('chunkingComplete', function () {
604
+ if (!firedRetry) $.resumableObj.upload()
605
+ firedRetry = true
606
+ })
607
+ }
608
+ $.bootstrap = function () {
609
+ $.abort()
610
+ _error = false
611
+ // Rebuild stack of chunks from file
612
+ $.chunks = []
613
+ $._prevProgress = 0
614
+ const round = $.getOpt('forceChunkSize') ? Math.ceil : Math.floor
615
+ const maxOffset = Math.max(round($.file.size / $.getOpt('chunkSize')), 1)
616
+ for (let offset = 0; offset < maxOffset; offset++) {
617
+ (function (offset) {
618
+ window.setTimeout(function () {
619
+ $.chunks.push(
620
+ new ResumableChunk($.resumableObj, $, offset, chunkEvent)
621
+ )
622
+ $.resumableObj.fire('chunkingProgress', $, offset / maxOffset)
623
+ }, 0)
624
+ })(offset)
625
+ }
626
+ window.setTimeout(function () {
627
+ $.resumableObj.fire('chunkingComplete', $)
628
+ }, 0)
629
+ }
630
+ $.progress = function () {
631
+ if (_error) return 1
632
+ // Sum up progress across everything
633
+ let ret = 0
634
+ let error = false
635
+ $h.each($.chunks, function (c) {
636
+ if (c.status() == 'error') error = true
637
+ ret += c.progress(true) // get chunk progress relative to entire file
638
+ })
639
+ ret = error ? 1 : ret > 0.99999 ? 1 : ret
640
+ ret = Math.max($._prevProgress, ret) // We don't want to lose percentages when an upload is paused
641
+ $._prevProgress = ret
642
+ return ret
643
+ }
644
+ $.isUploading = function () {
645
+ let uploading = false
646
+ $h.each($.chunks, function (chunk) {
647
+ if (chunk.status() == 'uploading') {
648
+ uploading = true
649
+ return false
650
+ }
651
+ })
652
+ return uploading
653
+ }
654
+ $.isComplete = function () {
655
+ let outstanding = false
656
+ if ($.preprocessState === 1) {
657
+ return false
658
+ }
659
+ $h.each($.chunks, function (chunk) {
660
+ const status = chunk.status()
661
+ if (
662
+ status == 'pending' ||
663
+ status == 'uploading' ||
664
+ chunk.preprocessState === 1
665
+ ) {
666
+ outstanding = true
667
+ return false
668
+ }
669
+ })
670
+ return !outstanding
671
+ }
672
+ $.pause = function (pause) {
673
+ if (typeof pause === 'undefined') {
674
+ $._pause = !$._pause
675
+ } else {
676
+ $._pause = pause
677
+ }
678
+ }
679
+ $.isPaused = function () {
680
+ return $._pause
681
+ }
682
+ $.preprocessFinished = function () {
683
+ $.preprocessState = 2
684
+ $.upload()
685
+ }
686
+ $.upload = function () {
687
+ let found = false
688
+ if ($.isPaused() === false) {
689
+ const preprocess = $.getOpt('preprocessFile')
690
+ if (typeof preprocess === 'function') {
691
+ switch ($.preprocessState) {
692
+ case 0:
693
+ $.preprocessState = 1
694
+ preprocess($)
695
+ return true
696
+ case 1:
697
+ return true
698
+ case 2:
699
+ break
700
+ }
701
+ }
702
+ $h.each($.chunks, function (chunk) {
703
+ if (chunk.status() == 'pending' && chunk.preprocessState !== 1) {
704
+ chunk.send()
705
+ found = true
706
+ return false
707
+ }
708
+ })
709
+ }
710
+ return found
711
+ }
712
+ $.markChunksCompleted = function (chunkNumber) {
713
+ if (!$.chunks || $.chunks.length <= chunkNumber) {
714
+ return
715
+ }
716
+ for (let num = 0; num < chunkNumber; num++) {
717
+ $.chunks[num].markComplete = true
718
+ }
719
+ }
720
+
721
+ // Bootstrap and return
722
+ $.resumableObj.fire('chunkingStart', $)
723
+ $.bootstrap()
724
+ return this
725
+ }
726
+
727
+ function ResumableChunk (resumableObj, fileObj, offset, callback) {
728
+ const $ = this
729
+ $.opts = {}
730
+ $.getOpt = resumableObj.getOpt
731
+ $.resumableObj = resumableObj
732
+ $.fileObj = fileObj
733
+ $.fileObjSize = fileObj.size
734
+ $.fileObjType = fileObj.file.type
735
+ $.offset = offset
736
+ $.callback = callback
737
+ $.lastProgressCallback = new Date()
738
+ $.tested = false
739
+ $.retries = 0
740
+ $.pendingRetry = false
741
+ $.preprocessState = 0 // 0 = unprocessed, 1 = processing, 2 = finished
742
+ $.markComplete = false
743
+
744
+ // Computed properties
745
+ const chunkSize = $.getOpt('chunkSize')
746
+ $.loaded = 0
747
+ $.startByte = $.offset * chunkSize
748
+ $.endByte = Math.min($.fileObjSize, ($.offset + 1) * chunkSize)
749
+ if ($.fileObjSize - $.endByte < chunkSize && !$.getOpt('forceChunkSize')) {
750
+ // The last chunk will be bigger than the chunk size, but less than 2*chunkSize
751
+ $.endByte = $.fileObjSize
752
+ }
753
+ $.xhr = null
754
+
755
+ // test() makes a GET request without any data to see if the chunk has already been uploaded in a previous session
756
+ $.test = function () {
757
+ // Set up request and listen for event
758
+ $.xhr = new XMLHttpRequest()
759
+
760
+ const testHandler = function (e) {
761
+ $.tested = true
762
+ const status = $.status()
763
+ if (status == 'success') {
764
+ $.callback(status, $.message())
765
+ $.resumableObj.uploadNextChunk()
766
+ } else {
767
+ $.send()
768
+ }
769
+ }
770
+ $.xhr.addEventListener('load', testHandler, false)
771
+ $.xhr.addEventListener('error', testHandler, false)
772
+ $.xhr.addEventListener('timeout', testHandler, false)
773
+
774
+ // Add data from the query options
775
+ let params = []
776
+ const parameterNamespace = $.getOpt('parameterNamespace')
777
+ let customQuery = $.getOpt('query')
778
+ if (typeof customQuery === 'function') customQuery = customQuery($.fileObj, $)
779
+ $h.each(customQuery, function (k, v) {
780
+ params.push(
781
+ [encodeURIComponent(parameterNamespace + k), encodeURIComponent(v)].join(
782
+ '='
783
+ )
784
+ )
785
+ })
786
+ // Add extra data to identify chunk
787
+ params = params.concat(
788
+ [
789
+ // define key/value pairs for additional parameters
790
+ ['chunkNumberParameterName', $.offset + 1],
791
+ ['chunkSizeParameterName', $.getOpt('chunkSize')],
792
+ ['currentChunkSizeParameterName', $.endByte - $.startByte],
793
+ ['totalSizeParameterName', $.fileObjSize],
794
+ ['typeParameterName', $.fileObjType],
795
+ ['identifierParameterName', $.fileObj.uniqueIdentifier],
796
+ ['fileNameParameterName', $.fileObj.fileName],
797
+ ['relativePathParameterName', $.fileObj.relativePath],
798
+ ['totalChunksParameterName', $.fileObj.chunks.length]
799
+ ]
800
+ .filter(function (pair) {
801
+ // include items that resolve to truthy values
802
+ // i.e. exclude false, null, undefined and empty strings
803
+ return $.getOpt(pair[0])
804
+ })
805
+ .map(function (pair) {
806
+ // map each key/value pair to its final form
807
+ return [
808
+ parameterNamespace + $.getOpt(pair[0]),
809
+ encodeURIComponent(pair[1])
810
+ ].join('=')
811
+ })
812
+ )
813
+ // Append the relevant chunk and send it
814
+ $.xhr.open($.getOpt('testMethod'), $h.getTarget('test', params))
815
+ $.xhr.timeout = $.getOpt('xhrTimeout')
816
+ $.xhr.withCredentials = $.getOpt('withCredentials')
817
+ // Add data from header options
818
+ let customHeaders = $.getOpt('headers')
819
+ if (typeof customHeaders === 'function') {
820
+ customHeaders = customHeaders($.fileObj, $)
821
+ }
822
+ $h.each(customHeaders, function (k, v) {
823
+ $.xhr.setRequestHeader(k, v)
824
+ })
825
+ $.xhr.send(null)
826
+ }
827
+
828
+ $.preprocessFinished = function () {
829
+ $.preprocessState = 2
830
+ $.send()
831
+ }
832
+
833
+ // send() uploads the actual data in a POST call
834
+ $.send = function () {
835
+ const preprocess = $.getOpt('preprocess')
836
+ if (typeof preprocess === 'function') {
837
+ switch ($.preprocessState) {
838
+ case 0:
839
+ $.preprocessState = 1
840
+ preprocess($)
841
+ return
842
+ case 1:
843
+ return
844
+ case 2:
845
+ break
846
+ }
847
+ }
848
+ if ($.getOpt('testChunks') && !$.tested) {
849
+ $.test()
850
+ return
851
+ }
852
+
853
+ // Set up request and listen for event
854
+ $.xhr = new XMLHttpRequest()
855
+
856
+ // Progress
857
+ $.xhr.upload.addEventListener(
858
+ 'progress',
859
+ function (e) {
860
+ if (
861
+ new Date() - $.lastProgressCallback >
862
+ $.getOpt('throttleProgressCallbacks') * 1000
863
+ ) {
864
+ $.callback('progress')
865
+ $.lastProgressCallback = new Date()
866
+ }
867
+ $.loaded = e.loaded || 0
868
+ },
869
+ false
870
+ )
871
+ $.loaded = 0
872
+ $.pendingRetry = false
873
+ $.callback('progress')
874
+
875
+ // Done (either done, failed or retry)
876
+ const doneHandler = function (e) {
877
+ const status = $.status()
878
+ if (status == 'success' || status == 'error') {
879
+ $.callback(status, $.message())
880
+ $.resumableObj.uploadNextChunk()
881
+ } else {
882
+ $.callback('retry', $.message())
883
+ $.abort()
884
+ $.retries++
885
+ const retryInterval = $.getOpt('chunkRetryInterval')
886
+ if (retryInterval !== undefined) {
887
+ $.pendingRetry = true
888
+ setTimeout($.send, retryInterval)
889
+ } else {
890
+ $.send()
891
+ }
892
+ }
893
+ }
894
+ $.xhr.addEventListener('load', doneHandler, false)
895
+ $.xhr.addEventListener('error', doneHandler, false)
896
+ $.xhr.addEventListener('timeout', doneHandler, false)
897
+
898
+ // Set up the basic query data from Resumable
899
+ const query = [
900
+ ['chunkNumberParameterName', $.offset + 1],
901
+ ['chunkSizeParameterName', $.getOpt('chunkSize')],
902
+ ['currentChunkSizeParameterName', $.endByte - $.startByte],
903
+ ['totalSizeParameterName', $.fileObjSize],
904
+ ['typeParameterName', $.fileObjType],
905
+ ['identifierParameterName', $.fileObj.uniqueIdentifier],
906
+ ['fileNameParameterName', $.fileObj.fileName],
907
+ ['relativePathParameterName', $.fileObj.relativePath],
908
+ ['totalChunksParameterName', $.fileObj.chunks.length]
909
+ ]
910
+ .filter(function (pair) {
911
+ // include items that resolve to truthy values
912
+ // i.e. exclude false, null, undefined and empty strings
913
+ return $.getOpt(pair[0])
914
+ })
915
+ .reduce(function (query, pair) {
916
+ // assign query key/value
917
+ query[$.getOpt(pair[0])] = pair[1]
918
+ return query
919
+ }, {})
920
+ // Mix in custom data
921
+ let customQuery = $.getOpt('query')
922
+ if (typeof customQuery === 'function') customQuery = customQuery($.fileObj, $)
923
+ $h.each(customQuery, function (k, v) {
924
+ query[k] = v
925
+ })
926
+
927
+ const func = $.fileObj.file.slice
928
+ ? 'slice'
929
+ : $.fileObj.file.mozSlice
930
+ ? 'mozSlice'
931
+ : $.fileObj.file.webkitSlice
932
+ ? 'webkitSlice'
933
+ : 'slice'
934
+ const bytes = $.fileObj.file[func](
935
+ $.startByte,
936
+ $.endByte,
937
+ $.getOpt('setChunkTypeFromFile') ? $.fileObj.file.type : ''
938
+ )
939
+ let data = null
940
+ const params = []
941
+
942
+ const parameterNamespace = $.getOpt('parameterNamespace')
943
+ if ($.getOpt('method') === 'octet') {
944
+ // Add data from the query options
945
+ data = bytes
946
+ $h.each(query, function (k, v) {
947
+ params.push(
948
+ [
949
+ encodeURIComponent(parameterNamespace + k),
950
+ encodeURIComponent(v)
951
+ ].join('=')
952
+ )
953
+ })
954
+ } else {
955
+ // Add data from the query options
956
+ data = new FormData()
957
+ $h.each(query, function (k, v) {
958
+ data.append(parameterNamespace + k, v)
959
+ params.push(
960
+ [
961
+ encodeURIComponent(parameterNamespace + k),
962
+ encodeURIComponent(v)
963
+ ].join('=')
964
+ )
965
+ })
966
+ if ($.getOpt('chunkFormat') == 'blob') {
967
+ data.append(
968
+ parameterNamespace + $.getOpt('fileParameterName'),
969
+ bytes,
970
+ $.fileObj.fileName
971
+ )
972
+ } else if ($.getOpt('chunkFormat') == 'base64') {
973
+ const fr = new FileReader()
974
+ fr.onload = function (e) {
975
+ data.append(
976
+ parameterNamespace + $.getOpt('fileParameterName'),
977
+ fr.result
978
+ )
979
+ $.xhr.send(data)
980
+ }
981
+ fr.readAsDataURL(bytes)
982
+ }
983
+ }
984
+
985
+ const target = $h.getTarget('upload', params)
986
+ const method = $.getOpt('uploadMethod')
987
+
988
+ $.xhr.open(method, target)
989
+ if ($.getOpt('method') === 'octet') {
990
+ $.xhr.setRequestHeader('Content-Type', 'application/octet-stream')
991
+ }
992
+ $.xhr.timeout = $.getOpt('xhrTimeout')
993
+ $.xhr.withCredentials = $.getOpt('withCredentials')
994
+ // Add data from header options
995
+ let customHeaders = $.getOpt('headers')
996
+ if (typeof customHeaders === 'function') {
997
+ customHeaders = customHeaders($.fileObj, $)
998
+ }
999
+
1000
+ $h.each(customHeaders, function (k, v) {
1001
+ $.xhr.setRequestHeader(k, v)
1002
+ })
1003
+
1004
+ if ($.getOpt('chunkFormat') == 'blob') {
1005
+ if (data.on) {
1006
+ const chunks = []
1007
+ data.on('data', (chunk) => {
1008
+ chunks.push(chunk)
1009
+ })
1010
+ data.on('end', () => {
1011
+ $.xhr.send(Buffer.concat(chunks))
1012
+ })
1013
+ data.on('error', (error) => {
1014
+ doneHandler()
1015
+ })
1016
+ } else $.xhr.send(data)
1017
+ }
1018
+ }
1019
+ $.abort = function () {
1020
+ // Abort and reset
1021
+ if ($.xhr) $.xhr.abort()
1022
+ $.xhr = null
1023
+ }
1024
+ $.status = function () {
1025
+ // Returns: 'pending', 'uploading', 'success', 'error'
1026
+ if ($.pendingRetry) {
1027
+ // if pending retry then that's effectively the same as actively uploading,
1028
+ // there might just be a slight delay before the retry starts
1029
+ return 'uploading'
1030
+ } else if ($.markComplete) {
1031
+ return 'success'
1032
+ } else if (!$.xhr) {
1033
+ return 'pending'
1034
+ } else if ($.xhr.readyState < 4) {
1035
+ // Status is really 'OPENED', 'HEADERS_RECEIVED' or 'LOADING' - meaning that stuff is happening
1036
+ return 'uploading'
1037
+ } else {
1038
+ if ($.xhr.status == 200 || $.xhr.status == 201) {
1039
+ // HTTP 200, 201 (created)
1040
+ return 'success'
1041
+ } else if (
1042
+ $h.contains($.getOpt('permanentErrors'), $.xhr.status) ||
1043
+ $.retries >= $.getOpt('maxChunkRetries')
1044
+ ) {
1045
+ // HTTP 400, 404, 409, 415, 500, 501 (permanent error)
1046
+ return 'error'
1047
+ } else {
1048
+ // this should never happen, but we'll reset and queue a retry
1049
+ // a likely case for this would be 503 service unavailable
1050
+ $.abort()
1051
+ return 'pending'
1052
+ }
1053
+ }
1054
+ }
1055
+ $.message = function () {
1056
+ return $.xhr ? $.xhr.responseText : ''
1057
+ }
1058
+ $.progress = function (relative) {
1059
+ if (typeof relative === 'undefined') relative = false
1060
+ let factor = relative ? ($.endByte - $.startByte) / $.fileObjSize : 1
1061
+ if ($.pendingRetry) return 0
1062
+ if ((!$.xhr || !$.xhr.status) && !$.markComplete) factor *= 0.95
1063
+ const s = $.status()
1064
+ switch (s) {
1065
+ case 'success':
1066
+ case 'error':
1067
+ return 1 * factor
1068
+ case 'pending':
1069
+ return 0 * factor
1070
+ default:
1071
+ return ($.loaded / ($.endByte - $.startByte)) * factor
1072
+ }
1073
+ }
1074
+ return this
1075
+ }
1076
+
1077
+ // QUEUE
1078
+ $.uploadNextChunk = function () {
1079
+ let found = false
1080
+
1081
+ // In some cases (such as videos) it's really handy to upload the first
1082
+ // and last chunk of a file quickly; this let's the server check the file's
1083
+ // metadata and determine if there's even a point in continuing.
1084
+ if ($.getOpt('prioritizeFirstAndLastChunk')) {
1085
+ $h.each($.files, function (file) {
1086
+ if (
1087
+ file.chunks.length &&
1088
+ file.chunks[0].status() == 'pending' &&
1089
+ file.chunks[0].preprocessState === 0
1090
+ ) {
1091
+ file.chunks[0].send()
1092
+ found = true
1093
+ return false
1094
+ }
1095
+ if (
1096
+ file.chunks.length > 1 &&
1097
+ file.chunks[file.chunks.length - 1].status() == 'pending' &&
1098
+ file.chunks[file.chunks.length - 1].preprocessState === 0
1099
+ ) {
1100
+ file.chunks[file.chunks.length - 1].send()
1101
+ found = true
1102
+ return false
1103
+ }
1104
+ })
1105
+ if (found) return true
1106
+ }
1107
+
1108
+ // Now, simply look for the next, best thing to upload
1109
+ $h.each($.files, function (file) {
1110
+ found = file.upload()
1111
+ if (found) return false
1112
+ })
1113
+ if (found) return true
1114
+
1115
+ // The are no more outstanding chunks to upload, check is everything is done
1116
+ let outstanding = false
1117
+ $h.each($.files, function (file) {
1118
+ if (!file.isComplete()) {
1119
+ outstanding = true
1120
+ return false
1121
+ }
1122
+ })
1123
+ if (!outstanding) {
1124
+ // All chunks have been uploaded, complete
1125
+ $.fire('complete')
1126
+ }
1127
+ return false
1128
+ }
1129
+
1130
+ // PUBLIC METHODS FOR RESUMABLE.JS
1131
+ $.assignBrowse = function (domNodes, isDirectory) {
1132
+ if (typeof domNodes.length === 'undefined') domNodes = [domNodes]
1133
+ $h.each(domNodes, function (domNode) {
1134
+ let input
1135
+ if (domNode.tagName === 'INPUT' && domNode.type === 'file') {
1136
+ input = domNode
1137
+ } else {
1138
+ input = document.createElement('input')
1139
+ input.setAttribute('type', 'file')
1140
+ input.style.display = 'none'
1141
+ domNode.addEventListener(
1142
+ 'click',
1143
+ function () {
1144
+ input.style.opacity = 0
1145
+ input.style.display = 'block'
1146
+ input.focus()
1147
+ input.click()
1148
+ input.style.display = 'none'
1149
+ },
1150
+ false
1151
+ )
1152
+ domNode.appendChild(input)
1153
+ }
1154
+ const maxFiles = $.getOpt('maxFiles')
1155
+ if (typeof maxFiles === 'undefined' || maxFiles != 1) {
1156
+ input.setAttribute('multiple', 'multiple')
1157
+ } else {
1158
+ input.removeAttribute('multiple')
1159
+ }
1160
+ if (isDirectory) {
1161
+ input.setAttribute('webkitdirectory', 'webkitdirectory')
1162
+ } else {
1163
+ input.removeAttribute('webkitdirectory')
1164
+ }
1165
+ const fileTypes = $.getOpt('fileType')
1166
+ if (typeof fileTypes !== 'undefined' && fileTypes.length >= 1) {
1167
+ input.setAttribute(
1168
+ 'accept',
1169
+ fileTypes
1170
+ .map(function (e) {
1171
+ e = e.replace(/\s/g, '').toLowerCase()
1172
+ if (e.match(/^[^.][^/]+$/)) {
1173
+ e = '.' + e
1174
+ }
1175
+ return e
1176
+ })
1177
+ .join(',')
1178
+ )
1179
+ } else {
1180
+ input.removeAttribute('accept')
1181
+ }
1182
+ // When new files are added, simply append them to the overall list
1183
+ input.addEventListener(
1184
+ 'change',
1185
+ function (e) {
1186
+ appendFilesFromFileList(e.target.files, e)
1187
+ const clearInput = $.getOpt('clearInput')
1188
+ if (clearInput) {
1189
+ e.target.value = ''
1190
+ }
1191
+ },
1192
+ false
1193
+ )
1194
+ })
1195
+ }
1196
+ $.assignDrop = function (domNodes) {
1197
+ if (typeof domNodes.length === 'undefined') domNodes = [domNodes]
1198
+
1199
+ $h.each(domNodes, function (domNode) {
1200
+ domNode.addEventListener('dragover', onDragOverEnter, false)
1201
+ domNode.addEventListener('dragenter', onDragOverEnter, false)
1202
+ domNode.addEventListener('dragleave', onDragLeave, false)
1203
+ domNode.addEventListener('drop', onDrop, false)
1204
+ })
1205
+ }
1206
+ $.unAssignDrop = function (domNodes) {
1207
+ if (typeof domNodes.length === 'undefined') domNodes = [domNodes]
1208
+
1209
+ $h.each(domNodes, function (domNode) {
1210
+ domNode.removeEventListener('dragover', onDragOverEnter)
1211
+ domNode.removeEventListener('dragenter', onDragOverEnter)
1212
+ domNode.removeEventListener('dragleave', onDragLeave)
1213
+ domNode.removeEventListener('drop', onDrop)
1214
+ })
1215
+ }
1216
+ $.isUploading = function () {
1217
+ let uploading = false
1218
+ $h.each($.files, function (file) {
1219
+ if (file.isUploading()) {
1220
+ uploading = true
1221
+ return false
1222
+ }
1223
+ })
1224
+ return uploading
1225
+ }
1226
+ $.upload = function () {
1227
+ // Make sure we don't start too many uploads at once
1228
+ if ($.isUploading()) return
1229
+ // Kick off the queue
1230
+ $.fire('uploadStart')
1231
+ for (let num = 1; num <= $.getOpt('simultaneousUploads'); num++) {
1232
+ $.uploadNextChunk()
1233
+ }
1234
+ }
1235
+ $.pause = function () {
1236
+ // Resume all chunks currently being uploaded
1237
+ $h.each($.files, function (file) {
1238
+ file.abort()
1239
+ })
1240
+ $.fire('pause')
1241
+ }
1242
+ $.cancel = function () {
1243
+ $.fire('beforeCancel')
1244
+ for (let i = $.files.length - 1; i >= 0; i--) {
1245
+ $.files[i].cancel()
1246
+ }
1247
+ $.fire('cancel')
1248
+ }
1249
+ $.progress = function () {
1250
+ let totalDone = 0
1251
+ let totalSize = 0
1252
+ // Resume all chunks currently being uploaded
1253
+ $h.each($.files, function (file) {
1254
+ totalDone += file.progress() * file.size
1255
+ totalSize += file.size
1256
+ })
1257
+ return totalSize > 0 ? totalDone / totalSize : 0
1258
+ }
1259
+ $.addFile = function (file, event) {
1260
+ appendFilesFromFileList([file], event)
1261
+ }
1262
+ $.addFiles = function (files, event) {
1263
+ appendFilesFromFileList(files, event)
1264
+ }
1265
+ $.removeFile = function (file) {
1266
+ for (let i = $.files.length - 1; i >= 0; i--) {
1267
+ if ($.files[i] === file) {
1268
+ $.files.splice(i, 1)
1269
+ }
1270
+ }
1271
+ }
1272
+ $.getFromUniqueIdentifier = function (uniqueIdentifier) {
1273
+ let ret = false
1274
+ $h.each($.files, function (f) {
1275
+ if (f.uniqueIdentifier == uniqueIdentifier) ret = f
1276
+ })
1277
+ return ret
1278
+ }
1279
+ $.getSize = function () {
1280
+ let totalSize = 0
1281
+ $h.each($.files, function (file) {
1282
+ totalSize += file.size
1283
+ })
1284
+ return totalSize
1285
+ }
1286
+ $.handleDropEvent = function (e) {
1287
+ onDrop(e)
1288
+ }
1289
+ $.handleChangeEvent = function (e) {
1290
+ appendFilesFromFileList(e.target.files, e)
1291
+ e.target.value = ''
1292
+ }
1293
+ $.updateQuery = function (query) {
1294
+ $.opts.query = query
1295
+ }
1296
+
1297
+ return this
1298
+ }
1299
+
1300
+ // Node.js-style export for Node and Component
1301
+ if (typeof module !== 'undefined') {
1302
+ // left here for backwards compatibility
1303
+ module.exports = Resumable
1304
+ module.exports.Resumable = Resumable
1305
+ } else if (typeof define === 'function' && define.amd) {
1306
+ // AMD/requirejs: Define the module
1307
+ define(function () {
1308
+ return Resumable
1309
+ })
1310
+ } else {
1311
+ // Browser: Expose to window
1312
+ window.Resumable = Resumable
1313
+ }
1314
+ })()