fix 1password csv importer
This commit is contained in:
parent
b816ddddff
commit
0a30c7eb1e
|
@ -6,7 +6,7 @@ import { ImportResult } from '../models/domain/importResult';
|
||||||
import { CipherType } from '../enums/cipherType';
|
import { CipherType } from '../enums/cipherType';
|
||||||
import { CardView } from '../models/view';
|
import { CardView } from '../models/view';
|
||||||
|
|
||||||
const IgnoredProperties = ['ainfo', 'autosubmit', 'notesPlain', 'ps', 'scope', 'tags', 'title', 'uuid'];
|
const IgnoredProperties = ['ainfo', 'autosubmit', 'notesplain', 'ps', 'scope', 'tags', 'title', 'uuid'];
|
||||||
|
|
||||||
export class OnePasswordWinCsvImporter extends BaseImporter implements Importer {
|
export class OnePasswordWinCsvImporter extends BaseImporter implements Importer {
|
||||||
parse(data: string): ImportResult {
|
parse(data: string): ImportResult {
|
||||||
|
@ -18,15 +18,16 @@ export class OnePasswordWinCsvImporter extends BaseImporter implements Importer
|
||||||
}
|
}
|
||||||
|
|
||||||
results.forEach((value) => {
|
results.forEach((value) => {
|
||||||
if (this.isNullOrWhitespace(value.title)) {
|
if (this.isNullOrWhitespace(this.getProp(value, 'title'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cipher = this.initLoginCipher();
|
const cipher = this.initLoginCipher();
|
||||||
cipher.name = this.getValueOrDefault(value.title, '--');
|
cipher.name = this.getValueOrDefault(this.getProp(value, 'title'), '--');
|
||||||
cipher.notes = this.getValueOrDefault(value.notesPlain, '') + '\n';
|
cipher.notes = this.getValueOrDefault(this.getProp(value, 'notesPlain'), '') + '\n';
|
||||||
|
|
||||||
if (!this.isNullOrWhitespace(value.number) && !this.isNullOrWhitespace(value['expiry date'])) {
|
if (!this.isNullOrWhitespace(this.getProp(value, 'number')) &&
|
||||||
|
!this.isNullOrWhitespace(this.getProp(value, 'expiry date'))) {
|
||||||
cipher.type = CipherType.Card;
|
cipher.type = CipherType.Card;
|
||||||
cipher.card = new CardView();
|
cipher.card = new CardView();
|
||||||
}
|
}
|
||||||
|
@ -37,30 +38,31 @@ export class OnePasswordWinCsvImporter extends BaseImporter implements Importer
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lowerProp = property.toLowerCase();
|
||||||
if (cipher.type === CipherType.Login) {
|
if (cipher.type === CipherType.Login) {
|
||||||
if (this.isNullOrWhitespace(cipher.login.password) && property === 'password') {
|
if (this.isNullOrWhitespace(cipher.login.password) && lowerProp === 'password') {
|
||||||
cipher.login.password = value[property];
|
cipher.login.password = value[property];
|
||||||
continue;
|
continue;
|
||||||
} else if (this.isNullOrWhitespace(cipher.login.username) && property === 'username') {
|
} else if (this.isNullOrWhitespace(cipher.login.username) && lowerProp === 'username') {
|
||||||
cipher.login.username = value[property];
|
cipher.login.username = value[property];
|
||||||
continue;
|
continue;
|
||||||
} else if ((cipher.login.uris == null || cipher.login.uri.length === 0) && property === 'urls') {
|
} else if ((cipher.login.uris == null || cipher.login.uri.length === 0) && lowerProp === 'urls') {
|
||||||
const urls = value[property].split(this.newLineRegex);
|
const urls = value[property].split(this.newLineRegex);
|
||||||
cipher.login.uris = this.makeUriArray(urls);
|
cipher.login.uris = this.makeUriArray(urls);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (cipher.type === CipherType.Card) {
|
} else if (cipher.type === CipherType.Card) {
|
||||||
if (this.isNullOrWhitespace(cipher.card.number) && property === 'number') {
|
if (this.isNullOrWhitespace(cipher.card.number) && lowerProp === 'number') {
|
||||||
cipher.card.number = value[property];
|
cipher.card.number = value[property];
|
||||||
cipher.card.brand = this.getCardBrand(value.number);
|
cipher.card.brand = this.getCardBrand(this.getProp(value, 'number'));
|
||||||
continue;
|
continue;
|
||||||
} else if (this.isNullOrWhitespace(cipher.card.code) && property === 'verification number') {
|
} else if (this.isNullOrWhitespace(cipher.card.code) && lowerProp === 'verification number') {
|
||||||
cipher.card.code = value[property];
|
cipher.card.code = value[property];
|
||||||
continue;
|
continue;
|
||||||
} else if (this.isNullOrWhitespace(cipher.card.cardholderName) && property === 'cardholder name') {
|
} else if (this.isNullOrWhitespace(cipher.card.cardholderName) && lowerProp === 'cardholder name') {
|
||||||
cipher.card.cardholderName = value[property];
|
cipher.card.cardholderName = value[property];
|
||||||
continue;
|
continue;
|
||||||
} else if (this.isNullOrWhitespace(cipher.card.expiration) && property === 'expiry date' &&
|
} else if (this.isNullOrWhitespace(cipher.card.expiration) && lowerProp === 'expiry date' &&
|
||||||
value[property].length === 6) {
|
value[property].length === 6) {
|
||||||
cipher.card.expMonth = (value[property] as string).substr(4, 2);
|
cipher.card.expMonth = (value[property] as string).substr(4, 2);
|
||||||
if (cipher.card.expMonth[0] === '0') {
|
if (cipher.card.expMonth[0] === '0') {
|
||||||
|
@ -68,14 +70,15 @@ export class OnePasswordWinCsvImporter extends BaseImporter implements Importer
|
||||||
}
|
}
|
||||||
cipher.card.expYear = (value[property] as string).substr(0, 4);
|
cipher.card.expYear = (value[property] as string).substr(0, 4);
|
||||||
continue;
|
continue;
|
||||||
} else if (property === 'type') {
|
} else if (lowerProp === 'type') {
|
||||||
// Skip since brand was determined from number above
|
// Skip since brand was determined from number above
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IgnoredProperties.indexOf(property) === -1 && !property.startsWith('section:')) {
|
if (IgnoredProperties.indexOf(lowerProp) === -1 && !lowerProp.startsWith('section:') &&
|
||||||
if (altUsername == null && property === 'email') {
|
!lowerProp.startsWith('section ')) {
|
||||||
|
if (altUsername == null && lowerProp === 'email') {
|
||||||
altUsername = value[property];
|
altUsername = value[property];
|
||||||
}
|
}
|
||||||
this.processKvp(cipher, property, value[property]);
|
this.processKvp(cipher, property, value[property]);
|
||||||
|
@ -95,4 +98,8 @@ export class OnePasswordWinCsvImporter extends BaseImporter implements Importer
|
||||||
result.success = true;
|
result.success = true;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getProp(obj: any, name: string): any {
|
||||||
|
return obj[name] || obj[name.toUpperCase()];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue