add support for passkeep csv import

This commit is contained in:
Kyle Spearrin 2017-05-19 14:10:21 -04:00
parent 6a292d6905
commit 9918e903b2
2 changed files with 88 additions and 0 deletions

View File

@ -95,6 +95,9 @@
case 'meldiumcsv': case 'meldiumcsv':
importMeldiumCsv(file, success, error); importMeldiumCsv(file, success, error);
break; break;
case 'passkeepcsv':
importPassKeepCsv(file, success, error);
break;
default: default:
error(); error();
break; break;
@ -2369,5 +2372,84 @@
}); });
} }
function importPassKeepCsv(file, success, error) {
function getValue(key, obj) {
var val = obj[key] || obj[(' ' + key)];
if (val && val !== '') {
return val;
}
return null;
}
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
logins = [],
folderRelationships = [];
angular.forEach(results.data, function (value, key) {
var folderIndex = folders.length,
loginIndex = logins.length,
hasFolder = !!getValue('category', value),
addFolder = hasFolder,
i = 0;
if (hasFolder) {
for (i = 0; i < folders.length; i++) {
if (folders[i].name === getValue('category', value)) {
addFolder = false;
folderIndex = i;
break;
}
}
}
var login = {
favorite: false,
uri: !!getValue('site', value) ? fixUri(getValue('site', value)) : null,
username: !!getValue('username', value) ? getValue('username', value) : null,
password: !!getValue('password', value) ? getValue('password', value) : null,
notes: !!getValue('description', value) ? getValue('description', value) : null,
name: !!getValue('title', value) ? getValue('title', value) : '--'
};
if (!!getValue('password2', value)) {
if (!login.notes) {
login.notes = '';
}
else {
login.notes += '\n';
}
login.notes += ('Password 2: ' + getValue('password2', value));
}
logins.push(login);
if (addFolder) {
folders.push({
name: getValue('category', value)
});
}
if (hasFolder) {
var relationship = {
key: loginIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
});
success(folders, logins, folderRelationships);
}
});
}
return _service; return _service;
}); });

View File

@ -196,6 +196,12 @@
name: 'Meldium (csv)', name: 'Meldium (csv)',
instructions: $sce.trustAsHtml('Using the Meldium web vault, navigate to "Settings". ' + instructions: $sce.trustAsHtml('Using the Meldium web vault, navigate to "Settings". ' +
'Locate the "Export data" function and click "Show me my data" to save the CSV file.') 'Locate the "Export data" function and click "Show me my data" to save the CSV file.')
},
{
id: 'passkeepcsv',
name: 'PassKeep (csv)',
instructions: $sce.trustAsHtml('Using the PassKeep mobile app, navigate to "Backup/Restore". ' +
'Locate the "CSV Backup/Restore" section and click "Backup to CSV" to save the CSV file.')
} }
]; ];