1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-04 05:08:06 +02:00

handle lastpass import when users try to upload html file instead of csv

This commit is contained in:
Kyle Spearrin 2016-10-13 00:05:18 -04:00
parent 400826baf7
commit 004ddb1e75
2 changed files with 86 additions and 46 deletions

View File

@ -82,14 +82,55 @@
}
function importLastPass(file, success, error) {
if (file.type === 'text/html') {
var reader = new FileReader();
reader.readAsText(file, 'utf-8');
reader.onload = function (evt) {
var doc = $(evt.target.result);
var pre = doc.find('pre');
if (pre.length === 1) {
var csv = pre.text().trim();
var results = Papa.parse(csv, { header: true });
parseData(results.data);
}
else {
var foundPre = false;
for (var i = 0; i < doc.length; i++) {
if (doc[i].tagName === 'PRE') {
foundPre = true;
var csv = doc[i].outerText.trim();
var results = Papa.parse(csv, { header: true });
parseData(results.data);
break;
}
}
if (!foundPre) {
error();
}
}
};
reader.onerror = function (evt) {
error();
};
}
else {
Papa.parse(file, {
header: true,
complete: function (results) {
parseData(results.data);
}
});
}
function parseData(data) {
var folders = [],
sites = [],
siteRelationships = [];
angular.forEach(results.data, function (value, key) {
angular.forEach(data, function (value, key) {
if (!value.url || value.url === '') {
return;
}
@ -135,7 +176,6 @@
success(folders, sites, siteRelationships);
}
});
}
function importSafeInCloudCsv(file, success, error) {

View File

@ -19,7 +19,7 @@
}, function () {
$uibModalInstance.dismiss('cancel');
$state.go('backend.vault').then(function () {
$analytics.eventTrack('Imported Data', { label: model.source });
$analytics.eventTrack('Imported Data', { label: $scope.model.source });
toastr.success('Data has been successfully imported into your vault.', 'Import Success');
});
}, importError);