mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-05 09:10:53 +01:00
more importer helpers
This commit is contained in:
parent
4004449aa8
commit
c9fc74c5cb
@ -3,11 +3,6 @@ import { Importer } from './importer';
|
||||
|
||||
import { ImportResult } from '../models/domain/importResult';
|
||||
|
||||
import { CipherView } from '../models/view/cipherView';
|
||||
import { LoginView } from '../models/view/loginView';
|
||||
|
||||
import { CipherType } from '../enums/cipherType';
|
||||
|
||||
export class AviraCsvImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): ImportResult {
|
||||
const result = new ImportResult();
|
||||
@ -18,11 +13,9 @@ export class AviraCsvImporter extends BaseImporter implements Importer {
|
||||
}
|
||||
|
||||
results.forEach((value) => {
|
||||
const cipher = new CipherView();
|
||||
cipher.type = CipherType.Login;
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = this.getValueOrDefault(value.name,
|
||||
this.getValueOrDefault(this.nameFromUrl(value.website), '--'));
|
||||
cipher.login = new LoginView();
|
||||
cipher.login.uris = this.makeUriArray(value.website);
|
||||
cipher.login.password = this.getValueOrDefault(value.password);
|
||||
|
||||
@ -33,6 +26,7 @@ export class AviraCsvImporter extends BaseImporter implements Importer {
|
||||
cipher.notes = this.getValueOrDefault(value.secondary_username);
|
||||
}
|
||||
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
|
@ -2,10 +2,16 @@ import * as papa from 'papaparse';
|
||||
|
||||
import { ImportResult } from '../models/domain/importResult';
|
||||
|
||||
import { CipherView } from '../models/view/cipherView';
|
||||
import { CollectionView } from '../models/view/collectionView';
|
||||
import { LoginUriView } from '../models/view/loginUriView';
|
||||
|
||||
import { Utils } from '../misc/utils';
|
||||
import { FieldView } from '../models/view/fieldView';
|
||||
import { LoginView } from '../models/view/loginView';
|
||||
|
||||
import { CipherType } from '../enums/cipherType';
|
||||
import { FieldType } from '../enums/fieldType';
|
||||
|
||||
export abstract class BaseImporter {
|
||||
organization = false;
|
||||
@ -227,4 +233,58 @@ export abstract class BaseImporter {
|
||||
protected querySelectorAllDirectChild(parentEl: Element, query: string) {
|
||||
return Array.from(parentEl.querySelectorAll(query)).filter((el) => el.parentNode === parentEl);
|
||||
}
|
||||
|
||||
protected initLoginCipher() {
|
||||
const cipher = new CipherView();
|
||||
cipher.favorite = false;
|
||||
cipher.notes = '';
|
||||
cipher.fields = [];
|
||||
cipher.login = new LoginView();
|
||||
cipher.type = CipherType.Login;
|
||||
return cipher;
|
||||
}
|
||||
|
||||
protected cleanupCipher(cipher: CipherView) {
|
||||
if (cipher == null) {
|
||||
return;
|
||||
}
|
||||
if (cipher.type !== CipherType.Login) {
|
||||
cipher.login = null;
|
||||
}
|
||||
if (this.isNullOrWhitespace(cipher.name)) {
|
||||
cipher.name = '--';
|
||||
}
|
||||
if (this.isNullOrWhitespace(cipher.notes)) {
|
||||
cipher.notes = null;
|
||||
} else {
|
||||
cipher.notes = cipher.notes.trim();
|
||||
}
|
||||
if (cipher.fields != null && cipher.fields.length === 0) {
|
||||
cipher.fields = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected processKvp(cipher: CipherView, key: string, value: string) {
|
||||
if (this.isNullOrWhitespace(value)) {
|
||||
return;
|
||||
}
|
||||
if (this.isNullOrWhitespace(key)) {
|
||||
key = '';
|
||||
}
|
||||
if (value.length > 200 || value.search(this.newLineRegex) > -1) {
|
||||
if (cipher.notes == null) {
|
||||
cipher.notes = '';
|
||||
}
|
||||
cipher.notes += (key + ': ' + value + '\n');
|
||||
} else {
|
||||
if (cipher.fields == null) {
|
||||
cipher.fields = [];
|
||||
}
|
||||
const field = new FieldView();
|
||||
field.type = FieldType.Text;
|
||||
field.name = key;
|
||||
field.value = value;
|
||||
cipher.fields.push(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,6 @@ import { Importer } from './importer';
|
||||
|
||||
import { ImportResult } from '../models/domain/importResult';
|
||||
|
||||
import { CipherView } from '../models/view/cipherView';
|
||||
import { LoginView } from '../models/view/loginView';
|
||||
|
||||
import { CipherType } from '../enums/cipherType';
|
||||
|
||||
export class BlurCsvImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): ImportResult {
|
||||
const result = new ImportResult();
|
||||
@ -18,14 +13,12 @@ export class BlurCsvImporter extends BaseImporter implements Importer {
|
||||
}
|
||||
|
||||
results.forEach((value) => {
|
||||
const cipher = new CipherView();
|
||||
cipher.type = CipherType.Login;
|
||||
if (value.label === 'null') {
|
||||
value.label = null;
|
||||
}
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = this.getValueOrDefault(value.label,
|
||||
this.getValueOrDefault(this.nameFromUrl(value.domain), '--'));
|
||||
cipher.login = new LoginView();
|
||||
cipher.login.uris = this.makeUriArray(value.domain);
|
||||
cipher.login.password = this.getValueOrDefault(value.password);
|
||||
|
||||
@ -36,6 +29,7 @@ export class BlurCsvImporter extends BaseImporter implements Importer {
|
||||
cipher.notes = this.getValueOrDefault(value.username);
|
||||
}
|
||||
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
|
@ -3,11 +3,7 @@ import { Importer } from './importer';
|
||||
|
||||
import { ImportResult } from '../models/domain/importResult';
|
||||
|
||||
import { CipherView } from '../models/view/cipherView';
|
||||
import { FolderView } from '../models/view/folderView';
|
||||
import { LoginView } from '../models/view/loginView';
|
||||
|
||||
import { CipherType } from '../enums/cipherType';
|
||||
|
||||
export class KeePassXCsvImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): ImportResult {
|
||||
@ -50,15 +46,13 @@ export class KeePassXCsvImporter extends BaseImporter implements Importer {
|
||||
result.folderRelationships.push([result.ciphers.length, folderIndex]);
|
||||
}
|
||||
|
||||
const cipher = new CipherView();
|
||||
cipher.type = CipherType.Login;
|
||||
cipher.favorite = false;
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.notes = this.getValueOrDefault(value.Notes);
|
||||
cipher.name = this.getValueOrDefault(value.Title, '--');
|
||||
cipher.login = new LoginView();
|
||||
cipher.login.username = this.getValueOrDefault(value.Username);
|
||||
cipher.login.password = this.getValueOrDefault(value.Password);
|
||||
cipher.login.uris = this.makeUriArray(value.URL);
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
|
@ -3,14 +3,8 @@ import { Importer } from './importer';
|
||||
|
||||
import { ImportResult } from '../models/domain/importResult';
|
||||
|
||||
import { CipherView } from '../models/view/cipherView';
|
||||
import { CollectionView } from '../models/view/collectionView';
|
||||
import { FieldView } from '../models/view/fieldView';
|
||||
import { FolderView } from '../models/view/folderView';
|
||||
import { LoginView } from '../models/view/loginView';
|
||||
|
||||
import { CipherType } from '../enums/cipherType';
|
||||
import { FieldType } from '../enums/fieldType';
|
||||
|
||||
export class PadlockCsvImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): ImportResult {
|
||||
@ -84,13 +78,8 @@ export class PadlockCsvImporter extends BaseImporter implements Importer {
|
||||
}
|
||||
}
|
||||
|
||||
const cipher = new CipherView();
|
||||
cipher.type = CipherType.Login;
|
||||
cipher.favorite = false;
|
||||
cipher.notes = '';
|
||||
cipher.fields = [];
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = this.getValueOrDefault(value[0], '--');
|
||||
cipher.login = new LoginView();
|
||||
|
||||
for (let i = 2; i < value.length; i++) {
|
||||
const header = headers[i].trim().toLowerCase();
|
||||
@ -105,27 +94,11 @@ export class PadlockCsvImporter extends BaseImporter implements Importer {
|
||||
} else if (this.uriFieldNames.indexOf(header) > -1) {
|
||||
cipher.login.uris = this.makeUriArray(value[i]);
|
||||
} else {
|
||||
if (value[i].length > 200 || value[i].search(this.newLineRegex) > -1) {
|
||||
cipher.notes += (headers[i] + ': ' + value[i] + '\n');
|
||||
} else {
|
||||
const field = new FieldView();
|
||||
field.type = FieldType.Text;
|
||||
field.name = headers[i];
|
||||
field.value = value[i];
|
||||
cipher.fields.push(field);
|
||||
}
|
||||
this.processKvp(cipher, headers[i], value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isNullOrWhitespace(cipher.notes)) {
|
||||
cipher.notes = null;
|
||||
} else {
|
||||
cipher.notes = cipher.notes.trim();
|
||||
}
|
||||
if (cipher.fields.length === 0) {
|
||||
cipher.fields = null;
|
||||
}
|
||||
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
|
@ -3,14 +3,10 @@ import { Importer } from './importer';
|
||||
|
||||
import { ImportResult } from '../models/domain/importResult';
|
||||
|
||||
import { CipherView } from '../models/view/cipherView';
|
||||
import { FieldView } from '../models/view/fieldView';
|
||||
import { FolderView } from '../models/view/folderView';
|
||||
import { LoginView } from '../models/view/loginView';
|
||||
import { SecureNoteView } from '../models/view/secureNoteView';
|
||||
|
||||
import { CipherType } from '../enums/cipherType';
|
||||
import { FieldType } from '../enums/fieldType';
|
||||
import { SecureNoteType } from '../enums/secureNoteType';
|
||||
|
||||
export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
||||
@ -55,11 +51,8 @@ export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
||||
}
|
||||
}
|
||||
|
||||
const cipher = new CipherView();
|
||||
cipher.favorite = false;
|
||||
cipher.notes = '';
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = this.getValueOrDefault(cardEl.getAttribute('title'), '--');
|
||||
cipher.fields = null;
|
||||
|
||||
const cardType = cardEl.getAttribute('type');
|
||||
if (cardType === 'note') {
|
||||
@ -67,8 +60,6 @@ export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
||||
cipher.secureNote = new SecureNoteView();
|
||||
cipher.secureNote.type = SecureNoteType.Generic;
|
||||
} else {
|
||||
cipher.type = CipherType.Login;
|
||||
cipher.login = new LoginView();
|
||||
Array.from(this.querySelectorAllDirectChild(cardEl, 'field')).forEach((fieldEl) => {
|
||||
const text = fieldEl.textContent;
|
||||
if (this.isNullOrWhitespace(text)) {
|
||||
@ -84,17 +75,8 @@ export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
||||
cipher.notes += (text + '\n');
|
||||
} else if (fieldType === 'weblogin' || fieldType === 'website') {
|
||||
cipher.login.uris = this.makeUriArray(text);
|
||||
} else if (text.length > 200) {
|
||||
cipher.notes += (name + ': ' + text + '\n');
|
||||
} else {
|
||||
if (cipher.fields == null) {
|
||||
cipher.fields = [];
|
||||
}
|
||||
const field = new FieldView();
|
||||
field.name = name;
|
||||
field.value = text;
|
||||
field.type = FieldType.Text;
|
||||
cipher.fields.push(field);
|
||||
this.processKvp(cipher, name, text);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -103,11 +85,7 @@ export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
||||
cipher.notes += (notesEl.textContent + '\n');
|
||||
});
|
||||
|
||||
cipher.notes = cipher.notes.trim();
|
||||
if (cipher.notes === '') {
|
||||
cipher.notes = null;
|
||||
}
|
||||
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user