mirror of
https://github.com/bitwarden/browser
synced 2025-12-22 11:13:46 +00:00
* Move CollectionDialog to Vault * Fix CollectionDialogModule imports * Move CollectionAdminService and View to Vault * Move CollectionService to Vault * Split GroupService into internal and public facing classes * Move collection models to vault * lint spacing fix * Move collection spec file * Fix spec import * Update apps/web/src/app/core/core.module.ts Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com> * Remove CoreOrganizationModule from CollectionDialogModule --------- Co-authored-by: Thomas Rittson <31796059+eliykat@users.noreply.github.com>
87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
|
|
|
|
import { ImportResult } from "../models/import-result";
|
|
|
|
import { BaseImporter } from "./base-importer";
|
|
import { Importer } from "./importer";
|
|
|
|
export class PadlockCsvImporter extends BaseImporter implements Importer {
|
|
parse(data: string): Promise<ImportResult> {
|
|
const result = new ImportResult();
|
|
const results = this.parseCsv(data, false);
|
|
if (results == null) {
|
|
result.success = false;
|
|
return Promise.resolve(result);
|
|
}
|
|
|
|
let headers: string[] = null;
|
|
results.forEach((value) => {
|
|
if (headers == null) {
|
|
headers = value.map((v: string) => v);
|
|
return;
|
|
}
|
|
|
|
if (value.length < 2 || value.length !== headers.length) {
|
|
return;
|
|
}
|
|
|
|
if (!this.isNullOrWhitespace(value[1])) {
|
|
if (this.organization) {
|
|
const tags = (value[1] as string).split(",");
|
|
tags.forEach((tag) => {
|
|
tag = tag.trim();
|
|
let addCollection = true;
|
|
let collectionIndex = result.collections.length;
|
|
|
|
for (let i = 0; i < result.collections.length; i++) {
|
|
if (result.collections[i].name === tag) {
|
|
addCollection = false;
|
|
collectionIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (addCollection) {
|
|
const collection = new CollectionView();
|
|
collection.name = tag;
|
|
result.collections.push(collection);
|
|
}
|
|
|
|
result.collectionRelationships.push([result.ciphers.length, collectionIndex]);
|
|
});
|
|
} else {
|
|
const tags = (value[1] as string).split(",");
|
|
const tag = tags.length > 0 ? tags[0].trim() : null;
|
|
this.processFolder(result, tag);
|
|
}
|
|
}
|
|
|
|
const cipher = this.initLoginCipher();
|
|
cipher.name = this.getValueOrDefault(value[0], "--");
|
|
|
|
for (let i = 2; i < value.length; i++) {
|
|
const header = headers[i].trim().toLowerCase();
|
|
if (this.isNullOrWhitespace(value[i]) || this.isNullOrWhitespace(header)) {
|
|
continue;
|
|
}
|
|
|
|
if (this.usernameFieldNames.indexOf(header) > -1) {
|
|
cipher.login.username = value[i];
|
|
} else if (this.passwordFieldNames.indexOf(header) > -1) {
|
|
cipher.login.password = value[i];
|
|
} else if (this.uriFieldNames.indexOf(header) > -1) {
|
|
cipher.login.uris = this.makeUriArray(value[i]);
|
|
} else {
|
|
this.processKvp(cipher, headers[i], value[i]);
|
|
}
|
|
}
|
|
|
|
this.cleanupCipher(cipher);
|
|
result.ciphers.push(cipher);
|
|
});
|
|
|
|
result.success = true;
|
|
return Promise.resolve(result);
|
|
}
|
|
}
|