import { md5 } from 'js-md5'; import { parseHrefParam } from '../utils/utils'; // domain export function getOrgCode() { let domain; const paramCode = (parseHrefParam(window.location.href, 'code') as string) || window.sessionStorage.getItem('paramDomainCode'); if (paramCode) { domain = paramCode; window.sessionStorage.setItem('paramDomainCode', domain); return domain; } domain = window.localStorage.getItem('domain_in_url'); if (domain) return domain; const ipFormat = new RegExp(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/); const { hostname } = window.location; if (ipFormat.test(hostname) || hostname.includes('localhost')) return ''; domain = hostname.split('.')[0]; return domain; } export function getOrgCodeFromDomain(domain: string) { let code = ''; if (!domain) return ''; console.log('domain', domain); const hostname = domain.split('://')[1]; if (!hostname) return ''; const ipFormat = new RegExp(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/); if (ipFormat.test(hostname) || hostname.includes('localhost')) return ''; code = hostname.split('.')[0]; return code; } export const PLATFORM = 'WEB'; if (!localStorage.getItem('deviceId')) { localStorage.setItem('deviceId', md5(`${Math.random()}-${Date.now()}`)); } export const DEVICE_ID = localStorage.getItem('deviceId') as string;