mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 02:03:39 +00:00
Move to libs
This commit is contained in:
71
libs/common/src/importers/gnomeJsonImporter.ts
Normal file
71
libs/common/src/importers/gnomeJsonImporter.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { ImportResult } from "../models/domain/importResult";
|
||||
|
||||
import { BaseImporter } from "./baseImporter";
|
||||
import { Importer } from "./importer";
|
||||
|
||||
export class GnomeJsonImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): Promise<ImportResult> {
|
||||
const result = new ImportResult();
|
||||
const results = JSON.parse(data);
|
||||
if (results == null || Object.keys(results).length === 0) {
|
||||
result.success = false;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
for (const keyRing in results) {
|
||||
if (
|
||||
!results.hasOwnProperty(keyRing) || // eslint-disable-line
|
||||
this.isNullOrWhitespace(keyRing) ||
|
||||
results[keyRing].length === 0
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
results[keyRing].forEach((value: any) => {
|
||||
if (
|
||||
this.isNullOrWhitespace(value.display_name) ||
|
||||
value.display_name.indexOf("http") !== 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.processFolder(result, keyRing);
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = value.display_name.replace("http://", "").replace("https://", "");
|
||||
if (cipher.name.length > 30) {
|
||||
cipher.name = cipher.name.substring(0, 30);
|
||||
}
|
||||
cipher.login.password = this.getValueOrDefault(value.secret);
|
||||
cipher.login.uris = this.makeUriArray(value.display_name);
|
||||
|
||||
if (value.attributes != null) {
|
||||
cipher.login.username =
|
||||
value.attributes != null
|
||||
? this.getValueOrDefault(value.attributes.username_value)
|
||||
: null;
|
||||
for (const attr in value.attributes) {
|
||||
if (
|
||||
!value.attributes.hasOwnProperty(attr) || // eslint-disable-line
|
||||
attr === "username_value" ||
|
||||
attr === "xdg:schema"
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
this.processKvp(cipher, attr, value.attributes[attr]);
|
||||
}
|
||||
}
|
||||
|
||||
this.convertToNoteIfNeeded(cipher);
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.organization) {
|
||||
this.moveFoldersToCollections(result);
|
||||
}
|
||||
|
||||
result.success = true;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user