From e5d060c80b6c6ca4f863534ec73ed410bb30a21e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 23 Jul 2018 11:41:12 -0400 Subject: [PATCH] passkeep csv importer --- src/importers/passkeepCsvImporter.ts | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/importers/passkeepCsvImporter.ts diff --git a/src/importers/passkeepCsvImporter.ts b/src/importers/passkeepCsvImporter.ts new file mode 100644 index 00000000000..b51ffdaec5a --- /dev/null +++ b/src/importers/passkeepCsvImporter.ts @@ -0,0 +1,39 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class PassKeepCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + this.processFolder(result, this.getValue('category', value)); + const cipher = this.initLoginCipher(); + cipher.notes = this.getValue('description', value); + cipher.name = this.getValueOrDefault(this.getValue('title', value), '--'); + cipher.login.username = this.getValue('username', value); + cipher.login.password = this.getValue('password', value); + cipher.login.uris = this.makeUriArray(this.getValue('site', value)); + this.processKvp(cipher, 'Password 2', this.getValue('password2', value)); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + if (this.organization) { + this.moveFoldersToCollections(result); + } + + result.success = true; + return result; + } + + private getValue(key: string, value: any) { + return this.getValueOrDefault(value[key], this.getValueOrDefault(value[(' ' + key)])); + } +}