mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-19 07:35:48 +02:00
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
|
import { BaseImporter } from './baseImporter';
|
||
|
import { Importer } from './importer';
|
||
|
|
||
|
import { ImportResult } from '../models/domain/importResult';
|
||
|
|
||
|
export class RoboFormCsvImporter extends BaseImporter implements Importer {
|
||
|
parse(data: string): ImportResult {
|
||
|
const result = new ImportResult();
|
||
|
const results = this.parseCsv(data, true);
|
||
|
if (results == null) {
|
||
|
result.success = false;
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
let i = 1;
|
||
|
results.forEach((value) => {
|
||
|
const folder = !this.isNullOrWhitespace(value.Folder) && value.Folder.startsWith('/') ?
|
||
|
value.Folder.replace('/', '') : value.Folder;
|
||
|
const folderName = !this.isNullOrWhitespace(folder) ? folder.split('/').join(' > ') : null;
|
||
|
this.processFolder(result, folderName);
|
||
|
|
||
|
const cipher = this.initLoginCipher();
|
||
|
cipher.notes = this.getValueOrDefault(value.Note);
|
||
|
cipher.name = this.getValueOrDefault(value.Name, '--');
|
||
|
cipher.login.username = this.getValueOrDefault(value.Login);
|
||
|
cipher.login.password = this.getValueOrDefault(value.Pwd);
|
||
|
cipher.login.uris = this.makeUriArray(value.Url);
|
||
|
this.cleanupCipher(cipher);
|
||
|
|
||
|
if (i === results.length && cipher.name === '--' && this.isNullOrWhitespace(cipher.login.password)) {
|
||
|
return;
|
||
|
}
|
||
|
result.ciphers.push(cipher);
|
||
|
i++;
|
||
|
});
|
||
|
|
||
|
if (this.organization) {
|
||
|
this.moveFoldersToCollections(result);
|
||
|
}
|
||
|
|
||
|
result.success = true;
|
||
|
return result;
|
||
|
}
|
||
|
}
|