1
0
mirror of https://github.com/bitwarden/browser synced 2024-12-28 19:02:42 +01:00

feat: add an importer for Safari (CSV) (#512)

* feat(importers/safariCsvImporter): add the importer for Safari (CSV)

* Revert changes to package-lock.json

Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
This commit is contained in:
pan93412 2021-10-26 15:00:03 +08:00 committed by GitHub
parent 71f8ef601f
commit 257de6517c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import { BaseImporter } from './baseImporter';
import { Importer } from './importer';
import { ImportResult } from '../models/domain/importResult';
export class SafariCsvImporter extends BaseImporter implements Importer {
parse(data: string): Promise<ImportResult> {
const result = new ImportResult();
const results = this.parseCsv(data, true);
if (results == null) {
result.success = false;
return Promise.resolve(result);
}
results.forEach(value => {
const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(value.Title, '--');
cipher.login.username = this.getValueOrDefault(value.Username);
cipher.login.password = this.getValueOrDefault(value.Password);
cipher.login.uris = this.makeUriArray(value.Url);
cipher.login.totp = this.getValueOrDefault(value.OTPAuth);
this.cleanupCipher(cipher);
result.ciphers.push(cipher);
});
result.success = true;
return Promise.resolve(result);
}
}

View File

@ -70,6 +70,7 @@ import { PasswordSafeXmlImporter } from '../importers/passwordSafeXmlImporter';
import { PasswordWalletTxtImporter } from '../importers/passwordWalletTxtImporter';
import { RememBearCsvImporter } from '../importers/rememBearCsvImporter';
import { RoboFormCsvImporter } from '../importers/roboformCsvImporter';
import { SafariCsvImporter } from '../importers/safariCsvImporter';
import { SafeInCloudXmlImporter } from '../importers/safeInCloudXmlImporter';
import { SaferPassCsvImporter } from '../importers/saferpassCsvImport';
import { SecureSafeCsvImporter } from '../importers/secureSafeCsvImporter';
@ -87,6 +88,7 @@ export class ImportService implements ImportServiceAbstraction {
{ id: 'lastpasscsv', name: 'LastPass (csv)' },
{ id: 'chromecsv', name: 'Chrome (csv)' },
{ id: 'firefoxcsv', name: 'Firefox (csv)' },
{ id: 'safaricsv', name: 'Safari (csv)' },
{ id: 'keepass2xml', name: 'KeePass 2 (xml)' },
{ id: '1password1pif', name: '1Password (1pif)' },
{ id: 'dashlanejson', name: 'Dashlane (json)' },
@ -226,6 +228,8 @@ export class ImportService implements ImportServiceAbstraction {
return new UpmCsvImporter();
case 'saferpasscsv':
return new SaferPassCsvImporter();
case 'safaricsv':
return new SafariCsvImporter();
case 'meldiumcsv':
return new MeldiumCsvImporter();
case '1password1pif':