1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00

Create and use safeGetString() instead of instanceof checks to determine type (#8906)

`safeGetString` takes a `string` or `EncString` and return the appropiate value based on it's type

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Daniel James Smith
2024-04-24 23:41:35 +02:00
committed by GitHub
parent a6755f5f20
commit dba910d0b9
11 changed files with 82 additions and 137 deletions

View File

@@ -10,6 +10,7 @@ import { IdentityExport } from "./identity.export";
import { LoginExport } from "./login.export";
import { PasswordHistoryExport } from "./password-history.export";
import { SecureNoteExport } from "./secure-note.export";
import { safeGetString } from "./utils";
export class CipherExport {
static template(): CipherExport {
@@ -145,23 +146,16 @@ export class CipherExport {
this.type = o.type;
this.reprompt = o.reprompt;
if (o instanceof CipherView) {
this.name = o.name;
this.notes = o.notes;
} else {
this.name = o.name?.encryptedString;
this.notes = o.notes?.encryptedString;
this.name = safeGetString(o.name);
this.notes = safeGetString(o.notes);
if ("key" in o) {
this.key = o.key?.encryptedString;
}
this.favorite = o.favorite;
if (o.fields != null) {
if (o instanceof CipherView) {
this.fields = o.fields.map((f) => new FieldExport(f));
} else {
this.fields = o.fields.map((f) => new FieldExport(f));
}
this.fields = o.fields.map((f) => new FieldExport(f));
}
switch (o.type) {
@@ -180,11 +174,7 @@ export class CipherExport {
}
if (o.passwordHistory != null) {
if (o instanceof CipherView) {
this.passwordHistory = o.passwordHistory.map((ph) => new PasswordHistoryExport(ph));
} else {
this.passwordHistory = o.passwordHistory.map((ph) => new PasswordHistoryExport(ph));
}
this.passwordHistory = o.passwordHistory.map((ph) => new PasswordHistoryExport(ph));
}
this.creationDate = o.creationDate;