From 41dd6b1f2c2d12bfa23162fa4ff5200620b6e8ac Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 12 Jul 2018 15:53:14 -0400 Subject: [PATCH] dashlane csv importer --- src/importers/dashlaneCsvImporter.ts | 90 ++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/importers/dashlaneCsvImporter.ts diff --git a/src/importers/dashlaneCsvImporter.ts b/src/importers/dashlaneCsvImporter.ts new file mode 100644 index 0000000000..028a79a055 --- /dev/null +++ b/src/importers/dashlaneCsvImporter.ts @@ -0,0 +1,90 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class DashlaneCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + let skip = false; + if (value.length < 2) { + return; + } + + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value[0], '--'); + + if (value.length === 2) { + cipher.login.uris = this.makeUriArray(value[1]); + } else if (value.length === 3) { + cipher.login.uris = this.makeUriArray(value[1]); + cipher.login.username = this.getValueOrDefault(value[2]); + } else if (value.length === 4) { + if (this.isNullOrWhitespace(value[2]) && this.isNullOrWhitespace(value[3])) { + cipher.login.username = value[1]; + cipher.notes = value[2] + '\n' + value[3]; + } else { + cipher.login.username = value[2]; + cipher.notes = value[1] + '\n' + value[3]; + } + } else if (value.length === 5) { + cipher.login.uris = this.makeUriArray(value[1]); + cipher.login.username = this.getValueOrDefault(value[2]); + cipher.login.password = this.getValueOrDefault(value[3]); + cipher.notes = this.getValueOrDefault(value[4]); + } else if (value.length === 6) { + if (this.isNullOrWhitespace(value[2])) { + cipher.login.username = this.getValueOrDefault(value[3]); + cipher.login.password = this.getValueOrDefault(value[4]); + cipher.notes = this.getValueOrDefault(value[5]); + } else { + cipher.login.username = this.getValueOrDefault(value[2]); + cipher.login.password = this.getValueOrDefault(value[3]); + cipher.notes = this.getValueOrDefault(value[4], '') + '\n' + this.getValueOrDefault(value[5], ''); + } + cipher.login.uris = this.makeUriArray(value[1]); + } else if (value.length === 7) { + if (this.isNullOrWhitespace(value[2])) { + cipher.login.username = this.getValueOrDefault(value[3]); + cipher.notes = this.getValueOrDefault(value[4], '') + '\n' + this.getValueOrDefault(value[6], ''); + } else { + cipher.login.username = this.getValueOrDefault(value[2]); + cipher.notes = this.getValueOrDefault(value[3], '') + '\n' + + this.getValueOrDefault(value[4], '') + '\n' + this.getValueOrDefault(value[6], ''); + } + cipher.login.uris = this.makeUriArray(value[1]); + cipher.login.password = this.getValueOrDefault(value[5]); + } else { + for (let i = 1; i < value.length; i++) { + cipher.notes += (value[i] + '\n'); + if (value[i] === 'NO_TYPE') { + skip = true; + break; + } + } + } + + if (skip) { + return; + } + if (this.isNullOrWhitespace(cipher.login.username)) { + cipher.login.username = null; + } + if (this.isNullOrWhitespace(cipher.login.password)) { + cipher.login.password = null; + } + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return result; + } +}