From 0d2cd4c482c19ee3385677e957bbd99ae2eafbb6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 25 Jun 2018 15:19:51 -0400 Subject: [PATCH] name from url --- src/importers/aviraCsvImporter.ts | 3 ++- src/importers/baseImporter.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/importers/aviraCsvImporter.ts b/src/importers/aviraCsvImporter.ts index d70402862..bb10ad392 100644 --- a/src/importers/aviraCsvImporter.ts +++ b/src/importers/aviraCsvImporter.ts @@ -20,7 +20,8 @@ export class AviraCsvImporter extends BaseImporter implements Importer { results.forEach((value) => { const cipher = new CipherView(); cipher.type = CipherType.Login; - cipher.name = this.getValueOrDefault(value.name, '--'); + cipher.name = this.getValueOrDefault(value.name, + this.getValueOrDefault(this.nameFromUrl(value.website), '--')); cipher.login = new LoginView(); cipher.login.uris = this.makeUriArray(value.website); cipher.login.password = this.getValueOrDefault(value.password); diff --git a/src/importers/baseImporter.ts b/src/importers/baseImporter.ts index dccd7114e..c1a245e51 100644 --- a/src/importers/baseImporter.ts +++ b/src/importers/baseImporter.ts @@ -2,6 +2,8 @@ import * as papa from 'papaparse'; import { LoginUriView } from '../models/view/loginUriView'; +import { Utils } from '../misc/utils'; + export abstract class BaseImporter { protected passwordFieldNames = [ 'password', 'pass word', 'passphrase', 'pass phrase', @@ -112,6 +114,14 @@ export abstract class BaseImporter { return uri; } + protected nameFromUrl(url: string) { + const hostname = Utils.getHostname(url); + if (this.isNullOrWhitespace(hostname)) { + return null; + } + return hostname.startsWith('www.') ? hostname.replace('www.', '') : hostname; + } + protected isNullOrWhitespace(str: string): boolean { return str == null || str.trim() === ''; }