Browse Source

add babel

ChrisFuck 5 years ago
parent
commit
7e7da0e720
8 changed files with 918 additions and 2 deletions
  1. 6
    0
      .babelrc
  2. 1
    0
      .gitignore
  3. 15
    0
      index.js/contants.js
  4. 190
    0
      index.js/index.js
  5. 52
    0
      index.js/utils.js
  6. 649
    0
      package-lock.json
  7. 3
    0
      package.json
  8. 2
    2
      utils/index.js

+ 6
- 0
.babelrc View File

@@ -0,0 +1,6 @@
1
+{
2
+  "presets": [
3
+    "es2015"
4
+  ],
5
+  "plugins": []
6
+}

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+/node_modules

+ 15
- 0
index.js/contants.js View File

@@ -0,0 +1,15 @@
1
+'use strict';
2
+
3
+Object.defineProperty(exports, "__esModule", {
4
+  value: true
5
+});
6
+var Constants = {
7
+  IMAGE_MULTIPART: '/multipart/upload/',
8
+  VIDEO_MULTIPART: '/upload/',
9
+  IMAGE_TYPE_ERROR: 101,
10
+  VIDOE_TYPE_ERROR: 102,
11
+  UPLOAD_SUCCESS_CODE: 200,
12
+  UPLOAD_FAILED_CODE: 400
13
+};
14
+
15
+exports.Constants = Constants;

+ 190
- 0
index.js/index.js View File

@@ -0,0 +1,190 @@
1
+'use strict';
2
+
3
+Object.defineProperty(exports, "__esModule", {
4
+  value: true
5
+});
6
+exports.default = UploadSdk;
7
+
8
+var _contants = require('./contants');
9
+
10
+var _utils = require('./utils');
11
+
12
+var _utils2 = _interopRequireDefault(_utils);
13
+
14
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+function FileFactory(file) {
17
+  this.offset = 0; //用于断点续传,默认为 0
18
+  this.BYTES_PER_CHUNK = 1024 * 1024;
19
+  this.file = file;
20
+  this.fileSize = file.size;
21
+  this.fileType = file.name.split('.')[1].toLowerCase();
22
+  this.chunkNum = this.BYTES_PER_CHUNK > this.fileSize ? Math.ceil(this.fileSize / this.BYTES_PER_CHUNK) : 1;
23
+  this.chunkSize = this.BYTES_PER_CHUNK > this.fileSize ? this.fileSize : this.BYTES_PER_CHUNK;
24
+}
25
+
26
+FileFactory.prototype.setOffset = function (offset) {
27
+  this.offset = offset;
28
+};
29
+
30
+function UploadSdk(host, origin, token, file) {
31
+
32
+  this.handlers = []; //用于处理出触发事件
33
+  this.host = host.indexOf('http:') > -1 ? 'http:' + host : host;
34
+  this.origin = origin;
35
+  this.token = token;
36
+  this.file = file;
37
+
38
+  this.generateMd5 = function (callback) {
39
+    (0, _utils2.default)(this.file).then(function (result) {
40
+      callback(result);
41
+    });
42
+  };
43
+
44
+  this.imageUploadAction = function () {
45
+    var _this = this;
46
+
47
+    return new Promise(function (resolve, reject) {
48
+      var fileFactory = new FileFactory(_this.file);
49
+      if (!fileFactory.fileType.match('[(jpg)|(png)|(gif)]+$')) {
50
+        reject(_contants.Constants.IMAGE_TYPE_ERROR);
51
+      }
52
+      _this.generateMd5(function (md5) {
53
+        _this.md5 = md5;
54
+        _this.postImage(_this.md5, fileFactory).then(function (res) {
55
+          resolve(res);
56
+        }).catch(function (err) {
57
+          reject(err);
58
+        });
59
+      });
60
+    });
61
+  };
62
+
63
+  this.videoUploadAction = function () {
64
+    var _this2 = this;
65
+
66
+    return new Promise(function (resolve, reject) {
67
+      if (!_this2.file.type.match('[(mp4)|(rmvb)|(flv)|(mpeg)|(avi)]+$')) {
68
+        reject(_contants.Constants.VIDOE_TYPE_ERROR);
69
+      }
70
+      _this2.postVideo().then(function (res) {
71
+        resolve(res);
72
+      }).catch(function (err) {
73
+        reject(err);
74
+      });
75
+    });
76
+  };
77
+
78
+  this.postVideo = function () {
79
+    var _this3 = this;
80
+
81
+    var self = this;
82
+    return new Promise(function (resolve, reject) {
83
+      var xhr = new XMLHttpRequest();
84
+      xhr.open('POST', _this3.host + _contants.Constants.VIDEO_MULTIPART + _this3.origin, true);
85
+      xhr.withCredentials = true;
86
+      xhr.setRequestHeader('Authorization', 'Bearer ' + _this3.token);
87
+      xhr.setRequestHeader('Content-type', 'application/json');
88
+      xhr.upload.addEventListener("progress", function updateProgress(oEvent) {
89
+        if (oEvent.lengthComputable) {
90
+          var percentComplete = oEvent.loaded / oEvent.total * 100;
91
+          self.emitUpdateProgress(percentComplete);
92
+        }
93
+      }, false);
94
+      var fd = new FormData();
95
+      fd.append('file', _this3.file);
96
+      fd.append('code_rate', 'ld,sd,hd');
97
+      xhr.send(fd);
98
+      xhr.onreadystatechange = function () {
99
+        if (xhr.readyState === 4) {
100
+          var obj = JSON.parse(xhr.responseText);
101
+          if (xhr.status === 304 || xhr.status >= 200 && xhr.status < 300) {
102
+            resolve({
103
+              code: _contants.Constants.UPLOAD_SUCCESS_CODE,
104
+              url: obj.url,
105
+              msg: 'success'
106
+            });
107
+          } else {
108
+            reject({
109
+              code: _contants.Constants.UPLOAD_FAILED_CODE,
110
+              url: '',
111
+              msg: obj.message
112
+            });
113
+          }
114
+        }
115
+      };
116
+    });
117
+  };
118
+
119
+  this.postImage = function (md5, fileFactory) {
120
+    var _this4 = this;
121
+
122
+    var self = this;
123
+    return new Promise(function (resolve, reject) {
124
+      var xhr = new XMLHttpRequest();
125
+      xhr.upload.addEventListener("progress", function updateProgress(oEvent) {
126
+        if (oEvent.lengthComputable) {
127
+          var percentComplete = oEvent.loaded / oEvent.total * 100;
128
+          self.emitUpdateProgress(percentComplete);
129
+        }
130
+      }, false);
131
+      xhr.open('POSt', _this4.host + _contants.Constants.IMAGE_MULTIPART + _this4.origin, true);
132
+      xhr.withCredentials = true;
133
+      xhr.setRequestHeader('Authorization', 'Bearer ' + _this4.token);
134
+      xhr.setRequestHeader('X-Upload-File-Size', fileFactory.fileSize);
135
+      xhr.setRequestHeader('X-Upload-Chunk-Index', 1 + '');
136
+      xhr.setRequestHeader('X-Upload-Chunk-Num', fileFactory.chunkNum);
137
+      xhr.setRequestHeader('X-Upload-Chunk-Size', fileFactory.chunkSize);
138
+      xhr.setRequestHeader('X-Upload-Offset', fileFactory.offset + '');
139
+      xhr.setRequestHeader('X-Upload-File-Md5', md5);
140
+      xhr.setRequestHeader('X-Upload-File-Type', fileFactory.fileType);
141
+      var fd = new FormData();
142
+      fd.append('file', _this4.file);
143
+      xhr.send(fd);
144
+      xhr.onreadystatechange = function () {
145
+        if (xhr.readyState === 4) {
146
+          var obj = JSON.parse(xhr.responseText);
147
+          if (xhr.status === 304 || xhr.status >= 200 && xhr.status < 300) {
148
+
149
+            if (obj.status === 1) {
150
+              resolve({
151
+                code: _contants.Constants.UPLOAD_SUCCESS_CODE,
152
+                url: obj.url,
153
+                msg: 'success'
154
+              });
155
+            } else if (obj.status === 0) {
156
+              fileFactory.setOffset(obj.msg);
157
+              this.getAllResponseHeaders.postImage(md5, fileFactory);
158
+            }
159
+          } else {
160
+            reject({
161
+              code: _contants.Constants.UPLOAD_FAILED_CODE,
162
+              url: '',
163
+              msg: obj.message
164
+            });
165
+          }
166
+        }
167
+      };
168
+    });
169
+  };
170
+}
171
+
172
+UploadSdk.prototype = {
173
+
174
+  onUpdateProgress: function onUpdateProgress(subscriber) {
175
+    var isExist = this.handlers.some(function (item) {
176
+      return item == subscriber;
177
+    });
178
+    if (!isExist) {
179
+      this.handlers.push(subscriber);
180
+    }
181
+    return this;
182
+  },
183
+
184
+  emitUpdateProgress: function emitUpdateProgress(data) {
185
+    this.handlers.forEach(function (fn) {
186
+      fn(data);
187
+    });
188
+    return this;
189
+  }
190
+};

