update password boss importer

This commit is contained in:
Kyle Spearrin 2019-12-20 13:05:22 -05:00
parent 77282e7b0f
commit a7517a3621
1 changed files with 31 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import { Importer } from './importer';
import { ImportResult } from '../models/domain/importResult'; import { ImportResult } from '../models/domain/importResult';
import { CardView } from '../models/view/cardView'; import { CardView } from '../models/view/cardView';
import { FolderView } from '../models/view/folderView';
import { CipherType } from '../enums/cipherType'; import { CipherType } from '../enums/cipherType';
@ -11,16 +12,32 @@ export class PasswordBossJsonImporter extends BaseImporter implements Importer {
parse(data: string): ImportResult { parse(data: string): ImportResult {
const result = new ImportResult(); const result = new ImportResult();
const results = JSON.parse(data); const results = JSON.parse(data);
if (results == null) { if (results == null || results.items == null) {
result.success = false; result.success = false;
return result; return result;
} }
results.forEach((value: any) => { const foldersMap = new Map<string, string>();
results.folders.forEach((value: any) => {
foldersMap.set(value.id, value.name);
});
const foldersIndexMap = new Map<string, number>();
foldersMap.forEach((val, key) => {
foldersIndexMap.set(key, result.folders.length);
const f = new FolderView();
f.name = val;
result.folders.push(f);
});
results.items.forEach((value: any) => {
const cipher = this.initLoginCipher(); const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(value.name, '--'); cipher.name = this.getValueOrDefault(value.name, '--');
cipher.login.uris = this.makeUriArray(value.login_url); cipher.login.uris = this.makeUriArray(value.login_url);
if (value.folder != null && foldersIndexMap.has(value.folder)) {
result.folderRelationships.push([result.ciphers.length, foldersIndexMap.get(value.folder)]);
}
if (value.identifiers == null) { if (value.identifiers == null) {
return; return;
} }
@ -44,6 +61,13 @@ export class PasswordBossJsonImporter extends BaseImporter implements Importer {
continue; continue;
} }
if (property === 'custom_fields') {
valObj.forEach((cf: any) => {
this.processKvp(cipher, cf.name, cf.value);
});
continue;
}
if (cipher.type === CipherType.Card) { if (cipher.type === CipherType.Card) {
if (property === 'cardNumber') { if (property === 'cardNumber') {
cipher.card.number = val; cipher.card.number = val;
@ -66,12 +90,16 @@ export class PasswordBossJsonImporter extends BaseImporter implements Importer {
continue; continue;
} }
} else { } else {
if (property === 'username') { if ((property === 'username' || property === 'email') &&
this.isNullOrWhitespace(cipher.login.username)) {
cipher.login.username = val; cipher.login.username = val;
continue; continue;
} else if (property === 'password') { } else if (property === 'password') {
cipher.login.password = val; cipher.login.password = val;
continue; continue;
} else if (property === 'totp') {
cipher.login.totp = val;
continue;
} else if ((cipher.login.uris == null || cipher.login.uris.length === 0) && } else if ((cipher.login.uris == null || cipher.login.uris.length === 0) &&
this.uriFieldNames.indexOf(property) > -1) { this.uriFieldNames.indexOf(property) > -1) {
cipher.login.uris = this.makeUriArray(val); cipher.login.uris = this.makeUriArray(val);