diff --git a/src/importers/bitwardenCsvImporter.ts b/src/importers/bitwardenCsvImporter.ts index 76ea7aa08b..c8414f5ac2 100644 --- a/src/importers/bitwardenCsvImporter.ts +++ b/src/importers/bitwardenCsvImporter.ts @@ -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(); diff --git a/src/importers/keepassxCsvImporter.ts b/src/importers/keepassxCsvImporter.ts index c679a45cec..7d99a33909 100644 --- a/src/importers/keepassxCsvImporter.ts +++ b/src/importers/keepassxCsvImporter.ts @@ -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); diff --git a/src/importers/keeperCsvImporter.ts b/src/importers/keeperCsvImporter.ts index 6e4cee1737..27a520e52f 100644 --- a/src/importers/keeperCsvImporter.ts +++ b/src/importers/keeperCsvImporter.ts @@ -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], '--'); diff --git a/src/importers/padlockCsvImporter.ts b/src/importers/padlockCsvImporter.ts index 7e0cd4f153..b85e4113bc 100644 --- a/src/importers/padlockCsvImporter.ts +++ b/src/importers/padlockCsvImporter.ts @@ -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); } } diff --git a/src/importers/passwordDragonXmlImporter.ts b/src/importers/passwordDragonXmlImporter.ts index 9528b7ede9..5b5db151fb 100644 --- a/src/importers/passwordDragonXmlImporter.ts +++ b/src/importers/passwordDragonXmlImporter.ts @@ -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');