1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-27 17:18:04 +01:00

update exporter for logins and note types

This commit is contained in:
Kyle Spearrin 2017-10-23 12:40:54 -04:00
parent 3c296dc5d4
commit a6d56975fb

View File

@ -2,7 +2,7 @@
.module('bit.tools') .module('bit.tools')
.controller('toolsExportController', function ($scope, $state, toastr, $q, $analytics, .controller('toolsExportController', function ($scope, $state, toastr, $q, $analytics,
i18nService, cryptoService, userService, folderService, cipherService, $window) { i18nService, cryptoService, userService, folderService, cipherService, $window, constantsService) {
$scope.i18n = i18nService; $scope.i18n = i18nService;
$('#master-password').focus(); $('#master-password').focus();
@ -40,9 +40,8 @@
} }
function getCsv() { function getCsv() {
var deferred = $q.defer();
var decFolders = []; var decFolders = [];
var decLogins = []; var decCiphers = [];
var promises = []; var promises = [];
var folderPromise = folderService.getAllDecrypted().then(function (folders) { var folderPromise = folderService.getAllDecrypted().then(function (folders) {
@ -50,55 +49,75 @@
}); });
promises.push(folderPromise); promises.push(folderPromise);
var loginPromise = cipherService.getAllDecrypted().then(function (logins) { var ciphersPromise = cipherService.getAllDecrypted().then(function (ciphers) {
decLogins = logins; decCiphers = ciphers;
}); });
promises.push(loginPromise); promises.push(ciphersPromise);
$q.all(promises).then(function () { return $q.all(promises).then(function () {
var exportLogins = []; var foldersDict = {};
for (var i = 0; i < decLogins.length; i++) { for (var i = 0; i < decFolders.length; i++) {
var login = { foldersDict[decFolders[i].id] = decFolders[i];
name: decLogins[i].name, }
uri: decLogins[i].uri,
username: decLogins[i].username, var exportCiphers = [];
password: decLogins[i].password, for (i = 0; i < decCiphers.length; i++) {
notes: decLogins[i].notes, // only export logins and secure notes
folder: null, if (decCiphers[i].type !== constantsService.cipherType.login &&
totp: decLogins[i].totp, decCiphers[i].type !== constantsService.cipherType.secureNote) {
fields: null continue;
}
var cipher = {
folder: decCiphers[i].folderId && (decCiphers[i].folderId in foldersDict) ?
foldersDict[decCiphers[i].folderId].name : null,
favorite: decCiphers[i].favorite ? 1 : null,
type: null,
name: decCiphers[i].name,
notes: decCiphers[i].notes,
fields: null,
// Login props
login_uri: null,
login_username: null,
login_password: null,
login_totp: null
}; };
var j; if (decCiphers[i].fields) {
for (var j = 0; j < decCiphers[i].fields.length; j++) {
if (decLogins[i].fields) { if (!cipher.fields) {
for (j = 0; j < decLogins[i].fields.length; j++) { cipher.fields = '';
if (!login.fields) {
login.fields = '';
} }
else { else {
login.fields += '\n'; cipher.fields += '\n';
} }
login.fields += (decLogins[i].fields[j].name + ': ' + decLogins[i].fields[j].value); cipher.fields += ((decCiphers[i].fields[j].name || '') + ': ' + decCiphers[i].fields[j].value);
} }
} }
for (j = 0; j < decFolders.length; j++) { switch (decCiphers[i].type) {
if (decFolders[j].id === decLogins[i].folderId && decFolders[j].name !== i18nService.noneFolder) { case constantsService.cipherType.login:
login.folder = decFolders[j].name; cipher.type = 'login';
cipher.login_uri = decCiphers[i].login.uri;
cipher.login_username = decCiphers[i].login.username;
cipher.login_password = decCiphers[i].login.password;
cipher.login_totp = decCiphers[i].login.totp;
break;
case constantsService.cipherType.secureNote:
cipher.type = 'note';
break;
default:
continue;
break; break;
} }
exportCiphers.push(cipher);
} }
exportLogins.push(login); var csv = Papa.unparse(exportCiphers);
} return csv;
var csv = Papa.unparse(exportLogins);
deferred.resolve(csv);
}); });
return deferred.promise;
} }
function downloadFile(csvString) { function downloadFile(csvString) {