mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-06 05:28:51 +02:00
handle lastpass import when users try to upload html file instead of csv
This commit is contained in:
parent
400826baf7
commit
004ddb1e75
@ -82,14 +82,55 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function importLastPass(file, success, error) {
|
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, {
|
Papa.parse(file, {
|
||||||
header: true,
|
header: true,
|
||||||
complete: function (results) {
|
complete: function (results) {
|
||||||
|
parseData(results.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseData(data) {
|
||||||
var folders = [],
|
var folders = [],
|
||||||
sites = [],
|
sites = [],
|
||||||
siteRelationships = [];
|
siteRelationships = [];
|
||||||
|
|
||||||
angular.forEach(results.data, function (value, key) {
|
angular.forEach(data, function (value, key) {
|
||||||
if (!value.url || value.url === '') {
|
if (!value.url || value.url === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -135,7 +176,6 @@
|
|||||||
|
|
||||||
success(folders, sites, siteRelationships);
|
success(folders, sites, siteRelationships);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function importSafeInCloudCsv(file, success, error) {
|
function importSafeInCloudCsv(file, success, error) {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
}, function () {
|
}, function () {
|
||||||
$uibModalInstance.dismiss('cancel');
|
$uibModalInstance.dismiss('cancel');
|
||||||
$state.go('backend.vault').then(function () {
|
$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');
|
toastr.success('Data has been successfully imported into your vault.', 'Import Success');
|
||||||
});
|
});
|
||||||
}, importError);
|
}, importError);
|
||||||
|
Loading…
Reference in New Issue
Block a user