+ 52
- 0
index.js/utils.js View File

@@ -0,0 +1,52 @@
1
+'use strict';
2
+
3
+Object.defineProperty(exports, "__esModule", {
4
+    value: true
5
+});
6
+exports.default = getFilemd5sum;
7
+
8
+var _sparkMd = require('spark-md5');
9
+
10
+var _sparkMd2 = _interopRequireDefault(_sparkMd);
11
+
12
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+function getFilemd5sum(ofile) {
15
+    return new Promise(function (resolve, reject) {
16
+        var file = ofile;
17
+        var tmp_md5 = void 0;
18
+        var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
19
+
20
+        // file = this.files[0],
21
+        chunkSize = 8097152,
22
+            // Read in chunks of 2MB
23
+        chunks = Math.ceil(file.size / chunkSize),
24
+            currentChunk = 0,
25
+            spark = new _sparkMd2.default.ArrayBuffer(),
26
+            fileReader = new FileReader();
27
+
28
+        function loadNext() {
29
+            var start = currentChunk * chunkSize,
30
+                end = start + chunkSize >= file.size ? file.size : start + chunkSize;
31
+            fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
32
+        }
33
+
34
+        fileReader.onload = function (e) {
35
+            spark.append(e.target.result); // Append array buffer
36
+            currentChunk++;
37
+
38
+            if (currentChunk < chunks) {
39
+                loadNext();
40
+            } else {
41
+                tmp_md5 = spark.end();
42
+                resolve(tmp_md5);
43
+            }
44
+        };
45
+
46
+        fileReader.onerror = function () {
47
+            reject('error');
48
+        };
49
+
50
+        loadNext();
51
+    });
52
+}

+ 649
- 0
package-lock.json View File

@@ -9,10 +9,659 @@
9 9
       "resolved": "http://registry.npm.taobao.org/@types/spark-md5/download/@types/spark-md5-3.0.1.tgz",
