2019-11-25 22:10:51 +01:00
|
|
|
import { BaseImporter } from './baseImporter';
|
|
|
|
import { Importer } from './importer';
|
|
|
|
|
|
|
|
import { ImportResult } from '../models/domain/importResult';
|
|
|
|
|
|
|
|
export class CodebookCsvImporter extends BaseImporter implements Importer {
|
2020-12-05 03:05:11 +01:00
|
|
|
parse(data: string): Promise<ImportResult> {
|
2019-11-25 22:10:51 +01:00
|
|
|
const result = new ImportResult();
|
|
|
|
const results = this.parseCsv(data, true);
|
|
|
|
if (results == null) {
|
|
|
|
result.success = false;
|
2020-12-05 03:05:11 +01:00
|
|
|
return Promise.resolve(result);
|
2019-11-25 22:10:51 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 16:49:23 +01:00
|
|
|
results.forEach(value => {
|
2019-11-25 22:10:51 +01:00
|
|
|
this.processFolder(result, this.getValueOrDefault(value.Category));
|
|
|
|
|
|
|
|
const cipher = this.initLoginCipher();
|
|
|
|
cipher.favorite = this.getValueOrDefault(value.Favorite) === 'True';
|
|
|
|
cipher.name = this.getValueOrDefault(value.Entry, '--');
|
|
|
|
cipher.notes = this.getValueOrDefault(value.Note);
|
|
|
|
cipher.login.username = this.getValueOrDefault(value.Username, value.Email);
|
|
|
|
cipher.login.password = this.getValueOrDefault(value.Password);
|
|
|
|
cipher.login.totp = this.getValueOrDefault(value.TOTP);
|
|
|
|
cipher.login.uris = this.makeUriArray(value.Website);
|
|
|
|
|
|
|
|
if (!this.isNullOrWhitespace(value.Username)) {
|
|
|
|
this.processKvp(cipher, 'Email', value.Email);
|
|
|
|
}
|
|
|
|
this.processKvp(cipher, 'Phone', value.Phone);
|
|
|
|
this.processKvp(cipher, 'PIN', value.PIN);
|
|
|
|
this.processKvp(cipher, 'Account', value.Account);
|
|
|
|
this.processKvp(cipher, 'Date', value.Date);
|
|
|
|
|
2019-11-26 14:34:45 +01:00
|
|
|
this.convertToNoteIfNeeded(cipher);
|
2019-11-25 22:10:51 +01:00
|
|
|
this.cleanupCipher(cipher);
|
|
|
|
result.ciphers.push(cipher);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.organization) {
|
|
|
|
this.moveFoldersToCollections(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
result.success = true;
|
2020-12-05 03:05:11 +01:00
|
|
|
return Promise.resolve(result);
|
2019-11-25 22:10:51 +01:00
|
|
|
}
|
|
|
|
}
|