mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
parse extra note fields into custom fields
This commit is contained in:
parent
eecd774b13
commit
3c6f6dbe2f
@ -166,7 +166,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
|
|||||||
if (typeParts.length > 1 && typeParts[0] === 'NoteType' &&
|
if (typeParts.length > 1 && typeParts[0] === 'NoteType' &&
|
||||||
(typeParts[1] === 'Credit Card' || typeParts[1] === 'Address')) {
|
(typeParts[1] === 'Credit Card' || typeParts[1] === 'Address')) {
|
||||||
if (typeParts[1] === 'Credit Card') {
|
if (typeParts[1] === 'Credit Card') {
|
||||||
const mappedData = this.parseSecureNoteMapping<CardView>(extraParts, {
|
const mappedData = this.parseSecureNoteMapping<CardView>(cipher, extraParts, {
|
||||||
'Number': 'number',
|
'Number': 'number',
|
||||||
'Name on Card': 'cardholderName',
|
'Name on Card': 'cardholderName',
|
||||||
'Security Code': 'code',
|
'Security Code': 'code',
|
||||||
@ -175,29 +175,31 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
|
|||||||
'Expiration Date': 'expMonth',
|
'Expiration Date': 'expMonth',
|
||||||
});
|
});
|
||||||
|
|
||||||
const exp = mappedData[0].expMonth;
|
if (this.isNullOrWhitespace(mappedData.expMonth) || mappedData.expMonth === ',') {
|
||||||
if (exp === ',' || this.isNullOrWhitespace(exp)) {
|
|
||||||
// No expiration data
|
// No expiration data
|
||||||
delete mappedData[0].expMonth;
|
mappedData.expMonth = null;
|
||||||
} else {
|
} else {
|
||||||
const [monthString, year] = exp.split(',');
|
const [monthString, year] = mappedData.expMonth.split(',');
|
||||||
// Parse month name into number
|
// Parse month name into number
|
||||||
if (!this.isNullOrWhitespace(monthString)) {
|
if (!this.isNullOrWhitespace(monthString)) {
|
||||||
const month = new Date(Date.parse(monthString + '1, 2012')).getMonth() + 1;
|
const month = new Date(Date.parse(monthString.trim() + ' 1, 2012')).getMonth() + 1;
|
||||||
mappedData[0].expMonth = month.toString();
|
if (isNaN(month)) {
|
||||||
|
mappedData.expMonth = null;
|
||||||
} else {
|
} else {
|
||||||
delete mappedData[0].expMonth;
|
mappedData.expMonth = month.toString();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mappedData.expMonth = null;
|
||||||
}
|
}
|
||||||
if (!this.isNullOrWhitespace(year)) {
|
if (!this.isNullOrWhitespace(year)) {
|
||||||
mappedData[0].expYear = year;
|
mappedData.expYear = year;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cipher.type = CipherType.Card;
|
cipher.type = CipherType.Card;
|
||||||
cipher.card = mappedData[0];
|
cipher.card = mappedData;
|
||||||
cipher.notes = mappedData[1];
|
|
||||||
} else if (typeParts[1] === 'Address') {
|
} else if (typeParts[1] === 'Address') {
|
||||||
const mappedData = this.parseSecureNoteMapping<IdentityView>(extraParts, {
|
const mappedData = this.parseSecureNoteMapping<IdentityView>(cipher, extraParts, {
|
||||||
'Title': 'title',
|
'Title': 'title',
|
||||||
'First Name': 'firstName',
|
'First Name': 'firstName',
|
||||||
'Last Name': 'lastName',
|
'Last Name': 'lastName',
|
||||||
@ -214,8 +216,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
|
|||||||
'Username': 'username',
|
'Username': 'username',
|
||||||
});
|
});
|
||||||
cipher.type = CipherType.Identity;
|
cipher.type = CipherType.Identity;
|
||||||
cipher.identity = mappedData[0];
|
cipher.identity = mappedData;
|
||||||
cipher.notes = mappedData[1];
|
|
||||||
}
|
}
|
||||||
processedNote = true;
|
processedNote = true;
|
||||||
}
|
}
|
||||||
@ -228,8 +229,7 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseSecureNoteMapping<T>(extraParts: string[], map: any): [T, string] {
|
private parseSecureNoteMapping<T>(cipher: CipherView, extraParts: string[], map: any): T {
|
||||||
let notes: string = null;
|
|
||||||
const dataObj: any = {};
|
const dataObj: any = {};
|
||||||
|
|
||||||
let processingNotes = false;
|
let processingNotes = false;
|
||||||
@ -255,26 +255,21 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (processingNotes) {
|
if (processingNotes) {
|
||||||
notes += ('\n' + extraPart);
|
cipher.notes += ('\n' + extraPart);
|
||||||
} else if (key === 'Notes') {
|
} else if (key === 'Notes') {
|
||||||
if (!this.isNullOrWhitespace(notes)) {
|
if (!this.isNullOrWhitespace(cipher.notes)) {
|
||||||
notes += ('\n' + val);
|
cipher.notes += ('\n' + val);
|
||||||
} else {
|
} else {
|
||||||
notes = val;
|
cipher.notes = val;
|
||||||
}
|
}
|
||||||
processingNotes = true;
|
processingNotes = true;
|
||||||
} else if (map.hasOwnProperty(key)) {
|
} else if (map.hasOwnProperty(key)) {
|
||||||
dataObj[map[key]] = val;
|
dataObj[map[key]] = val;
|
||||||
} else {
|
} else {
|
||||||
if (!this.isNullOrWhitespace(notes)) {
|
this.processKvp(cipher, key, val);
|
||||||
notes += '\n';
|
|
||||||
} else {
|
|
||||||
notes = '';
|
|
||||||
}
|
|
||||||
notes += (key + ': ' + val);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return [dataObj as T, notes];
|
return dataObj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user