bitwarden-estensione-browser/libs/importer/src/importers/securesafe-csv-importer.ts

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

32 lines
1.1 KiB
TypeScript
Raw Normal View History

import { ImportResult } from "../models/import-result";
2022-02-22 15:39:11 +01:00
import { BaseImporter } from "./base-importer";
2019-08-22 05:13:08 +02:00
import { Importer } from "./importer";
export class SecureSafeCsvImporter extends BaseImporter implements Importer {
parse(data: string): Promise<ImportResult> {
2019-08-22 05:13:08 +02:00
const result = new ImportResult();
const results = this.parseCsv(data, true);
if (results == null) {
result.success = false;
return Promise.resolve(result);
2019-08-22 05:13:08 +02:00
}
// The url field can be in different case formats.
const urlField = Object.keys(results[0]).find((k) => /url/i.test(k));
results.forEach((value) => {
2019-08-22 05:13:08 +02:00
const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(value.Title);
cipher.notes = this.getValueOrDefault(value.Comment);
cipher.login.uris = this.makeUriArray(value[urlField]);
2019-08-22 05:13:08 +02:00
cipher.login.password = this.getValueOrDefault(value.Password);
cipher.login.username = this.getValueOrDefault(value.Username);
this.cleanupCipher(cipher);
result.ciphers.push(cipher);
});
result.success = true;
return Promise.resolve(result);
2019-08-22 05:13:08 +02:00
}
}