files.com 1.0.206 → 1.0.209
Sign up to get free protection for your applications and to get access to all the features.
- package/_VERSION +1 -1
- package/docs/Errors.md +1 -0
- package/lib/Errors.js +326 -306
- package/lib/models/File.js +59 -31
- package/package.json +1 -1
- package/src/Errors.js +1 -0
- package/src/models/File.js +44 -24
package/lib/models/File.js
CHANGED
@@ -986,7 +986,7 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
|
|
986
986
|
};
|
987
987
|
}());
|
988
988
|
(0, _defineProperty2.default)(File, "_completeUpload", /*#__PURE__*/function () {
|
989
|
-
var _ref15 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(
|
989
|
+
var _ref15 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(firstFileUploadPart) {
|
990
990
|
var params;
|
991
991
|
return _regenerator.default.wrap(function _callee13$(_context13) {
|
992
992
|
while (1) {
|
@@ -994,9 +994,9 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
|
|
994
994
|
case 0:
|
995
995
|
params = {
|
996
996
|
action: 'end',
|
997
|
-
ref:
|
997
|
+
ref: firstFileUploadPart.ref
|
998
998
|
};
|
999
|
-
return _context13.abrupt("return", _Api.default.sendRequest("/files/".concat(encodeURIComponent(
|
999
|
+
return _context13.abrupt("return", _Api.default.sendRequest("/files/".concat(encodeURIComponent(firstFileUploadPart.path)), 'POST', params));
|
1000
1000
|
|
1001
1001
|
case 2:
|
1002
1002
|
case "end":
|
@@ -1012,7 +1012,7 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
|
|
1012
1012
|
}());
|
1013
1013
|
(0, _defineProperty2.default)(File, "uploadStream", /*#__PURE__*/function () {
|
1014
1014
|
var _ref16 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(destinationPath, readableStream, params) {
|
1015
|
-
var
|
1015
|
+
var firstFileUploadPart, file;
|
1016
1016
|
return _regenerator.default.wrap(function _callee16$(_context16) {
|
1017
1017
|
while (1) {
|
1018
1018
|
switch (_context16.prev = _context16.next) {
|
@@ -1021,9 +1021,9 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
|
|
1021
1021
|
return File._openUpload(destinationPath, params);
|
1022
1022
|
|
1023
1023
|
case 2:
|
1024
|
-
|
1024
|
+
firstFileUploadPart = _context16.sent;
|
1025
1025
|
|
1026
|
-
if (
|
1026
|
+
if (firstFileUploadPart) {
|
1027
1027
|
_context16.next = 5;
|
1028
1028
|
break;
|
1029
1029
|
}
|
@@ -1037,47 +1037,63 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
|
|
1037
1037
|
var part = 0;
|
1038
1038
|
var chunks = [];
|
1039
1039
|
var length = 0;
|
1040
|
+
var concurrentUploads = [];
|
1040
1041
|
readableStream.on('error', function (error) {
|
1041
1042
|
reject(error);
|
1042
1043
|
});
|
1043
1044
|
readableStream.on('data', /*#__PURE__*/function () {
|
1044
1045
|
var _ref17 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(chunk) {
|
1045
|
-
var buffer, nextFileUploadPart;
|
1046
|
+
var nextLength, excessLength, chunkBuffer, lastChunkForPart, firstChunkForNextPart, buffer, nextFileUploadPart;
|
1046
1047
|
return _regenerator.default.wrap(function _callee14$(_context14) {
|
1047
1048
|
while (1) {
|
1048
1049
|
switch (_context14.prev = _context14.next) {
|
1049
1050
|
case 0:
|
1050
|
-
|
1051
|
+
_context14.prev = 0;
|
1052
|
+
nextLength = length + chunk.length;
|
1053
|
+
excessLength = nextLength - firstFileUploadPart.partsize;
|
1054
|
+
chunkBuffer = _safeBuffer.Buffer.from(chunk);
|
1051
1055
|
|
1052
|
-
if (!(
|
1053
|
-
_context14.next =
|
1056
|
+
if (!(excessLength > 0)) {
|
1057
|
+
_context14.next = 19;
|
1054
1058
|
break;
|
1055
1059
|
}
|
1056
1060
|
|
1057
1061
|
readableStream.pause();
|
1062
|
+
lastChunkForPart = chunkBuffer.subarray(0, excessLength);
|
1063
|
+
firstChunkForNextPart = chunkBuffer.subarray(excessLength);
|
1064
|
+
chunks.push(lastChunkForPart);
|
1058
1065
|
buffer = _safeBuffer.Buffer.concat(chunks);
|
1059
|
-
_context14.next =
|
1060
|
-
return File._continueUpload(destinationPath, ++part,
|
1066
|
+
_context14.next = 12;
|
1067
|
+
return File._continueUpload(destinationPath, ++part, firstFileUploadPart);
|
1061
1068
|
|
1062
|
-
case
|
1069
|
+
case 12:
|
1063
1070
|
nextFileUploadPart = _context14.sent;
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
case 9:
|
1068
|
-
chunks = [];
|
1069
|
-
length = 0;
|
1071
|
+
concurrentUploads.push(_Api.default.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer));
|
1072
|
+
chunks = [firstChunkForNextPart];
|
1073
|
+
length = 1;
|
1070
1074
|
readableStream.resume();
|
1075
|
+
_context14.next = 21;
|
1076
|
+
break;
|
1071
1077
|
|
1072
|
-
case
|
1073
|
-
chunks.push(
|
1078
|
+
case 19:
|
1079
|
+
chunks.push(chunkBuffer);
|
1080
|
+
length += chunk.length;
|
1074
1081
|
|
1075
|
-
case
|
1082
|
+
case 21:
|
1083
|
+
_context14.next = 26;
|
1084
|
+
break;
|
1085
|
+
|
1086
|
+
case 23:
|
1087
|
+
_context14.prev = 23;
|
1088
|
+
_context14.t0 = _context14["catch"](0);
|
1089
|
+
reject(_context14.t0);
|
1090
|
+
|
1091
|
+
case 26:
|
1076
1092
|
case "end":
|
1077
1093
|
return _context14.stop();
|
1078
1094
|
}
|
1079
1095
|
}
|
1080
|
-
}, _callee14);
|
1096
|
+
}, _callee14, null, [[0, 23]]);
|
1081
1097
|
}));
|
1082
1098
|
|
1083
1099
|
return function (_x14) {
|
@@ -1090,35 +1106,47 @@ var File = /*#__PURE__*/(0, _createClass2.default)(function File() {
|
|
1090
1106
|
while (1) {
|
1091
1107
|
switch (_context15.prev = _context15.next) {
|
1092
1108
|
case 0:
|
1109
|
+
_context15.prev = 0;
|
1110
|
+
|
1093
1111
|
if (!(chunks.length > 0)) {
|
1094
1112
|
_context15.next = 7;
|
1095
1113
|
break;
|
1096
1114
|
}
|
1097
1115
|
|
1098
1116
|
buffer = _safeBuffer.Buffer.concat(chunks);
|
1099
|
-
_context15.next =
|
1100
|
-
return File._continueUpload(destinationPath, ++part,
|
1117
|
+
_context15.next = 5;
|
1118
|
+
return File._continueUpload(destinationPath, ++part, firstFileUploadPart);
|
1101
1119
|
|
1102
|
-
case
|
1120
|
+
case 5:
|
1103
1121
|
nextFileUploadPart = _context15.sent;
|
1104
|
-
|
1105
|
-
return _Api.default.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer);
|
1122
|
+
concurrentUploads.push(_Api.default.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer));
|
1106
1123
|
|
1107
1124
|
case 7:
|
1108
1125
|
_context15.next = 9;
|
1109
|
-
return
|
1126
|
+
return Promise.all(concurrentUploads);
|
1110
1127
|
|
1111
1128
|
case 9:
|
1129
|
+
_context15.next = 11;
|
1130
|
+
return File._completeUpload(firstFileUploadPart);
|
1131
|
+
|
1132
|
+
case 11:
|
1112
1133
|
response = _context15.sent;
|
1113
1134
|
createdFile = new File(response.data);
|
1114
1135
|
resolve(createdFile);
|
1136
|
+
_context15.next = 19;
|
1137
|
+
break;
|
1138
|
+
|
1139
|
+
case 16:
|
1140
|
+
_context15.prev = 16;
|
1141
|
+
_context15.t0 = _context15["catch"](0);
|
1142
|
+
reject(_context15.t0);
|
1115
1143
|
|
1116
|
-
case
|
1144
|
+
case 19:
|
1117
1145
|
case "end":
|
1118
1146
|
return _context15.stop();
|
1119
1147
|
}
|
1120
1148
|
}
|
1121
|
-
}, _callee15);
|
1149
|
+
}, _callee15, null, [[0, 16]]);
|
1122
1150
|
})));
|
1123
1151
|
});
|
1124
1152
|
|
package/package.json
CHANGED
package/src/Errors.js
CHANGED
@@ -167,6 +167,7 @@ export class NotAuthorized_WritePermissionRequiredError extends NotAuthorizedErr
|
|
167
167
|
export class NotAuthorized_ZipDownloadIpMismatchError extends NotAuthorizedError { constructor(message, code) { super(message, code); this.name = 'NotAuthorized_ZipDownloadIpMismatchError' } } errorClasses.NotAuthorized_ZipDownloadIpMismatchError = NotAuthorized_ZipDownloadIpMismatchError
|
168
168
|
export class NotFound_ApiKeyNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_ApiKeyNotFoundError' } } errorClasses.NotFound_ApiKeyNotFoundError = NotFound_ApiKeyNotFoundError
|
169
169
|
export class NotFound_BundlePathNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_BundlePathNotFoundError' } } errorClasses.NotFound_BundlePathNotFoundError = NotFound_BundlePathNotFoundError
|
170
|
+
export class NotFound_BundleRegistrationNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_BundleRegistrationNotFoundError' } } errorClasses.NotFound_BundleRegistrationNotFoundError = NotFound_BundleRegistrationNotFoundError
|
170
171
|
export class NotFound_CodeNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_CodeNotFoundError' } } errorClasses.NotFound_CodeNotFoundError = NotFound_CodeNotFoundError
|
171
172
|
export class NotFound_FileNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_FileNotFoundError' } } errorClasses.NotFound_FileNotFoundError = NotFound_FileNotFoundError
|
172
173
|
export class NotFound_FileUploadNotFoundError extends NotFoundError { constructor(message, code) { super(message, code); this.name = 'NotFound_FileUploadNotFoundError' } } errorClasses.NotFound_FileUploadNotFoundError = NotFound_FileUploadNotFoundError
|
package/src/models/File.js
CHANGED
@@ -67,22 +67,22 @@ class File {
|
|
67
67
|
return new FileUploadPart(partData)
|
68
68
|
}
|
69
69
|
|
70
|
-
static _completeUpload = async
|
70
|
+
static _completeUpload = async firstFileUploadPart => {
|
71
71
|
const params = {
|
72
72
|
action: 'end',
|
73
|
-
ref:
|
73
|
+
ref: firstFileUploadPart.ref,
|
74
74
|
}
|
75
75
|
|
76
|
-
return Api.sendRequest(`/files/${encodeURIComponent(
|
76
|
+
return Api.sendRequest(`/files/${encodeURIComponent(firstFileUploadPart.path)}`, 'POST', params)
|
77
77
|
}
|
78
78
|
|
79
79
|
/**
|
80
80
|
* @note see File.copy() for list of supported params
|
81
81
|
*/
|
82
82
|
static uploadStream = async (destinationPath, readableStream, params) => {
|
83
|
-
const
|
83
|
+
const firstFileUploadPart = await File._openUpload(destinationPath, params)
|
84
84
|
|
85
|
-
if (!
|
85
|
+
if (!firstFileUploadPart) {
|
86
86
|
return
|
87
87
|
}
|
88
88
|
|
@@ -91,41 +91,61 @@ class File {
|
|
91
91
|
let part = 0
|
92
92
|
let chunks = []
|
93
93
|
let length = 0
|
94
|
+
const concurrentUploads = []
|
94
95
|
|
95
96
|
readableStream.on('error', error => { reject(error) })
|
96
97
|
|
97
98
|
readableStream.on('data', async chunk => {
|
98
|
-
|
99
|
+
try {
|
100
|
+
const nextLength = length + chunk.length
|
101
|
+
const excessLength = nextLength - firstFileUploadPart.partsize
|
99
102
|
|
100
|
-
|
101
|
-
readableStream.pause()
|
103
|
+
const chunkBuffer = Buffer.from(chunk)
|
102
104
|
|
103
|
-
|
104
|
-
|
105
|
+
if (excessLength > 0) {
|
106
|
+
readableStream.pause()
|
105
107
|
|
106
|
-
|
108
|
+
const lastChunkForPart = chunkBuffer.subarray(0, excessLength)
|
109
|
+
const firstChunkForNextPart = chunkBuffer.subarray(excessLength)
|
107
110
|
|
108
|
-
|
109
|
-
length = 0
|
111
|
+
chunks.push(lastChunkForPart)
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
+
const buffer = Buffer.concat(chunks)
|
114
|
+
const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, firstFileUploadPart)
|
115
|
+
|
116
|
+
concurrentUploads.push(Api.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer))
|
117
|
+
|
118
|
+
chunks = [firstChunkForNextPart]
|
119
|
+
length = 1
|
113
120
|
|
114
|
-
|
121
|
+
readableStream.resume()
|
122
|
+
} else {
|
123
|
+
chunks.push(chunkBuffer)
|
124
|
+
length += chunk.length
|
125
|
+
}
|
126
|
+
} catch (error) {
|
127
|
+
reject(error)
|
128
|
+
}
|
115
129
|
})
|
116
130
|
|
117
131
|
readableStream.on('end', async () => {
|
118
|
-
|
119
|
-
|
120
|
-
|
132
|
+
try {
|
133
|
+
if (chunks.length > 0) {
|
134
|
+
const buffer = Buffer.concat(chunks)
|
135
|
+
const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, firstFileUploadPart)
|
121
136
|
|
122
|
-
|
123
|
-
|
137
|
+
concurrentUploads.push(Api.sendFilePart(nextFileUploadPart.upload_uri, 'PUT', buffer))
|
138
|
+
}
|
124
139
|
|
125
|
-
|
126
|
-
const createdFile = new File(response.data)
|
140
|
+
await Promise.all(concurrentUploads)
|
127
141
|
|
128
|
-
|
142
|
+
const response = await File._completeUpload(firstFileUploadPart)
|
143
|
+
const createdFile = new File(response.data)
|
144
|
+
|
145
|
+
resolve(createdFile)
|
146
|
+
} catch (error) {
|
147
|
+
reject(error)
|
148
|
+
}
|
129
149
|
})
|
130
150
|
})
|
131
151
|
|