bitwarden-estensione-browser/src/models/view/loginUriView.ts

76 lines
2.0 KiB
TypeScript
Raw Normal View History

import { UriMatchType } from '../../enums/uriMatchType';
import { View } from './view';
import { LoginUri } from '../domain/loginUri';
import { PlatformUtilsService } from '../../abstractions/platformUtils.service';
2018-04-23 19:03:47 +02:00
import { Utils } from '../../misc/utils';
2018-04-19 20:40:42 +02:00
export class LoginUriView implements View {
match: UriMatchType = null;
// tslint:disable
private _uri: string;
private _domain: string;
2018-04-19 20:40:42 +02:00
private _hostname: string;
// tslint:enable
constructor(u?: LoginUri) {
if (!u) {
return;
}
this.match = u.match;
}
get uri(): string {
return this._uri;
}
set uri(value: string) {
this._uri = value;
this._domain = null;
}
get domain(): string {
if (this._domain == null && this.uri != null) {
2018-05-15 05:41:12 +02:00
const containerService = (Utils.global as any).bitwardenContainerService;
if (containerService) {
const platformUtilsService: PlatformUtilsService = containerService.getPlatformUtilsService();
this._domain = platformUtilsService.getDomain(this.uri);
if (this._domain === '') {
this._domain = null;
}
} else {
2018-05-15 05:41:12 +02:00
throw new Error('global bitwardenContainerService not initialized.');
}
}
return this._domain;
}
2018-04-19 20:40:42 +02:00
get hostname(): string {
if (this._hostname == null && this.uri != null) {
2018-04-23 19:03:47 +02:00
this._hostname = Utils.getHostname(this.uri);
2018-04-19 20:40:42 +02:00
if (this._hostname === '') {
this._hostname = null;
}
}
return this._hostname;
}
get hostnameOrUri(): string {
return this.hostname != null ? this.hostname : this.uri;
}
get isWebsite(): boolean {
return this.uri != null && (this.uri.indexOf('http://') === 0 || this.uri.indexOf('https://') === 0);
}
get canLaunch(): boolean {
return this.uri != null && this.uri.indexOf('://') > -1;
}
}