bitwarden-estensione-browser/libs/common/src/importers/splashIdCsvImporter.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-07-23 17:23:20 +02:00
import { ImportResult } from "../models/domain/importResult";
import { CipherView } from "../models/view/cipherView";
2022-02-22 15:39:11 +01:00
import { BaseImporter } from "./baseImporter";
import { Importer } from "./importer";
2018-07-23 17:23:20 +02:00
export class SplashIdCsvImporter extends BaseImporter implements Importer {
parse(data: string): Promise<ImportResult> {
2018-07-23 17:23:20 +02:00
const result = new ImportResult();
const results = this.parseCsv(data, false);
if (results == null) {
result.success = false;
return Promise.resolve(result);
2018-07-23 17:23:20 +02:00
}
results.forEach((value) => {
2018-07-23 17:23:20 +02:00
if (value.length < 3) {
2021-12-16 13:36:21 +01:00
return;
}
2018-07-23 17:23:20 +02:00
this.processFolder(result, this.getValueOrDefault(value[value.length - 1]));
const cipher = this.initLoginCipher();
cipher.notes = this.getValueOrDefault(value[value.length - 2], "");
cipher.name = this.getValueOrDefault(value[1], "--");
2021-12-16 13:36:21 +01:00
2018-07-23 17:23:20 +02:00
if (value[0] === "Web Logins" || value[0] === "Servers" || value[0] === "Email Accounts") {
cipher.login.username = this.getValueOrDefault(value[2]);
cipher.login.password = this.getValueOrDefault(value[3]);
cipher.login.uris = this.makeUriArray(value[4]);
this.parseFieldsToNotes(cipher, 5, value);
} else {
this.parseFieldsToNotes(cipher, 2, value);
}
2021-12-16 13:36:21 +01:00
2018-07-23 17:23:20 +02:00
this.convertToNoteIfNeeded(cipher);
this.cleanupCipher(cipher);
result.ciphers.push(cipher);
2021-12-16 13:36:21 +01:00
});
2018-07-23 17:23:20 +02:00
if (this.organization) {
this.moveFoldersToCollections(result);
}
2021-12-16 13:36:21 +01:00
2018-07-23 17:23:20 +02:00
result.success = true;
return Promise.resolve(result);
2021-12-16 13:36:21 +01:00
}
2018-07-23 17:23:20 +02:00
private parseFieldsToNotes(cipher: CipherView, startIndex: number, value: any) {
// last 3 rows do not get parsed
for (let i = startIndex; i < value.length - 3; i++) {
if (this.isNullOrWhitespace(value[i])) {
continue;
2021-12-16 13:36:21 +01:00
}
2018-07-23 17:23:20 +02:00
cipher.notes += value[i] + "\n";
2021-12-16 13:36:21 +01:00
}
}
2018-07-23 17:23:20 +02:00
}