From 21635dd72871768cce4c5531b96798b53856e31b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 2 Oct 2017 12:37:17 -0400 Subject: [PATCH] import/export custom fields --- src/app/services/importService.js | 41 +++++++++++++++++++++++--- src/app/tools/toolsExportController.js | 16 +++++++++- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/app/services/importService.js b/src/app/services/importService.js index 83a2176961..f01425b816 100644 --- a/src/app/services/importService.js +++ b/src/app/services/importService.js @@ -243,7 +243,8 @@ var folders = [], logins = [], - folderRelationships = []; + folderRelationships = [], + i = 0; angular.forEach(results.data, function (value, key) { var folderIndex = folders.length, @@ -252,7 +253,7 @@ addFolder = hasFolder; if (hasFolder) { - for (var i = 0; i < folders.length; i++) { + for (i = 0; i < folders.length; i++) { if (folders[i].name === value.folder) { addFolder = false; folderIndex = i; @@ -261,7 +262,7 @@ } } - logins.push({ + var login = { favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false, uri: value.uri && value.uri !== '' ? trimUri(value.uri) : null, username: value.username && value.username !== '' ? value.username : null, @@ -269,7 +270,39 @@ notes: value.notes && value.notes !== '' ? value.notes : null, name: value.name && value.name !== '' ? value.name : '--', totp: value.totp && value.totp !== '' ? value.totp : null - }); + }; + + if (value.fields && value.fields !== '') { + var fields = value.fields.split('\n'); + for (i = 0; i < fields.length; i++) { + if (!fields[i] || fields[i] === '') { + continue; + } + + var delimPosition = fields[i].lastIndexOf(': '); + if (delimPosition === -1) { + continue; + } + + if (!login.fields) { + login.fields = []; + } + + var field = { + name: fields[i].substr(0, delimPosition), + value: null, + type: 0 + } + + if (fields[i].length > (delimPosition + 2)) { + field.value = fields[i].substr(delimPosition + 2); + } + + login.fields.push(field); + } + } + + logins.push(login); if (addFolder) { folders.push({ diff --git a/src/app/tools/toolsExportController.js b/src/app/tools/toolsExportController.js index 9810de3b24..834c0333c5 100644 --- a/src/app/tools/toolsExportController.js +++ b/src/app/tools/toolsExportController.js @@ -41,9 +41,23 @@ folder: decLogins[i].folderId && (decLogins[i].folderId in foldersDict) ? foldersDict[decLogins[i].folderId].name : null, favorite: decLogins[i].favorite ? 1 : null, - totp: decLogins[i].totp + totp: decLogins[i].totp, + fields: null }; + if (decLogins[i].fields) { + for (var j = 0; j < decLogins[i].fields.length; j++) { + if (!login.fields) { + login.fields = ''; + } + else { + login.fields += '\n'; + } + + login.fields += (decLogins[i].fields[j].name + ': ' + decLogins[i].fields[j].value); + } + } + exportLogins.push(login); }