1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-24 12:06:15 +01:00

capture attachment in closure

This commit is contained in:
Kyle Spearrin 2017-07-10 16:21:39 -04:00
parent 47cb20f01e
commit 51e30b2f7a

View File

@ -116,23 +116,24 @@
var attachmentSharePromises = []; var attachmentSharePromises = [];
if ($scope.login.attachments) { if ($scope.login.attachments) {
for (var i = 0; i < $scope.login.attachments.length; i++) { for (var i = 0; i < $scope.login.attachments.length; i++) {
var attachment = $scope.login.attachments[i]; (function (attachment) {
var promise = cipherService.downloadAndDecryptAttachment(null, attachment, false) var promise = cipherService.downloadAndDecryptAttachment(null, attachment, false)
.then(function (decData) { .then(function (decData) {
return cryptoService.encryptToBytes(decData.buffer, orgKey); return cryptoService.encryptToBytes(decData.buffer, orgKey);
}).then(function (encData) { }).then(function (encData) {
var fd = new FormData(); var fd = new FormData();
var blob = new Blob([encData], { type: 'application/octet-stream' }); var blob = new Blob([encData], { type: 'application/octet-stream' });
var encFilename = cryptoService.encrypt(attachment.fileName, orgKey); var encFilename = cryptoService.encrypt(attachment.fileName, orgKey);
fd.append('data', blob, encFilename); fd.append('data', blob, encFilename);
return apiService.ciphers.postShareAttachment({ return apiService.ciphers.postShareAttachment({
id: loginId, id: loginId,
attachmentId: attachment.id, attachmentId: attachment.id,
orgId: model.organizationId orgId: model.organizationId
}, fd).$promise; }, fd).$promise;
}); });
attachmentSharePromises.push(promise); attachmentSharePromises.push(promise);
})($scope.login.attachments[i]);
} }
} }