mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 10:13:31 +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
88
libs/importer/src/importers/clipperz-html-importer.ts
Normal file
88
libs/importer/src/importers/clipperz-html-importer.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { ImportResult } from "../models/import-result";
|
||||
|
||||
import { BaseImporter } from "./base-importer";
|
||||
import { Importer } from "./importer";
|
||||
|
||||
export class ClipperzHtmlImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): Promise<ImportResult> {
|
||||
const result = new ImportResult();
|
||||
const doc = this.parseXml(data);
|
||||
if (doc == null) {
|
||||
result.success = false;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
const textarea = doc.querySelector("textarea");
|
||||
if (textarea == null || this.isNullOrWhitespace(textarea.textContent)) {
|
||||
result.errorMessage = "Missing textarea.";
|
||||
result.success = false;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
const entries = JSON.parse(textarea.textContent);
|
||||
entries.forEach((entry: any) => {
|
||||
const cipher = this.initLoginCipher();
|
||||
if (!this.isNullOrWhitespace(entry.label)) {
|
||||
cipher.name = entry.label.split(" ")[0];
|
||||
}
|
||||
if (entry.data != null && !this.isNullOrWhitespace(entry.data.notes)) {
|
||||
cipher.notes = entry.data.notes.split("\\n").join("\n");
|
||||
}
|
||||
|
||||
if (entry.currentVersion != null && entry.currentVersion.fields != null) {
|
||||
for (const property in entry.currentVersion.fields) {
|
||||
// eslint-disable-next-line
|
||||
if (!entry.currentVersion.fields.hasOwnProperty(property)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const field = entry.currentVersion.fields[property];
|
||||
const actionType = field.actionType != null ? field.actionType.toLowerCase() : null;
|
||||
switch (actionType) {
|
||||
case "password":
|
||||
cipher.login.password = this.getValueOrDefault(field.value);
|
||||
break;
|
||||
case "email":
|
||||
case "username":
|
||||
case "user":
|
||||
case "name":
|
||||
cipher.login.username = this.getValueOrDefault(field.value);
|
||||
break;
|
||||
case "url":
|
||||
cipher.login.uris = this.makeUriArray(field.value);
|
||||
break;
|
||||
default: {
|
||||
const labelLower = field.label != null ? field.label.toLowerCase() : null;
|
||||
if (
|
||||
cipher.login.password == null &&
|
||||
this.passwordFieldNames.indexOf(labelLower) > -1
|
||||
) {
|
||||
cipher.login.password = this.getValueOrDefault(field.value);
|
||||
} else if (
|
||||
cipher.login.username == null &&
|
||||
this.usernameFieldNames.indexOf(labelLower) > -1
|
||||
) {
|
||||
cipher.login.username = this.getValueOrDefault(field.value);
|
||||
} else if (
|
||||
(cipher.login.uris == null || cipher.login.uris.length === 0) &&
|
||||
this.uriFieldNames.indexOf(labelLower) > -1
|
||||
) {
|
||||
cipher.login.uris = this.makeUriArray(field.value);
|
||||
} else {
|
||||
this.processKvp(cipher, field.label, field.value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.convertToNoteIfNeeded(cipher);
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
result.success = true;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user