mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 18:53:29 +00:00
[PM-328] Move common/importer to libs/importer (tools-migration) (#5060)
* Create and register new libs/importer Create package.json Create tsconfig Create jest.config Extend shared and root tsconfig and jest.configs Register with eslint * Move importer-related files to libs/importer * Move importer-spec-related files to libs/importer Move import.service.spec * Update package-lock.json * Set CODEOWNERS for new libs/importer * Register libs/importer with cli and fix imports * Register libs/importer with web and fix imports * Move importOption into models Rename importOptions to import-options * Fix linting issues after updating prettier * Only expose necessary files from libs/importer Fix tsconfig files - Removes the trailing /index on imports in web/cli As the spec-files no longer can access the internals via @bitwarden/importer they import by path (../src/importers) * Add barrel files to vendors with more than one importer
This commit is contained in:
committed by
GitHub
parent
7cfabf053c
commit
a5a12a6723
69
libs/importer/src/importers/roboform-csv-importer.ts
Normal file
69
libs/importer/src/importers/roboform-csv-importer.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { ImportResult } from "../models/import-result";
|
||||
|
||||
import { BaseImporter } from "./base-importer";
|
||||
import { Importer } from "./importer";
|
||||
|
||||
export class RoboFormCsvImporter 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);
|
||||
}
|
||||
|
||||
let i = 1;
|
||||
results.forEach((value) => {
|
||||
const folder =
|
||||
!this.isNullOrWhitespace(value.Folder) && value.Folder.startsWith("/")
|
||||
? value.Folder.replace("/", "")
|
||||
: value.Folder;
|
||||
const folderName = !this.isNullOrWhitespace(folder) ? folder : null;
|
||||
this.processFolder(result, folderName);
|
||||
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.notes = this.getValueOrDefault(value.Note);
|
||||
cipher.name = this.getValueOrDefault(value.Name, "--");
|
||||
cipher.login.username = this.getValueOrDefault(value.Login);
|
||||
cipher.login.password = this.getValueOrDefault(value.Pwd);
|
||||
cipher.login.uris = this.makeUriArray(value.Url);
|
||||
|
||||
if (!this.isNullOrWhitespace(value.Rf_fields)) {
|
||||
let fields: string[] = [value.Rf_fields];
|
||||
if (value.__parsed_extra != null && value.__parsed_extra.length > 0) {
|
||||
fields = fields.concat(value.__parsed_extra);
|
||||
}
|
||||
fields.forEach((field: string) => {
|
||||
const parts = field.split(":");
|
||||
if (parts.length < 3) {
|
||||
return;
|
||||
}
|
||||
const key = parts[0] === "-no-name-" ? null : parts[0];
|
||||
const val = parts.length === 4 && parts[2] === "rck" ? parts[1] : parts[2];
|
||||
this.processKvp(cipher, key, val);
|
||||
});
|
||||
}
|
||||
|
||||
this.convertToNoteIfNeeded(cipher);
|
||||
this.cleanupCipher(cipher);
|
||||
|
||||
if (
|
||||
i === results.length &&
|
||||
cipher.name === "--" &&
|
||||
this.isNullOrWhitespace(cipher.login.password)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
result.ciphers.push(cipher);
|
||||
i++;
|
||||
});
|
||||
|
||||
if (this.organization) {
|
||||
this.moveFoldersToCollections(result);
|
||||
}
|
||||
|
||||
result.success = true;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user