1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-05 09:10:53 +01:00

keeper csv import (#1)

This commit is contained in:
Kyle Spearrin 2016-11-11 00:10:16 -05:00
parent 4b583bea9b
commit c328144a58
2 changed files with 81 additions and 0 deletions

View File

@ -41,6 +41,9 @@
case 'upmcsv': case 'upmcsv':
importUpmCsv(file, success, error); importUpmCsv(file, success, error);
break; break;
case 'keepercsv':
importKeeperCsv(file, success, error);
break;
default: default:
error(); error();
break; break;
@ -780,5 +783,82 @@
}); });
} }
function importKeeperCsv(file, success, error) {
Papa.parse(file, {
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var folders = [],
sites = [],
folderRelationships = [];
angular.forEach(results.data, function (value, key) {
if (value.length >= 6) {
var folderIndex = folders.length,
siteIndex = sites.length,
hasFolder = value[0] && value[0] !== '',
addFolder = hasFolder,
i = 0;
if (hasFolder) {
for (i = 0; i < folders.length; i++) {
if (folders[i].name === value[0]) {
addFolder = false;
folderIndex = i;
break;
}
}
}
var site = {
favorite: false,
uri: value[4] && value[4] !== '' ? trimUri(value[4]) : null,
username: value[2] && value[2] !== '' ? value[2] : null,
password: value[3] && value[3] !== '' ? value[3] : null,
notes: value[5] && value[5] !== '' ? value[5] : null,
name: value[1] && value[1] !== '' ? value[1] : '--',
};
if (value.length > 6) {
// we have some custom fields. add them to notes.
if (site.notes === null) {
site.notes = '';
}
else {
site.notes += '\n';
}
for (i = 6; i < value.length; i = i + 2) {
var cfName = value[i];
var cfValue = value[i + 1];
site.notes += (cfName + ': ' + cfValue + '\n');
}
}
sites.push(site);
if (addFolder) {
folders.push({
name: value[0]
});
}
if (hasFolder) {
var relationship = {
key: siteIndex,
value: folderIndex
};
folderRelationships.push(relationship);
}
}
});
success(folders, sites, folderRelationships);
}
});
}
return _service; return _service;
}); });

View File

@ -17,6 +17,7 @@
<option value="padlockcsv">Padlock (csv)</option> <option value="padlockcsv">Padlock (csv)</option>
<option value="1password1pif">1Password (1pif)</option> <option value="1password1pif">1Password (1pif)</option>
<option value="upmcsv">Universal Password Manager (csv)</option> <option value="upmcsv">Universal Password Manager (csv)</option>
<option value="keepercsv">Keeper (csv)</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">