mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 06:43:35 +00:00
getDomain moved to jslib
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import * as tldjs from 'tldjs';
|
||||
|
||||
import { BrowserApi } from '../browser/browserApi';
|
||||
|
||||
import { DeviceType } from 'jslib/enums/deviceType';
|
||||
@@ -12,43 +10,6 @@ import { AnalyticsIds } from 'jslib/misc/analytics';
|
||||
const DialogPromiseExpiration = 600000; // 10 minutes
|
||||
|
||||
export default class BrowserPlatformUtilsService implements PlatformUtilsService {
|
||||
static getDomain(uriString: string): string {
|
||||
if (uriString == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
uriString = uriString.trim();
|
||||
if (uriString === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
|
||||
try {
|
||||
const url = new URL(uriString);
|
||||
|
||||
if (url.hostname === 'localhost' || BrowserPlatformUtilsService.validIpAddress(url.hostname)) {
|
||||
return url.hostname;
|
||||
}
|
||||
|
||||
const urlDomain = tldjs.getDomain(url.hostname);
|
||||
return urlDomain != null ? urlDomain : url.hostname;
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
const domain = tldjs.getDomain(uriString);
|
||||
if (domain != null) {
|
||||
return domain;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static validIpAddress(ipString: string): boolean {
|
||||
// tslint:disable-next-line
|
||||
const ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
||||
return ipRegex.test(ipString);
|
||||
}
|
||||
|
||||
identityClientId: string = 'browser';
|
||||
|
||||
private showDialogResolves = new Map<number, { resolve: (value: boolean) => void, date: Date }>();
|
||||
@@ -127,10 +88,6 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
return this.analyticsIdCache;
|
||||
}
|
||||
|
||||
getDomain(uriString: string): string {
|
||||
return BrowserPlatformUtilsService.getDomain(uriString);
|
||||
}
|
||||
|
||||
isViewOpen(): boolean {
|
||||
if (BrowserApi.isPopupOpen()) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user