10 10
       "integrity": "sha1-NRs4OzL6empXm4Nu+Hhik8Sn5zs="
11 11
     },
12
+    "ansi-regex": {
13
+      "version": "2.1.1",
14
+      "resolved": "http://registry.npm.taobao.org/ansi-regex/download/ansi-regex-2.1.1.tgz",
15
+      "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
16
+      "dev": true
17
+    },
18
+    "ansi-styles": {
19
+      "version": "2.2.1",
20
+      "resolved": "http://registry.npm.taobao.org/ansi-styles/download/ansi-styles-2.2.1.tgz",
21
+      "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
22
+      "dev": true
23
+    },
24
+    "babel-code-frame": {
25
+      "version": "6.26.0",
26
+      "resolved": "http://registry.npm.taobao.org/babel-code-frame/download/babel-code-frame-6.26.0.tgz",
27
+      "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=",
28
+      "dev": true,
29
+      "requires": {
30
+        "chalk": "^1.1.3",
31
+        "esutils": "^2.0.2",
32
+        "js-tokens": "^3.0.2"
33
+      }
34
+    },
35
+    "babel-helper-call-delegate": {
36
+      "version": "6.24.1",
37
+      "resolved": "http://registry.npm.taobao.org/babel-helper-call-delegate/download/babel-helper-call-delegate-6.24.1.tgz",
38
+      "integrity": "sha1-7Oaqzdx25Bw0YfiL/Fdb0Nqi340=",
39
+      "dev": true,
40
+      "requires": {
41
+        "babel-helper-hoist-variables": "^6.24.1",
42
+        "babel-runtime": "^6.22.0",
43
+        "babel-traverse": "^6.24.1",
44
+        "babel-types": "^6.24.1"
45
+      }
46
+    },
47
+    "babel-helper-define-map": {
48
+      "version": "6.26.0",
49
+      "resolved": "http://registry.npm.taobao.org/babel-helper-define-map/download/babel-helper-define-map-6.26.0.tgz",
50
+      "integrity": "sha1-pfVtq0GiX5fstJjH66ypgZ+Vvl8=",
51
+      "dev": true,
52
+      "requires": {
53
+        "babel-helper-function-name": "^6.24.1",
54
+        "babel-runtime": "^6.26.0",
55
+        "babel-types": "^6.26.0",
56
+        "lodash": "^4.17.4"
57
+      }
58
+    },
59
+    "babel-helper-function-name": {
60
+      "version": "6.24.1",
61
+      "resolved": "http://registry.npm.taobao.org/babel-helper-function-name/download/babel-helper-function-name-6.24.1.tgz",
62
+      "integrity": "sha1-00dbjAPtmCQqJbSDUasYOZ01gKk=",
63
+      "dev": true,
64
+      "requires": {
65
+        "babel-helper-get-function-arity": "^6.24.1",
66
+        "babel-runtime": "^6.22.0",
67
+        "babel-template": "^6.24.1",
68
+        "babel-traverse": "^6.24.1",
69
+        "babel-types": "^6.24.1"
70
+      }
71
+    },
72
+    "babel-helper-get-function-arity": {
73
+      "version": "6.24.1",
74
+      "resolved": "http://registry.npm.taobao.org/babel-helper-get-function-arity/download/babel-helper-get-function-arity-6.24.1.tgz",
75
+      "integrity": "sha1-j3eCqpNAfEHTqlCQj4mwMbG2hT0=",
76
+      "dev": true,
77
+      "requires": {
78
+        "babel-runtime": "^6.22.0",
79
+        "babel-types": "^6.24.1"
80
+      }
81
+    },
82
+    "babel-helper-hoist-variables": {
83
+      "version": "6.24.1",
84
+      "resolved": "http://registry.npm.taobao.org/babel-helper-hoist-variables/download/babel-helper-hoist-variables-6.24.1.tgz",
85
+      "integrity": "sha1-HssnaJydJVE+rbyZFKc/VAi+enY=",
86
+      "dev": true,
87
+      "requires": {
88
+        "babel-runtime": "^6.22.0",
89
+        "babel-types": "^6.24.1"
90
+      }
91
+    },
92
+    "babel-helper-optimise-call-expression": {
93
+      "version": "6.24.1",
94
+      "resolved": "http://registry.npm.taobao.org/babel-helper-optimise-call-expression/download/babel-helper-optimise-call-expression-6.24.1.tgz",
95
+      "integrity": "sha1-96E0J7qfc/j0+pk8VKl4gtEkQlc=",
96
+      "dev": true,
97
+      "requires": {
98
+        "babel-runtime": "^6.22.0",
99
+        "babel-types": "^6.24.1"
100
+      }
101
+    },
102
+    "babel-helper-regex": {
103
+      "version": "6.26.0",
104
+      "resolved": "http://registry.npm.taobao.org/babel-helper-regex/download/babel-helper-regex-6.26.0.tgz",
105
+      "integrity": "sha1-MlxZ+QL4LyS3T6zu0DY5VPZJXnI=",
106
+      "dev": true,
107
+      "requires": {
108
+        "babel-runtime": "^6.26.0",
109
+        "babel-types": "^6.26.0",
110
+        "lodash": "^4.17.4"
111
+      }
112
+    },
113
+    "babel-helper-replace-supers": {
114
+      "version": "6.24.1",
115
+      "resolved": "http://registry.npm.taobao.org/babel-helper-replace-supers/download/babel-helper-replace-supers-6.24.1.tgz",
116
+      "integrity": "sha1-v22/5Dk40XNpohPKiov3S2qQqxo=",
117
+      "dev": true,
118
+      "requires": {
119
+        "babel-helper-optimise-call-expression": "^6.24.1",
120
+        "babel-messages": "^6.23.0",
121
+        "babel-runtime": "^6.22.0",
122
+        "babel-template": "^6.24.1",
123
+        "babel-traverse": "^6.24.1",
124
+        "babel-types": "^6.24.1"
125
+      }
126
+    },
127
+    "babel-messages": {
128
+      "version": "6.23.0",
129
+      "resolved": "http://registry.npm.taobao.org/babel-messages/download/babel-messages-6.23.0.tgz",
130
+      "integrity": "sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=",
131
+      "dev": true,
132
+      "requires": {
133
+        "babel-runtime": "^6.22.0"
134
+      }
135
+    },
136
+    "babel-plugin-check-es2015-constants": {
137
+      "version": "6.22.0",
138
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-check-es2015-constants/download/babel-plugin-check-es2015-constants-6.22.0.tgz",
139
+      "integrity": "sha1-NRV7EBQm/S/9PaP3XH0ekYNbv4o=",
140
+      "dev": true,
141
+      "requires": {
142
+        "babel-runtime": "^6.22.0"
143
+      }
144
+    },
145
+    "babel-plugin-transform-es2015-arrow-functions": {
146
+      "version": "6.22.0",
147
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-arrow-functions/download/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz",
148
+      "integrity": "sha1-RSaSy3EdX3ncf4XkQM5BufJE0iE=",
149
+      "dev": true,
150
+      "requires": {
151
+        "babel-runtime": "^6.22.0"
152
+      }
153
+    },
154
+    "babel-plugin-transform-es2015-block-scoped-functions": {
155
+      "version": "6.22.0",
156
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-block-scoped-functions/download/babel-plugin-transform-es2015-block-scoped-functions-6.22.0.tgz",
157
+      "integrity": "sha1-u8UbSflk1wy42OC5ToICRs46YUE=",
158
+      "dev": true,
159
+      "requires": {
160
+        "babel-runtime": "^6.22.0"
161
+      }
162
+    },
163
+    "babel-plugin-transform-es2015-block-scoping": {
164
+      "version": "6.26.0",
165
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-block-scoping/download/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz",
166
+      "integrity": "sha1-1w9SmcEwjQXBL0Y4E7CgnnOxiV8=",
167
+      "dev": true,
168
+      "requires": {
169
+        "babel-runtime": "^6.26.0",
170
+        "babel-template": "^6.26.0",
171
+        "babel-traverse": "^6.26.0",
172
+        "babel-types": "^6.26.0",
173
+        "lodash": "^4.17.4"
174
+      }
175
+    },
176
+    "babel-plugin-transform-es2015-classes": {
177
+      "version": "6.24.1",
178
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-classes/download/babel-plugin-transform-es2015-classes-6.24.1.tgz",
179
+      "integrity": "sha1-WkxYpQyclGHlZLSyo7+ryXolhNs=",
180
+      "dev": true,
181
+      "requires": {
182
+        "babel-helper-define-map": "^6.24.1",
183
+        "babel-helper-function-name": "^6.24.1",
184
+        "babel-helper-optimise-call-expression": "^6.24.1",
185
+        "babel-helper-replace-supers": "^6.24.1",
186
+        "babel-messages": "^6.23.0",
187
+        "babel-runtime": "^6.22.0",
188
+        "babel-template": "^6.24.1",
189
+        "babel-traverse": "^6.24.1",
190
+        "babel-types": "^6.24.1"
191
+      }
192
+    },
193
+    "babel-plugin-transform-es2015-computed-properties": {
194
+      "version": "6.24.1",
195
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-computed-properties/download/babel-plugin-transform-es2015-computed-properties-6.24.1.tgz",
196
+      "integrity": "sha1-b+Ko0WiV1WNPTNmZttNICjCBWbM=",
197
+      "dev": true,
198
+      "requires": {
199
+        "babel-runtime": "^6.22.0",
200
+        "babel-template": "^6.24.1"
201
+      }
202
+    },
203
+    "babel-plugin-transform-es2015-destructuring": {
204
+      "version": "6.23.0",
205
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-destructuring/download/babel-plugin-transform-es2015-destructuring-6.23.0.tgz",
206
+      "integrity": "sha1-mXux8auWf2gtKwh2/jWNYOdlxW0=",
207
+      "dev": true,
208
+      "requires": {
209
+        "babel-runtime": "^6.22.0"
210
+      }
211
+    },
212
+    "babel-plugin-transform-es2015-duplicate-keys": {
213
+      "version": "6.24.1",
214
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-duplicate-keys/download/babel-plugin-transform-es2015-duplicate-keys-6.24.1.tgz",
215
+      "integrity": "sha1-c+s9MQypaePvnskcU3QabxV2Qj4=",
216
+      "dev": true,
217
+      "requires": {
218
+        "babel-runtime": "^6.22.0",
219
+        "babel-types": "^6.24.1"
220
+      }
221
+    },
222
+    "babel-plugin-transform-es2015-for-of": {
223
+      "version": "6.23.0",
224
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-for-of/download/babel-plugin-transform-es2015-for-of-6.23.0.tgz",
225
+      "integrity": "sha1-9HyVsrYT3x0+zC/bdXNiPHUkhpE=",
226
+      "dev": true,
227
+      "requires": {
228
+        "babel-runtime": "^6.22.0"
229
+      }
230
+    },
231
+    "babel-plugin-transform-es2015-function-name": {
232
+      "version": "6.24.1",
233
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-function-name/download/babel-plugin-transform-es2015-function-name-6.24.1.tgz",
234
+      "integrity": "sha1-g0yJhTvDaxrw86TF26qU/Y6sqos=",
235
+      "dev": true,
236
+      "requires": {
237
+        "babel-helper-function-name": "^6.24.1",
238
+        "babel-runtime": "^6.22.0",
239
+        "babel-types": "^6.24.1"
240
+      }
241
+    },
242
+    "babel-plugin-transform-es2015-literals": {
243
+      "version": "6.22.0",
244
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-literals/download/babel-plugin-transform-es2015-literals-6.22.0.tgz",
245
+      "integrity": "sha1-T1SgLWzWbPkVKAAZox0xklN3yi4=",
246
+      "dev": true,
247
+      "requires": {
248
+        "babel-runtime": "^6.22.0"
249
+      }
250
+    },
251
+    "babel-plugin-transform-es2015-modules-amd": {
252
+      "version": "6.24.1",
253
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-amd/download/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz",
254
+      "integrity": "sha1-Oz5UAXI5hC1tGcMBHEvS8AoA0VQ=",
255
+      "dev": true,
256
+      "requires": {
257
+        "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
258
+        "babel-runtime": "^6.22.0",
259
+        "babel-template": "^6.24.1"
260
+      }
261
+    },
262
+    "babel-plugin-transform-es2015-modules-commonjs": {
263
+      "version": "6.26.2",
264
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-commonjs/download/babel-plugin-transform-es2015-modules-commonjs-6.26.2.tgz",
265
+      "integrity": "sha1-WKeThjqefKhwvcWogRF/+sJ9tvM=",
266
+      "dev": true,
267
+      "requires": {
268
+        "babel-plugin-transform-strict-mode": "^6.24.1",
269
+        "babel-runtime": "^6.26.0",
270
+        "babel-template": "^6.26.0",
271
+        "babel-types": "^6.26.0"
272
+      }
273
+    },
274
+    "babel-plugin-transform-es2015-modules-systemjs": {
275
+      "version": "6.24.1",
276
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-systemjs/download/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz",
277
+      "integrity": "sha1-/4mhQrkRmpBhlfXxBuzzBdlAfSM=",
278
+      "dev": true,
279
+      "requires": {
280
+        "babel-helper-hoist-variables": "^6.24.1",
281
+        "babel-runtime": "^6.22.0",
282
+        "babel-template": "^6.24.1"
283
+      }
284
+    },
285
+    "babel-plugin-transform-es2015-modules-umd": {
286
+      "version": "6.24.1",
287
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-modules-umd/download/babel-plugin-transform-es2015-modules-umd-6.24.1.tgz",
288
+      "integrity": "sha1-rJl+YoXNGO1hdq22B9YCNErThGg=",
289
+      "dev": true,
290
+      "requires": {
291
+        "babel-plugin-transform-es2015-modules-amd": "^6.24.1",
292
+        "babel-runtime": "^6.22.0",
293
+        "babel-template": "^6.24.1"
294
+      }
295
+    },
296
+    "babel-plugin-transform-es2015-object-super": {
297
+      "version": "6.24.1",
298
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-object-super/download/babel-plugin-transform-es2015-object-super-6.24.1.tgz",
299
+      "integrity": "sha1-JM72muIcuDp/hgPa0CH1cusnj40=",
300
+      "dev": true,
301
+      "requires": {
302
+        "babel-helper-replace-supers": "^6.24.1",
303
+        "babel-runtime": "^6.22.0"
304
+      }
305
+    },
306
+    "babel-plugin-transform-es2015-parameters": {
307
+      "version": "6.24.1",
308
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-parameters/download/babel-plugin-transform-es2015-parameters-6.24.1.tgz",
309
+      "integrity": "sha1-V6w1GrScrxSpfNE7CfZv3wpiXys=",
310
+      "dev": true,
311
+      "requires": {
312
+        "babel-helper-call-delegate": "^6.24.1",
313
+        "babel-helper-get-function-arity": "^6.24.1",
314
+        "babel-runtime": "^6.22.0",
315
+        "babel-template": "^6.24.1",
316
+        "babel-traverse": "^6.24.1",
317
+        "babel-types": "^6.24.1"
318
+      }
319
+    },
320
+    "babel-plugin-transform-es2015-shorthand-properties": {
321
+      "version": "6.24.1",
322
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-shorthand-properties/download/babel-plugin-transform-es2015-shorthand-properties-6.24.1.tgz",
323
+      "integrity": "sha1-JPh11nIch2YbvZmkYi5R8U3jiqA=",
324
+      "dev": true,
325
+      "requires": {
326
+        "babel-runtime": "^6.22.0",
327
+        "babel-types": "^6.24.1"
328
+      }
329
+    },
330
+    "babel-plugin-transform-es2015-spread": {
331
+      "version": "6.22.0",
332
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-spread/download/babel-plugin-transform-es2015-spread-6.22.0.tgz",
333
+      "integrity": "sha1-1taKmfia7cRTbIGlQujdnxdG+NE=",
334
+      "dev": true,
335
+      "requires": {
336
+        "babel-runtime": "^6.22.0"
337
+      }
338
+    },
339
+    "babel-plugin-transform-es2015-sticky-regex": {
340
+      "version": "6.24.1",
341
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-sticky-regex/download/babel-plugin-transform-es2015-sticky-regex-6.24.1.tgz",
342
+      "integrity": "sha1-AMHNsaynERLN8M9hJsLta0V8zbw=",
343
+      "dev": true,
344
+      "requires": {
345
+        "babel-helper-regex": "^6.24.1",
346
+        "babel-runtime": "^6.22.0",
347
+        "babel-types": "^6.24.1"
348
+      }
349
+    },
350
+    "babel-plugin-transform-es2015-template-literals": {
351
+      "version": "6.22.0",
352
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-template-literals/download/babel-plugin-transform-es2015-template-literals-6.22.0.tgz",
353
+      "integrity": "sha1-qEs0UPfp+PH2g51taH2oS7EjbY0=",
354
+      "dev": true,
355
+      "requires": {
356
+        "babel-runtime": "^6.22.0"
357
+      }
358
+    },
359
+    "babel-plugin-transform-es2015-typeof-symbol": {
360
+      "version": "6.23.0",
361
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-typeof-symbol/download/babel-plugin-transform-es2015-typeof-symbol-6.23.0.tgz",
362
+      "integrity": "sha1-3sCfHN3/lLUqxz1QXITfWdzOs3I=",
363
+      "dev": true,
364
+      "requires": {
365
+        "babel-runtime": "^6.22.0"
366
+      }
367
+    },
368
+    "babel-plugin-transform-es2015-unicode-regex": {
369
+      "version": "6.24.1",
370
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-es2015-unicode-regex/download/babel-plugin-transform-es2015-unicode-regex-6.24.1.tgz",
371
+      "integrity": "sha1-04sS9C6nMj9yk4fxinxa4frrNek=",
372
+      "dev": true,
373
+      "requires": {
374
+        "babel-helper-regex": "^6.24.1",
375
+        "babel-runtime": "^6.22.0",
376
+        "regexpu-core": "^2.0.0"
377
+      }
378
+    },
379
+    "babel-plugin-transform-regenerator": {
380
+      "version": "6.26.0",
381
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-regenerator/download/babel-plugin-transform-regenerator-6.26.0.tgz",
382
+      "integrity": "sha1-4HA2lvveJ/Cj78rPi03KL3s6jy8=",
383
+      "dev": true,
384
+      "requires": {
385
+        "regenerator-transform": "^0.10.0"
386
+      }
387
+    },
388
+    "babel-plugin-transform-strict-mode": {
389
+      "version": "6.24.1",
390
+      "resolved": "http://registry.npm.taobao.org/babel-plugin-transform-strict-mode/download/babel-plugin-transform-strict-mode-6.24.1.tgz",
391
+      "integrity": "sha1-1fr3qleKZbvlkc9e2uBKDGcCB1g=",
392
+      "dev": true,
393
+      "requires": {
394
+        "babel-runtime": "^6.22.0",
395
+        "babel-types": "^6.24.1"
396
+      }
397
+    },
398
+    "babel-preset-es2015": {
399
+      "version": "6.24.1",
400
+      "resolved": "http://registry.npm.taobao.org/babel-preset-es2015/download/babel-preset-es2015-6.24.1.tgz",
401
+      "integrity": "sha1-1EBQ1rwsn+6nAqrzjXJ6AhBTiTk=",
402
+      "dev": true,
403
+      "requires": {
404
+        "babel-plugin-check-es2015-constants": "^6.22.0",
405
+        "babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
406
+        "babel-plugin-transform-es2015-block-scoped-functions": "^6.22.0",
407
+        "babel-plugin-transform-es2015-block-scoping": "^6.24.1",
408
+        "babel-plugin-transform-es2015-classes": "^6.24.1",
409
+        "babel-plugin-transform-es2015-computed-properties": "^6.24.1",
410
+        "babel-plugin-transform-es2015-destructuring": "^6.22.0",
411
+        "babel-plugin-transform-es2015-duplicate-keys": "^6.24.1",
412
+        "babel-plugin-transform-es2015-for-of": "^6.22.0",
413
+        "babel-plugin-transform-es2015-function-name": "^6.24.1",
414
+        "babel-plugin-transform-es2015-literals": "^6.22.0",
415
+        "babel-plugin-transform-es2015-modules-amd": "^6.24.1",
416
+        "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
417
+        "babel-plugin-transform-es2015-modules-systemjs": "^6.24.1",
418
+        "babel-plugin-transform-es2015-modules-umd": "^6.24.1",
419
+        "babel-plugin-transform-es2015-object-super": "^6.24.1",
420
+        "babel-plugin-transform-es2015-parameters": "^6.24.1",
421
+        "babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
422
+        "babel-plugin-transform-es2015-spread": "^6.22.0",
423
+        "babel-plugin-transform-es2015-sticky-regex": "^6.24.1",
424
+        "babel-plugin-transform-es2015-template-literals": "^6.22.0",
425
+        "babel-plugin-transform-es2015-typeof-symbol": "^6.22.0",
426
+        "babel-plugin-transform-es2015-unicode-regex": "^6.24.1",
427
+        "babel-plugin-transform-regenerator": "^6.24.1"
428
+      }
429
+    },
430
+    "babel-runtime": {
431
+      "version": "6.26.0",
432
+      "resolved": "http://registry.npm.taobao.org/babel-runtime/download/babel-runtime-6.26.0.tgz",
433
+      "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
434
+      "dev": true,
435
+      "requires": {
436
+        "core-js": "^2.4.0",
437
+        "regenerator-runtime": "^0.11.0"
438
+      }
439
+    },
440
+    "babel-template": {
441
+      "version": "6.26.0",
442
+      "resolved": "http://registry.npm.taobao.org/babel-template/download/babel-template-6.26.0.tgz",
443
+      "integrity": "sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=",
444
+      "dev": true,
445
+      "requires": {
446
+        "babel-runtime": "^6.26.0",
447
+        "babel-traverse": "^6.26.0",
448
+        "babel-types": "^6.26.0",
449
+        "babylon": "^6.18.0",
450
+        "lodash": "^4.17.4"
451
+      }
452
+    },
453
+    "babel-traverse": {
454
+      "version": "6.26.0",
455
+      "resolved": "http://registry.npm.taobao.org/babel-traverse/download/babel-traverse-6.26.0.tgz",
456
+      "integrity": "sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=",
457
+      "dev": true,
458
+      "requires": {
459
+        "babel-code-frame": "^6.26.0",
460
+        "babel-messages": "^6.23.0",
461
+        "babel-runtime": "^6.26.0",
462
+        "babel-types": "^6.26.0",
463
+        "babylon": "^6.18.0",
464
+        "debug": "^2.6.8",
465
+        "globals": "^9.18.0",
466
+        "invariant": "^2.2.2",
467
+        "lodash": "^4.17.4"
468
+      }
469
+    },
470
+    "babel-types": {
471
+      "version": "6.26.0",
472
+      "resolved": "http://registry.npm.taobao.org/babel-types/download/babel-types-6.26.0.tgz",
473
+      "integrity": "sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=",
474
+      "dev": true,
475
+      "requires": {
476
+        "babel-runtime": "^6.26.0",
477
+        "esutils": "^2.0.2",
478
+        "lodash": "^4.17.4",
479
+        "to-fast-properties": "^1.0.3"
480
+      }
481
+    },
482
+    "babylon": {
483
+      "version": "6.18.0",
484
+      "resolved": "http://registry.npm.taobao.org/babylon/download/babylon-6.18.0.tgz",
485
+      "integrity": "sha1-ry87iPpvXB5MY00aD46sT1WzleM=",
486
+      "dev": true
487
+    },
488
+    "chalk": {
489
+      "version": "1.1.3",
490
+      "resolved": "http://registry.npm.taobao.org/chalk/download/chalk-1.1.3.tgz",
491
+      "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
492
+      "dev": true,
493
+      "requires": {
494
+        "ansi-styles": "^2.2.1",
495
+        "escape-string-regexp": "^1.0.2",
496
+        "has-ansi": "^2.0.0",
497
+        "strip-ansi": "^3.0.0",
498
+        "supports-color": "^2.0.0"
499
+      }
500
+    },
501
+    "core-js": {
502
+      "version": "2.6.5",
503
+      "resolved": "http://registry.npm.taobao.org/core-js/download/core-js-2.6.5.tgz?cache=0&other_urls=http%3A%2F%2Fregistry.npm.taobao.org%2Fcore-js%2Fdownload%2Fcore-js-2.6.5.tgz",
504
+      "integrity": "sha1-RLyNJJ5/sv9dAOA0Gn/7lPv2eJU=",
505
+      "dev": true
506
+    },
507
+    "debug": {
508
+      "version": "2.6.9",
509
+      "resolved": "http://registry.npm.taobao.org/debug/download/debug-2.6.9.tgz",
510
+      "integrity": "sha1-XRKFFd8TT/Mn6QpMk/Tgd6U2NB8=",
511
+      "dev": true,
512
+      "requires": {
513
+        "ms": "2.0.0"
514
+      }
515
+    },
516
+    "escape-string-regexp": {
517
+      "version": "1.0.5",
518
+      "resolved": "http://registry.npm.taobao.org/escape-string-regexp/download/escape-string-regexp-1.0.5.tgz",
519
+      "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
520
+      "dev": true
521
+    },
522
+    "esutils": {
523
+      "version": "2.0.2",
524
+      "resolved": "http://registry.npm.taobao.org/esutils/download/esutils-2.0.2.tgz",
525
+      "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=",
526
+      "dev": true
527
+    },
528
+    "globals": {
529
+      "version": "9.18.0",
530
+      "resolved": "http://registry.npm.taobao.org/globals/download/globals-9.18.0.tgz",
531
+      "integrity": "sha1-qjiWs+abSH8X4x7SFD1pqOMMLYo=",
532
+      "dev": true
533
+    },
534
+    "has-ansi": {
535
+      "version": "2.0.0",
536
+      "resolved": "http://registry.npm.taobao.org/has-ansi/download/has-ansi-2.0.0.tgz",
537
+      "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=",
538
+      "dev": true,
539
+      "requires": {
540
+        "ansi-regex": "^2.0.0"
541
+      }
542
+    },
543
+    "invariant": {
544
+      "version": "2.2.4",
545
+      "resolved": "http://registry.npm.taobao.org/invariant/download/invariant-2.2.4.tgz",
546
+      "integrity": "sha1-YQ88ksk1nOHbYW5TgAjSP/NRWOY=",
547
+      "dev": true,
548
+      "requires": {
549
+        "loose-envify": "^1.0.0"
550
+      }
551
+    },
552
+    "js-tokens": {
553
+      "version": "3.0.2",
554
+      "resolved": "http://registry.npm.taobao.org/js-tokens/download/js-tokens-3.0.2.tgz",
555
+      "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=",
556
+      "dev": true
557
+    },
558
+    "jsesc": {
559
+      "version": "0.5.0",
560
+      "resolved": "http://registry.npm.taobao.org/jsesc/download/jsesc-0.5.0.tgz",
561
+      "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=",
562
+      "dev": true
563
+    },
564
+    "lodash": {
565
+      "version": "4.17.11",
566
+      "resolved": "http://registry.npm.taobao.org/lodash/download/lodash-4.17.11.tgz",
567
+      "integrity": "sha1-s56mIp72B+zYniyN8SU2iRysm40=",
568
+      "dev": true
569
+    },
570
+    "loose-envify": {
571
+      "version": "1.4.0",
572
+      "resolved": "http://registry.npm.taobao.org/loose-envify/download/loose-envify-1.4.0.tgz",
573
+      "integrity": "sha1-ce5R+nvkyuwaY4OffmgtgTLTDK8=",
574
+      "dev": true,
575
+      "requires": {
576
+        "js-tokens": "^3.0.0 || ^4.0.0"
577
+      }
578
+    },
579
+    "ms": {
580
+      "version": "2.0.0",
581
+      "resolved": "http://registry.npm.taobao.org/ms/download/ms-2.0.0.tgz",
582
+      "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
583
+      "dev": true
584
+    },
585
+    "private": {
586
+      "version": "0.1.8",
587
+      "resolved": "http://registry.npm.taobao.org/private/download/private-0.1.8.tgz",
588
+      "integrity": "sha1-I4Hts2ifelPWUxkAYPz4ItLzaP8=",
589
+      "dev": true
590
+    },
591
+    "regenerate": {
592
+      "version": "1.4.0",
593
+      "resolved": "http://registry.npm.taobao.org/regenerate/download/regenerate-1.4.0.tgz",
594
+      "integrity": "sha1-SoVuxLVuQHfFV1icroXnpMiGmhE=",
595
+      "dev": true
596
+    },
597
+    "regenerator-runtime": {
598
+      "version": "0.11.1",
599
+      "resolved": "http://registry.npm.taobao.org/regenerator-runtime/download/regenerator-runtime-0.11.1.tgz",
600
+      "integrity": "sha1-vgWtf5v30i4Fb5cmzuUBf78Z4uk=",
601
+      "dev": true
602
+    },
603
+    "regenerator-transform": {
604
+      "version": "0.10.1",
605
+      "resolved": "http://registry.npm.taobao.org/regenerator-transform/download/regenerator-transform-0.10.1.tgz",
606
+      "integrity": "sha1-HkmWg3Ix2ot/PPQRTXG1aRoGgN0=",
607
+      "dev": true,
608
+      "requires": {
609
+        "babel-runtime": "^6.18.0",
610
+        "babel-types": "^6.19.0",
611
+        "private": "^0.1.6"
612
+      }
613
+    },
614
+    "regexpu-core": {
615
+      "version": "2.0.0",
616
+      "resolved": "http://registry.npm.taobao.org/regexpu-core/download/regexpu-core-2.0.0.tgz",
617
+      "integrity": "sha1-SdA4g3uNz4v6W5pCE5k45uoq4kA=",
618
+      "dev": true,
619
+      "requires": {
620
+        "regenerate": "^1.2.1",
621
+        "regjsgen": "^0.2.0",
622
+        "regjsparser": "^0.1.4"
623
+      }
624
+    },
625
+    "regjsgen": {
626
+      "version": "0.2.0",
627
+      "resolved": "http://registry.npm.taobao.org/regjsgen/download/regjsgen-0.2.0.tgz",
628
+      "integrity": "sha1-bAFq3qxVT3WCP+N6wFuS1aTtsfc=",
629
+      "dev": true
630
+    },
631
+    "regjsparser": {
632
+      "version": "0.1.5",
633
+      "resolved": "http://registry.npm.taobao.org/regjsparser/download/regjsparser-0.1.5.tgz",
634
+      "integrity": "sha1-fuj4Tcb6eS0/0K4ijSS9lJ6tIFw=",
635
+      "dev": true,
636
+      "requires": {
637
+        "jsesc": "~0.5.0"
638
+      }
639
+    },
12 640
     "spark-md5": {
13 641
       "version": "3.0.0",
14 642
       "resolved": "http://registry.npm.taobao.org/spark-md5/download/spark-md5-3.0.0.tgz",
15 643
       "integrity": "sha1-NyIifFTi+vJLHcbZM8wUTm9xv+8="
644
+    },
645
+    "strip-ansi": {
646
+      "version": "3.0.1",
647
+      "resolved": "http://registry.npm.taobao.org/strip-ansi/download/strip-ansi-3.0.1.tgz",
648
+      "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
649
+      "dev": true,
650
+      "requires": {
651
+        "ansi-regex": "^2.0.0"
652
+      }
653
+    },
654
+    "supports-color": {
655
+      "version": "2.0.0",
656
+      "resolved": "http://registry.npm.taobao.org/supports-color/download/supports-color-2.0.0.tgz",
657
+      "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
658
+      "dev": true
659
+    },
660
+    "to-fast-properties": {
661
+      "version": "1.0.3",
662
+      "resolved": "http://registry.npm.taobao.org/to-fast-properties/download/to-fast-properties-1.0.3.tgz",
663
+      "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=",
664
+      "dev": true
16 665
     }
17 666
   }
18 667
 }

+ 3
- 0
package.json View File

@@ -18,5 +18,8 @@
18 18
   "dependencies": {
19 19
     "@types/spark-md5": "^3.0.1",
20 20
     "spark-md5": "^3.0.0"
21
+  },
22
+  "devDependencies": {
23
+    "babel-preset-es2015": "^6.24.1"
21 24
   }
22 25
 }

index.js → utils/index.js View File

@@ -1,5 +1,5 @@
1
-import { Constants } from './utils/contants'
2
-import getFilemd5sum from './utils/utils'
1
+import { Constants } from './contants'
2
+import getFilemd5sum from './utils'
3 3
 
4 4
 function FileFactory(file) {
5 5
   this.offset = 0; //用于断点续传,默认为 0