Fix referrer RegEx for permanent version redirect (#3864)
This commit is contained in:
parent
6e144e9f7c
commit
3654b693e3
@ -3,7 +3,7 @@ import { getActions } from '../global';
|
|||||||
import { PRODUCTION_HOSTNAME, WEB_VERSION_BASE } from '../config';
|
import { PRODUCTION_HOSTNAME, WEB_VERSION_BASE } from '../config';
|
||||||
import { clearWebsync } from './websync';
|
import { clearWebsync } from './websync';
|
||||||
|
|
||||||
const SEARCH_ENGINE_REFERRERS = ['google', 'bing', 'duckduckgo', 'ya', 'yandex'];
|
const SEARCH_ENGINE_REGEX = /(^|\.)(google|bing|duckduckgo|ya|yandex)\./i;
|
||||||
// Handled by the legacy version. Cannot be updated
|
// Handled by the legacy version. Cannot be updated
|
||||||
const PERMANENT_VERSION_KEY = 'kz_version';
|
const PERMANENT_VERSION_KEY = 'kz_version';
|
||||||
const AVAILABLE_VERSIONS = ['Z', 'K'] as const;
|
const AVAILABLE_VERSIONS = ['Z', 'K'] as const;
|
||||||
@ -34,24 +34,30 @@ export function checkAndAssignPermanentWebVersion() {
|
|||||||
if (window.location.hostname !== PRODUCTION_HOSTNAME) return;
|
if (window.location.hostname !== PRODUCTION_HOSTNAME) return;
|
||||||
|
|
||||||
const referrer = document.referrer.toLowerCase();
|
const referrer = document.referrer.toLowerCase();
|
||||||
if (!SEARCH_ENGINE_REFERRERS.some((engine) => referrer.match(`(\\/\\/:|\\.)${engine}\\.`))) return;
|
if (!referrer) return;
|
||||||
|
try {
|
||||||
|
const isSearchEngine = new URL(referrer).host.match(SEARCH_ENGINE_REGEX);
|
||||||
|
if (!isSearchEngine) return;
|
||||||
|
|
||||||
const currentVersion = getPermanentWebVersion();
|
const currentVersion = getPermanentWebVersion();
|
||||||
if (currentVersion) {
|
if (currentVersion) {
|
||||||
if (currentVersion !== CLIENT_VERSION) {
|
if (currentVersion !== CLIENT_VERSION) {
|
||||||
switchPermanentWebVersion(currentVersion);
|
switchPermanentWebVersion(currentVersion);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const hasTest = (urlParams.get('test') ?? undefined) !== undefined;
|
||||||
|
const shouldRedirect = Math.random() < 0.5;
|
||||||
|
|
||||||
|
if (hasTest || !shouldRedirect) {
|
||||||
|
setPermanentWebVersion('Z');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switchPermanentWebVersion('K');
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const hasTest = (urlParams.get('test') ?? undefined) !== undefined;
|
|
||||||
const shouldRedirect = Math.random() < 0.5;
|
|
||||||
|
|
||||||
if (hasTest || !shouldRedirect) {
|
|
||||||
setPermanentWebVersion('Z');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switchPermanentWebVersion('K');
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user