mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-18 02:41:15 +02:00
bitwarden json importer
This commit is contained in:
parent
3b22df15e8
commit
4d57f44a69
66
src/importers/bitwardenJsonImporter.ts
Normal file
66
src/importers/bitwardenJsonImporter.ts
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { BaseImporter } from './baseImporter';
|
||||||
|
import { Importer } from './importer';
|
||||||
|
|
||||||
|
import { ImportResult } from '../models/domain/importResult';
|
||||||
|
|
||||||
|
import { CipherWithIds } from '../models/export/cipherWithIds';
|
||||||
|
import { CollectionWithId } from '../models/export/collectionWithId';
|
||||||
|
import { FolderWithId } from '../models/export/folderWithId';
|
||||||
|
|
||||||
|
export class BitwardenJsonImporter extends BaseImporter implements Importer {
|
||||||
|
parse(data: string): ImportResult {
|
||||||
|
const result = new ImportResult();
|
||||||
|
const results = JSON.parse(data);
|
||||||
|
if (results == null || results.items == null || results.items.length === 0) {
|
||||||
|
result.success = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupingsMap = new Map<string, number>();
|
||||||
|
if (this.organization && results.collections != null) {
|
||||||
|
results.collections.forEach((c: CollectionWithId) => {
|
||||||
|
const collection = CollectionWithId.toView(c);
|
||||||
|
if (collection != null) {
|
||||||
|
collection.id = null;
|
||||||
|
collection.organizationId = null;
|
||||||
|
groupingsMap.set(c.id, result.collections.length);
|
||||||
|
result.collections.push(collection);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (!this.organization && results.folders != null) {
|
||||||
|
results.folders.forEach((f: FolderWithId) => {
|
||||||
|
const folder = FolderWithId.toView(f);
|
||||||
|
if (folder != null) {
|
||||||
|
folder.id = null;
|
||||||
|
groupingsMap.set(f.id, result.folders.length);
|
||||||
|
result.folders.push(folder);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
results.items.forEach((c: CipherWithIds) => {
|
||||||
|
const cipher = CipherWithIds.toView(c);
|
||||||
|
// reset ids incase they were set for some reason
|
||||||
|
cipher.id = null;
|
||||||
|
cipher.folderId = null;
|
||||||
|
cipher.organizationId = null;
|
||||||
|
cipher.collectionIds = null;
|
||||||
|
|
||||||
|
if (!this.organization && c.folderId != null && groupingsMap.has(c.folderId)) {
|
||||||
|
result.folderRelationships.push([result.ciphers.length, groupingsMap.get(c.folderId)]);
|
||||||
|
} else if (this.organization && c.collectionIds != null) {
|
||||||
|
c.collectionIds.forEach((cId) => {
|
||||||
|
if (groupingsMap.has(cId)) {
|
||||||
|
result.collectionRelationships.push([result.ciphers.length, groupingsMap.get(cId)]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cleanupCipher(cipher);
|
||||||
|
result.ciphers.push(cipher);
|
||||||
|
});
|
||||||
|
|
||||||
|
result.success = true;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -73,6 +73,9 @@ export class ExportService implements ExportServiceAbstraction {
|
|||||||
};
|
};
|
||||||
|
|
||||||
decFolders.forEach((f) => {
|
decFolders.forEach((f) => {
|
||||||
|
if (f.id == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const folder = new FolderExport();
|
const folder = new FolderExport();
|
||||||
folder.build(f);
|
folder.build(f);
|
||||||
jsonDoc.folders.push(folder);
|
jsonDoc.folders.push(folder);
|
||||||
|
@ -22,6 +22,7 @@ import { CipherView } from '../models/view/cipherView';
|
|||||||
import { AscendoCsvImporter } from '../importers/ascendoCsvImporter';
|
import { AscendoCsvImporter } from '../importers/ascendoCsvImporter';
|
||||||
import { AviraCsvImporter } from '../importers/aviraCsvImporter';
|
import { AviraCsvImporter } from '../importers/aviraCsvImporter';
|
||||||
import { BitwardenCsvImporter } from '../importers/bitwardenCsvImporter';
|
import { BitwardenCsvImporter } from '../importers/bitwardenCsvImporter';
|
||||||
|
import { BitwardenJsonImporter } from '../importers/bitwardenJsonImporter';
|
||||||
import { BlurCsvImporter } from '../importers/blurCsvImporter';
|
import { BlurCsvImporter } from '../importers/blurCsvImporter';
|
||||||
import { ChromeCsvImporter } from '../importers/chromeCsvImporter';
|
import { ChromeCsvImporter } from '../importers/chromeCsvImporter';
|
||||||
import { ClipperzHtmlImporter } from '../importers/clipperzHtmlImporter';
|
import { ClipperzHtmlImporter } from '../importers/clipperzHtmlImporter';
|
||||||
@ -58,6 +59,7 @@ import { ZohoVaultCsvImporter } from '../importers/zohoVaultCsvImporter';
|
|||||||
|
|
||||||
export class ImportService implements ImportServiceAbstraction {
|
export class ImportService implements ImportServiceAbstraction {
|
||||||
featuredImportOptions = [
|
featuredImportOptions = [
|
||||||
|
{ id: 'bitwardenjson', name: 'Bitwarden (json)' },
|
||||||
{ id: 'bitwardencsv', name: 'Bitwarden (csv)' },
|
{ id: 'bitwardencsv', name: 'Bitwarden (csv)' },
|
||||||
{ id: 'lastpasscsv', name: 'LastPass (csv)' },
|
{ id: 'lastpasscsv', name: 'LastPass (csv)' },
|
||||||
{ id: 'chromecsv', name: 'Chrome (csv)' },
|
{ id: 'chromecsv', name: 'Chrome (csv)' },
|
||||||
@ -148,6 +150,8 @@ export class ImportService implements ImportServiceAbstraction {
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case 'bitwardencsv':
|
case 'bitwardencsv':
|
||||||
return new BitwardenCsvImporter();
|
return new BitwardenCsvImporter();
|
||||||
|
case 'bitwardenjson':
|
||||||
|
return new BitwardenJsonImporter();
|
||||||
case 'lastpasscsv':
|
case 'lastpasscsv':
|
||||||
case 'passboltcsv':
|
case 'passboltcsv':
|
||||||
return new LastPassCsvImporter();
|
return new LastPassCsvImporter();
|
||||||
|
Loading…
Reference in New Issue
Block a user