From b6c9dba0fc30fa18b391c3b0b14d4d6ba6bc0fab Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 19 Oct 2016 18:22:18 -0400 Subject: [PATCH] Added Chrome csv importer. Adjustments to 1Password importer in preparation for detecting different formats. --- src/Web/wwwroot/app/services/importService.js | 48 ++++++++++++++++--- .../app/tools/toolsImportController.js | 1 + .../wwwroot/app/tools/views/toolsImport.html | 1 + 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/Web/wwwroot/app/services/importService.js b/src/Web/wwwroot/app/services/importService.js index 3b7ee0451c..a03c4b254d 100644 --- a/src/Web/wwwroot/app/services/importService.js +++ b/src/Web/wwwroot/app/services/importService.js @@ -32,6 +32,9 @@ case '1password1pif': import1Password1Pif(file, success, error); break; + case 'chromecsv': + importChromeCsv(file, success, error); + break; default: error(); break; @@ -556,12 +559,18 @@ reader.readAsText(file, 'utf-8'); reader.onload = function (evt) { var fileContent = evt.target.result; - var jsonParts = fileContent.split(/(?:\r\n|\r|\n)\*\*\*.*?\*\*\*(?:\r\n|\r|\n)/); - var jsonString = '[' + jsonParts.join(',') + ']'; - var items = JSON.parse(jsonString); + var fileLines = fileContent.split(/(?:\r\n|\r|\n)/); + //var jsonParts = fileContent.split(/(?:\r\n|\r|\n)\*\*\*.*?\*\*\*(?:\r\n|\r|\n)/); + //var jsonString = '[' + jsonParts.join(',') + ']'; + //var items = JSON.parse(jsonString); - for (i = 0; i < items.length; i++) { - var item = items[i]; + for (i = 0; i < fileLines.length; i++) { + var line = fileLines[i]; + if (!line.length || line[0] !== '{') { + continue; + } + + var item = JSON.parse(line); if (item.typeName !== 'webforms.WebForm') { continue; } @@ -576,7 +585,7 @@ }; if (item.secureContents) { - if (item.secureContents.notesPlain) { + if (item.secureContents.notesPlain && item.secureContents.notesPlain !== '') { site.notes = item.secureContents.notesPlain; } @@ -614,5 +623,32 @@ }; } + function importChromeCsv(file, success, error) { + Papa.parse(file, { + header: true, + encoding: 'UTF-8', + complete: function (results) { + parseCsvErrors(results); + + var folders = [], + sites = [], + siteRelationships = []; + + angular.forEach(results.data, function (value, key) { + sites.push({ + favorite: false, + uri: value.url && value.url !== '' ? trimUri(value.url) : null, + username: value.username && value.username !== '' ? value.username : null, + password: value.password && value.password !== '' ? value.password : null, + notes: null, + name: value.name && value.name !== '' ? value.name : '--', + }); + }); + + success(folders, sites, siteRelationships); + } + }); + } + return _service; }); diff --git a/src/Web/wwwroot/app/tools/toolsImportController.js b/src/Web/wwwroot/app/tools/toolsImportController.js index 53d51b261e..fe04be776c 100644 --- a/src/Web/wwwroot/app/tools/toolsImportController.js +++ b/src/Web/wwwroot/app/tools/toolsImportController.js @@ -13,6 +13,7 @@ function importSuccess(folders, sites, folderRelationships) { if (!folders.length && !sites.length) { + $uibModalInstance.dismiss('cancel'); toastr.error('Nothing was imported.'); return; } diff --git a/src/Web/wwwroot/app/tools/views/toolsImport.html b/src/Web/wwwroot/app/tools/views/toolsImport.html index b088d274fe..61661d1b00 100644 --- a/src/Web/wwwroot/app/tools/views/toolsImport.html +++ b/src/Web/wwwroot/app/tools/views/toolsImport.html @@ -9,6 +9,7 @@