1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

convert to processFolder helper

This commit is contained in:
Kyle Spearrin 2018-07-12 09:57:08 -04:00
parent 7ca2a40478
commit 89779db1f2
5 changed files with 8 additions and 116 deletions

View File

@ -47,29 +47,7 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer {
result.collectionRelationships.push([result.ciphers.length, collectionIndex]);
});
} else if (!this.organization) {
let folderIndex = result.folders.length;
const hasFolder = !this.isNullOrWhitespace(value.folder);
let addFolder = hasFolder;
if (hasFolder) {
for (let i = 0; i < result.folders.length; i++) {
if (result.folders[i].name === value.folder) {
addFolder = false;
folderIndex = i;
break;
}
}
}
if (addFolder) {
const f = new FolderView();
f.name = value.folder;
result.folders.push(f);
}
if (hasFolder) {
result.folderRelationships.push([result.ciphers.length, folderIndex]);
}
this.processFolder(result, value.folder);
}
const cipher = new CipherView();

View File

@ -22,29 +22,7 @@ export class KeePassXCsvImporter extends BaseImporter implements Importer {
value.Group = !this.isNullOrWhitespace(value.Group) && value.Group.startsWith('Root/') ?
value.Group.replace('Root/', '') : value.Group;
const groupName = !this.isNullOrWhitespace(value.Group) ? value.Group.split('/').join(' > ') : null;
let folderIndex = result.folders.length;
const hasFolder = groupName != null;
let addFolder = hasFolder;
if (hasFolder) {
for (let i = 0; i < result.folders.length; i++) {
if (result.folders[i].name === groupName) {
addFolder = false;
folderIndex = i;
break;
}
}
}
if (addFolder) {
const f = new FolderView();
f.name = groupName;
result.folders.push(f);
}
if (hasFolder) {
result.folderRelationships.push([result.ciphers.length, folderIndex]);
}
this.processFolder(result, groupName);
const cipher = this.initLoginCipher();
cipher.notes = this.getValueOrDefault(value.Notes);

View File

@ -19,29 +19,7 @@ export class KeeperCsvImporter extends BaseImporter implements Importer {
return;
}
let folderIndex = result.folders.length;
const hasFolder = !this.isNullOrWhitespace(value[0]);
let addFolder = hasFolder;
if (hasFolder) {
for (let i = 0; i < result.folders.length; i++) {
if (result.folders[i].name === value[0]) {
addFolder = false;
folderIndex = i;
break;
}
}
}
if (addFolder) {
const f = new FolderView();
f.name = value[0];
result.folders.push(f);
}
if (hasFolder) {
result.folderRelationships.push([result.ciphers.length, folderIndex]);
}
this.processFolder(result, value[0]);
const cipher = this.initLoginCipher();
cipher.notes = this.getValueOrDefault(value[5]) + '\n';
cipher.name = this.getValueOrDefault(value[1], '--');

View File

@ -52,29 +52,8 @@ export class PadlockCsvImporter extends BaseImporter implements Importer {
});
} else {
const tags = (value[1] as string).split(',');
let folderIndex = result.folders.length;
const hasFolder = tags.length > 0 && !this.isNullOrWhitespace(tags[0].trim());
let addFolder = hasFolder;
const tag = tags[0].trim();
if (hasFolder) {
for (let i = 0; i < result.folders.length; i++) {
if (result.folders[i].name === tag) {
addFolder = false;
folderIndex = i;
break;
}
}
}
if (addFolder) {
const f = new FolderView();
f.name = tag;
result.folders.push(f);
}
if (hasFolder) {
result.folderRelationships.push([result.ciphers.length, folderIndex]);
}
const tag = tags.length > 0 ? tags[0].trim() : null;
this.processFolder(result, tag);
}
}

View File

@ -17,30 +17,9 @@ export class PasswordDragonXmlImporter extends BaseImporter implements Importer
const records = doc.querySelectorAll('PasswordManager > record');
Array.from(records).forEach((record) => {
const category = this.querySelectorDirectChild(record, 'Category');
let folderIndex = result.folders.length;
const hasFolder = category != null && !this.isNullOrWhitespace(category.textContent) &&
category.textContent !== 'Unfiled';
let addFolder = hasFolder;
if (hasFolder) {
for (let i = 0; i < result.folders.length; i++) {
if (result.folders[i].name === category.textContent) {
addFolder = false;
folderIndex = i;
break;
}
}
}
if (addFolder) {
const f = new FolderView();
f.name = category.textContent;
result.folders.push(f);
}
if (hasFolder) {
result.folderRelationships.push([result.ciphers.length, folderIndex]);
}
const categoryText = category != null && !this.isNullOrWhitespace(category.textContent) &&
category.textContent !== 'Unfiled' ? category.textContent : null;
this.processFolder(result, categoryText);
const accountName = this.querySelectorDirectChild(record, 'Account-Name');
const userId = this.querySelectorDirectChild(record, 'User-Id');