importers parse

This commit is contained in:
Kyle Spearrin 2018-06-23 14:46:23 -04:00
parent 154c087b97
commit ce40a803d8
5 changed files with 15 additions and 7 deletions

View File

@ -50,15 +50,15 @@ export abstract class BaseImporter {
const result = papa.parse(data, { const result = papa.parse(data, {
header: header, header: header,
encoding: 'UTF-8', encoding: 'UTF-8',
skipEmptyLines: false,
}); });
if (result.errors != null && result.errors.length > 0) { if (result.errors != null && result.errors.length > 0) {
result.errors.forEach((e) => { result.errors.forEach((e) => {
// tslint:disable-next-line // tslint:disable-next-line
console.warn('Error parsing row ' + e.row + ': ' + e.message); console.warn('Error parsing row ' + e.row + ': ' + e.message);
}); });
return null;
} }
return result.data; return result.data && result.data.length > 0 ? result.data : null;
} }
protected parseSingleRowCsv(rowData: string) { protected parseSingleRowCsv(rowData: string) {

View File

@ -14,7 +14,7 @@ import { FieldType } from '../enums/fieldType';
import { SecureNoteType } from '../enums/secureNoteType'; import { SecureNoteType } from '../enums/secureNoteType';
export class BitwardenCsvImporter extends BaseImporter implements Importer { export class BitwardenCsvImporter extends BaseImporter implements Importer {
import(data: string): ImportResult { parse(data: string): ImportResult {
const result = new ImportResult(); const result = new ImportResult();
const results = this.parseCsv(data, true); const results = this.parseCsv(data, true);
if (results == null) { if (results == null) {
@ -104,6 +104,7 @@ export class BitwardenCsvImporter extends BaseImporter implements Importer {
} }
}); });
result.success = true;
return result; return result;
} }
} }

View File

@ -1,5 +1,5 @@
import { ImportResult } from '../models/domain/importResult'; import { ImportResult } from '../models/domain/importResult';
export interface Importer { export interface Importer {
import(data: string): ImportResult; parse(data: string): ImportResult;
} }

View File

@ -10,7 +10,7 @@ import { LoginView } from '../models/view/loginView';
import { CipherType } from '../enums/cipherType'; import { CipherType } from '../enums/cipherType';
export class KeePassXCsvImporter extends BaseImporter implements Importer { export class KeePassXCsvImporter extends BaseImporter implements Importer {
import(data: string): ImportResult { parse(data: string): ImportResult {
const result = new ImportResult(); const result = new ImportResult();
const results = this.parseCsv(data, true); const results = this.parseCsv(data, true);
if (results == null) { if (results == null) {
@ -62,6 +62,7 @@ export class KeePassXCsvImporter extends BaseImporter implements Importer {
} }
}); });
result.success = true;
return result; return result;
} }
} }

View File

@ -14,7 +14,7 @@ import { CipherType } from '../enums/cipherType';
import { SecureNoteType } from '../enums/secureNoteType'; import { SecureNoteType } from '../enums/secureNoteType';
export class LastPassCsvImporter extends BaseImporter implements Importer { export class LastPassCsvImporter extends BaseImporter implements Importer {
import(data: string): ImportResult { parse(data: string): ImportResult {
const result = new ImportResult(); const result = new ImportResult();
const results = this.parseCsv(data, true); const results = this.parseCsv(data, true);
if (results == null) { if (results == null) {
@ -22,7 +22,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
return result; return result;
} }
results.forEach((value) => { results.forEach((value, index) => {
let folderIndex = result.folders.length; let folderIndex = result.folders.length;
const cipherIndex = result.ciphers.length; const cipherIndex = result.ciphers.length;
const hasFolder = this.getValueOrDefault(value.grouping, '(none)') !== '(none)'; const hasFolder = this.getValueOrDefault(value.grouping, '(none)') !== '(none)';
@ -39,6 +39,11 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
} }
const cipher = this.buildBaseCipher(value); const cipher = this.buildBaseCipher(value);
if (cipher.name === '--' && results.length > 2 && index >= (results.length - 2)) {
// LastPass file traditionally has two empty lines at the end
return;
}
if (cipher.type === CipherType.Login) { if (cipher.type === CipherType.Login) {
cipher.notes = this.getValueOrDefault(value.extra); cipher.notes = this.getValueOrDefault(value.extra);
cipher.login = new LoginView(); cipher.login = new LoginView();
@ -75,6 +80,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
} }
}); });
result.success = true;
return result; return result;
} }