@atlaskit/media-store
Advanced tools
Comparing version 3.1.0 to 3.1.1
# @atlaskit/media-store | ||
## 3.1.1 | ||
- [patch] uploadFile() no longer creates an empty file when uploading a file to avoid empty (ghost) files being created in collections when an upload is aborted [5ee48c4](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/5ee48c4) | ||
- [none] Updated dependencies [5ee48c4](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/5ee48c4) | ||
## 3.1.0 | ||
@@ -4,0 +8,0 @@ - [minor] add media mocks [1754450](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/1754450) |
@@ -22,32 +22,8 @@ var _this = this; | ||
}); }; }; | ||
var createUploadingFunction = function (store) { | ||
return function (chunk) { return store.uploadChunk(chunk.hash, chunk.blob); }; | ||
}; | ||
export var uploadFile = function (file, config, callbacks) { | ||
var content = file.content, collection = file.collection, name = file.name, mimeType = file.mimeType; | ||
var occurrenceKey = uuid.v4(); | ||
var store = new MediaStore(config); | ||
var deferredUploadId = store | ||
.createUpload() | ||
.then(function (response) { return response.data[0].id; }); | ||
var uploadingFunction = function (chunk) { | ||
return store.uploadChunk(chunk.hash, chunk.blob); | ||
}; | ||
var offset = 0; | ||
var processingFunction = function (chunks) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_b = (_a = store).appendChunksToUpload; | ||
return [4 /*yield*/, deferredUploadId]; | ||
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent(), { | ||
chunks: hashedChunks(chunks), | ||
offset: offset, | ||
}])]; | ||
case 2: | ||
_c.sent(); | ||
offset += chunks.length; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var deferredEmptyFile = store.createFile({ collection: collection, occurrenceKey: occurrenceKey }); | ||
var _a = chunkinator(content, { | ||
@@ -59,6 +35,5 @@ hashingFunction: hashingFunction, | ||
uploadingConcurrency: 3, | ||
uploadingFunction: uploadingFunction, | ||
uploadingFunction: createUploadingFunction(store), | ||
probingFunction: createProbingFunction(store), | ||
processingBatchSize: 1000, | ||
processingFunction: processingFunction, | ||
}, { | ||
@@ -70,21 +45,40 @@ onProgress: function (progress) { | ||
}, | ||
}), response = _a.response, cancel = _a.cancel; | ||
var fileId = Promise.all([ | ||
deferredUploadId, | ||
deferredEmptyFile, | ||
response, | ||
]).then(function (_a) { | ||
var uploadId = _a[0], emptyFile = _a[1]; | ||
var fileId = emptyFile.data.id; | ||
return store | ||
.createFileFromUpload({ uploadId: uploadId, name: name, mimeType: mimeType }, { | ||
occurrenceKey: occurrenceKey, | ||
}), deferredChunks = _a.response, cancel = _a.cancel; | ||
var deferredFileId = deferredChunks | ||
.then(function (probedChunks) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var uploadId; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, store.createUpload()]; | ||
case 1: | ||
uploadId = (_a.sent()).data[0].id; | ||
return [2 /*return*/, { uploadId: uploadId, probedChunks: probedChunks }]; | ||
} | ||
}); | ||
}); }) | ||
.then(function (_a) { | ||
var uploadId = _a.uploadId, probedChunks = _a.probedChunks; | ||
return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, store.appendChunksToUpload(uploadId, { | ||
chunks: hashedChunks(probedChunks), | ||
})]; | ||
case 1: | ||
_b.sent(); | ||
return [2 /*return*/, uploadId]; | ||
} | ||
}); | ||
}); | ||
}) | ||
.then(function (uploadId) { | ||
return store.createFileFromUpload({ uploadId: uploadId, name: name, mimeType: mimeType }, { | ||
occurrenceKey: uuid.v4(), | ||
collection: collection, | ||
replaceFileId: fileId, | ||
}) | ||
.then(function () { return fileId; }); | ||
}); | ||
return { deferredFileId: fileId, cancel: cancel }; | ||
}); | ||
}) | ||
.then(function (resp) { return resp.data.id; }); | ||
return { deferredFileId: deferredFileId, cancel: cancel }; | ||
}; | ||
var hashedChunks = function (chunks) { return chunks.map(function (chunk) { return chunk.hash; }); }; | ||
//# sourceMappingURL=uploader.js.map |
@@ -24,32 +24,8 @@ "use strict"; | ||
}); }; }; | ||
var createUploadingFunction = function (store) { | ||
return function (chunk) { return store.uploadChunk(chunk.hash, chunk.blob); }; | ||
}; | ||
exports.uploadFile = function (file, config, callbacks) { | ||
var content = file.content, collection = file.collection, name = file.name, mimeType = file.mimeType; | ||
var occurrenceKey = uuid.v4(); | ||
var store = new media_store_1.MediaStore(config); | ||
var deferredUploadId = store | ||
.createUpload() | ||
.then(function (response) { return response.data[0].id; }); | ||
var uploadingFunction = function (chunk) { | ||
return store.uploadChunk(chunk.hash, chunk.blob); | ||
}; | ||
var offset = 0; | ||
var processingFunction = function (chunks) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_b = (_a = store).appendChunksToUpload; | ||
return [4 /*yield*/, deferredUploadId]; | ||
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent(), { | ||
chunks: hashedChunks(chunks), | ||
offset: offset, | ||
}])]; | ||
case 2: | ||
_c.sent(); | ||
offset += chunks.length; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var deferredEmptyFile = store.createFile({ collection: collection, occurrenceKey: occurrenceKey }); | ||
var _a = chunkinator_1.default(content, { | ||
@@ -61,6 +37,5 @@ hashingFunction: hashingFunction, | ||
uploadingConcurrency: 3, | ||
uploadingFunction: uploadingFunction, | ||
uploadingFunction: createUploadingFunction(store), | ||
probingFunction: createProbingFunction(store), | ||
processingBatchSize: 1000, | ||
processingFunction: processingFunction, | ||
}, { | ||
@@ -72,21 +47,40 @@ onProgress: function (progress) { | ||
}, | ||
}), response = _a.response, cancel = _a.cancel; | ||
var fileId = Promise.all([ | ||
deferredUploadId, | ||
deferredEmptyFile, | ||
response, | ||
]).then(function (_a) { | ||
var uploadId = _a[0], emptyFile = _a[1]; | ||
var fileId = emptyFile.data.id; | ||
return store | ||
.createFileFromUpload({ uploadId: uploadId, name: name, mimeType: mimeType }, { | ||
occurrenceKey: occurrenceKey, | ||
}), deferredChunks = _a.response, cancel = _a.cancel; | ||
var deferredFileId = deferredChunks | ||
.then(function (probedChunks) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var uploadId; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, store.createUpload()]; | ||
case 1: | ||
uploadId = (_a.sent()).data[0].id; | ||
return [2 /*return*/, { uploadId: uploadId, probedChunks: probedChunks }]; | ||
} | ||
}); | ||
}); }) | ||
.then(function (_a) { | ||
var uploadId = _a.uploadId, probedChunks = _a.probedChunks; | ||
return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, store.appendChunksToUpload(uploadId, { | ||
chunks: hashedChunks(probedChunks), | ||
})]; | ||
case 1: | ||
_b.sent(); | ||
return [2 /*return*/, uploadId]; | ||
} | ||
}); | ||
}); | ||
}) | ||
.then(function (uploadId) { | ||
return store.createFileFromUpload({ uploadId: uploadId, name: name, mimeType: mimeType }, { | ||
occurrenceKey: uuid.v4(), | ||
collection: collection, | ||
replaceFileId: fileId, | ||
}) | ||
.then(function () { return fileId; }); | ||
}); | ||
return { deferredFileId: fileId, cancel: cancel }; | ||
}); | ||
}) | ||
.then(function (resp) { return resp.data.id; }); | ||
return { deferredFileId: deferredFileId, cancel: cancel }; | ||
}; | ||
var hashedChunks = function (chunks) { return chunks.map(function (chunk) { return chunk.hash; }); }; | ||
//# sourceMappingURL=uploader.js.map |
{ | ||
"name": "@atlaskit/media-store", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"sideEffects": false | ||
} |
{ | ||
"name": "@atlaskit/media-store", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Media Store API Web Client Library", | ||
@@ -34,2 +34,2 @@ "license": "Apache-2.0", | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93376
1573