2018-03-02 05:44:29 +01:00
|
|
|
import { UriMatchType } from '../../enums/uriMatchType';
|
|
|
|
|
|
|
|
import { View } from './view';
|
|
|
|
|
|
|
|
import { LoginUri } from '../domain/loginUri';
|
|
|
|
|
2018-04-23 19:03:47 +02:00
|
|
|
import { Utils } from '../../misc/utils';
|
2018-04-19 20:40:42 +02:00
|
|
|
|
2018-11-02 13:39:09 +01:00
|
|
|
const CanLaunchWhitelist = [
|
|
|
|
'https://',
|
|
|
|
'http://',
|
|
|
|
'ssh://',
|
|
|
|
'ftp://',
|
|
|
|
'sftp://',
|
|
|
|
'irc://',
|
2019-02-14 15:07:20 +01:00
|
|
|
'vnc://',
|
2018-11-02 13:39:09 +01:00
|
|
|
'chrome://',
|
2019-04-17 05:32:02 +02:00
|
|
|
'iosapp://',
|
|
|
|
'androidapp://',
|
2018-11-02 13:39:09 +01:00
|
|
|
];
|
|
|
|
|
2018-03-02 05:44:29 +01:00
|
|
|
export class LoginUriView implements View {
|
|
|
|
match: UriMatchType = null;
|
|
|
|
|
|
|
|
// tslint:disable
|
2019-01-25 15:30:21 +01:00
|
|
|
private _uri: string = null;
|
|
|
|
private _domain: string = null;
|
|
|
|
private _hostname: string = null;
|
|
|
|
private _canLaunch: boolean = null;
|
2018-03-02 05:44:29 +01:00
|
|
|
// 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;
|
2018-11-02 18:03:00 +01:00
|
|
|
this._canLaunch = null;
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get domain(): string {
|
|
|
|
if (this._domain == null && this.uri != null) {
|
2018-10-14 04:21:54 +02:00
|
|
|
this._domain = Utils.getDomain(this.uri);
|
|
|
|
if (this._domain === '') {
|
|
|
|
this._domain = null;
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._domain;
|
|
|
|
}
|
|
|
|
|
2018-04-19 20:40:42 +02:00
|
|
|
get hostname(): string {
|
2020-06-18 17:58:29 +02:00
|
|
|
if (this.match === UriMatchType.RegularExpression) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-19 20:40:42 +02:00
|
|
|
if (this._hostname == null && this.uri != null) {
|
2020-07-13 22:47:55 +02:00
|
|
|
this._hostname = Utils.getHost(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;
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get isWebsite(): boolean {
|
2019-01-07 16:33:13 +01:00
|
|
|
return this.uri != null && (this.uri.indexOf('http://') === 0 || this.uri.indexOf('https://') === 0 ||
|
|
|
|
(this.uri.indexOf('://') < 0 && Utils.tldEndingRegex.test(this.uri)));
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get canLaunch(): boolean {
|
2018-11-02 18:03:00 +01:00
|
|
|
if (this._canLaunch != null) {
|
|
|
|
return this._canLaunch;
|
2018-11-02 13:39:09 +01:00
|
|
|
}
|
2019-02-08 14:03:12 +01:00
|
|
|
if (this.uri != null && this.match !== UriMatchType.RegularExpression) {
|
2019-01-07 16:33:13 +01:00
|
|
|
const uri = this.launchUri;
|
2018-11-02 18:03:00 +01:00
|
|
|
for (let i = 0; i < CanLaunchWhitelist.length; i++) {
|
2019-01-07 16:33:13 +01:00
|
|
|
if (uri.indexOf(CanLaunchWhitelist[i]) === 0) {
|
2018-11-02 18:03:00 +01:00
|
|
|
this._canLaunch = true;
|
|
|
|
return this._canLaunch;
|
|
|
|
}
|
2018-11-02 13:39:09 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-02 18:03:00 +01:00
|
|
|
this._canLaunch = false;
|
|
|
|
return this._canLaunch;
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|
2019-01-07 16:33:13 +01:00
|
|
|
|
|
|
|
get launchUri(): string {
|
|
|
|
return this.uri.indexOf('://') < 0 && Utils.tldEndingRegex.test(this.uri) ? ('http://' + this.uri) : this.uri;
|
|
|
|
}
|
2018-03-02 05:44:29 +01:00
|
|
|
}
|