157 lines
4.5 KiB
TypeScript
157 lines
4.5 KiB
TypeScript
// Metro module 4105 (f4106).
|
|
import { BUILD_OVERRIDE_COOKIE_NAME } from "./BuildOverrideConstants";
|
|
import { PRIMARY_DOMAIN } from "../../Constants";
|
|
import { getConstants } from "../../utils/native/ClientInfoUtils";
|
|
import { isAndroid, isIOS, getNativePlatform } from "../../utils/PlatformUtils";
|
|
import URLUtils from "../../utils/URLUtils";
|
|
import { HTTP } from "../../_bundle/sendRequest";
|
|
import { format } from "../../_bundle/Url_1469";
|
|
import Module4107 from "../../_bundle/Module4107";
|
|
let version, c2364_6, c2364_7, c2364_8, c2364_9;
|
|
PRIMARY_DOMAIN;
|
|
const constants = getConstants();
|
|
const r39 = isAndroid() ? constants.Version.split(" - ")[0] : isIOS() ? constants.Version : void 0;
|
|
export function getAPIEndpoint(a0) {
|
|
return `${location.protocol}//${location.host}${a0}`;
|
|
}
|
|
export function isManualBuildOverrideLink(a0) {
|
|
return a0 != null && c2364_7.test(a0);
|
|
}
|
|
export function manualOverrideLinkMeta(a0) {
|
|
const r9 = a0.match(c2364_7);
|
|
if (r9 != null && r9.length === 2) {
|
|
const nativePlatform = getNativePlatform();
|
|
const id = r9[1];
|
|
const targetBuildOverride = {};
|
|
targetBuildOverride[`discord_${nativePlatform}`] = {
|
|
type: "branch",
|
|
id
|
|
};
|
|
return {
|
|
targetBuildOverride,
|
|
validForUserIds: [],
|
|
expiresAt: "Mon, 1 Jan 2038 00:00:00 GMT"
|
|
};
|
|
}
|
|
return null;
|
|
}
|
|
version = r39;
|
|
c2364_6 = new RegExp("^https://(?:ptb\\.|canary\\.)?(discordapp|discord)\\.com/__development/link?[\\S]+$", "i");
|
|
c2364_7 = new RegExp("^dev://branch/([\\w-./]+)$", "i");
|
|
c2364_8 = new Set(["canary.discord.com", "ptb.discord.com", "discord.com", "canary.discordapp.com", "ptb.discordapp.com", "discordapp.com"]);
|
|
c2364_9 = new Set(["/__development/link", "/__development/link/"]);
|
|
export { version as APP_VERSION };
|
|
export function getBuildOverride() {
|
|
let r40;
|
|
const r8 = URLUtils.safeParseWithQuery(`${location.protocol}//${location.host}/__development/build_overrides`);
|
|
if (r8 == null) {
|
|
r40 = Promise.resolve(null);
|
|
} else {
|
|
r8.search = null;
|
|
if (version) {
|
|
r8.query.version = version;
|
|
}
|
|
r40 = HTTP.get({
|
|
url: format(r8),
|
|
oldFormErrors: true,
|
|
rejectWithError: false
|
|
}).then((result) => result.body || null, () => null);
|
|
}
|
|
return r40;
|
|
}
|
|
export function getBuildOverrideMeta(a0) {
|
|
let r38;
|
|
if (a0 != null && c2364_7.test(a0)) {
|
|
const r43 = Promise;
|
|
const r47 = a0.match(c2364_7);
|
|
const r48 = r47 == null;
|
|
let r49 = null;
|
|
if (!r48) {
|
|
const length = r47.length;
|
|
r49 = null;
|
|
if (length === 2) {
|
|
const nativePlatform = getNativePlatform();
|
|
const id = r47[1];
|
|
const targetBuildOverride = {};
|
|
targetBuildOverride[`discord_${nativePlatform}`] = {
|
|
type: "branch",
|
|
id
|
|
};
|
|
r49 = {
|
|
targetBuildOverride,
|
|
validForUserIds: [],
|
|
expiresAt: "Mon, 1 Jan 2038 00:00:00 GMT"
|
|
};
|
|
}
|
|
}
|
|
return r43.resolve(r49);
|
|
}
|
|
const r10 = URLUtils.safeParseWithQuery(a0);
|
|
if (r10 == null) {
|
|
r38 = Promise.resolve(null);
|
|
} else {
|
|
r10.search = null;
|
|
r10.query.meta = "true";
|
|
if (version) {
|
|
r10.query.version = version;
|
|
}
|
|
r10.host = window.location.host;
|
|
r38 = HTTP.get({
|
|
url: format(r10),
|
|
oldFormErrors: true,
|
|
rejectWithError: false
|
|
}).then((result) => result.body || null, () => null);
|
|
}
|
|
return r38;
|
|
}
|
|
export function probablyHasBuildOverride() {
|
|
return window.document.cookie.indexOf(`${BUILD_OVERRIDE_COOKIE_NAME}=`) !== -1;
|
|
}
|
|
export function getBuildOverrideExperiments() {
|
|
let r31;
|
|
try {
|
|
const r16 = Module4107.parse(window.document.cookie)[BUILD_OVERRIDE_COOKIE_NAME];
|
|
if (r16 == null) {
|
|
r31 = {};
|
|
} else {
|
|
const r19 = JSON;
|
|
const r21 = atob;
|
|
r31 = r19.parse(r21(r16.substring(r16.indexOf(".") + 1))).$meta.experiments;
|
|
if (r31 == null) {
|
|
r31 = {};
|
|
}
|
|
}
|
|
} catch ($e) {
|
|
return {};
|
|
}
|
|
return r31;
|
|
}
|
|
export function isBuildOverrideLink(a0) {
|
|
return a0 != null && c2364_6.test(a0);
|
|
}
|
|
export function validateURL(a0) {
|
|
if (a0 != null && c2364_7.test(a0)) {
|
|
return {
|
|
payload: null,
|
|
url: a0
|
|
};
|
|
}
|
|
const r19 = URLUtils.safeParseWithQuery(a0);
|
|
if (r19 == null) {
|
|
return null;
|
|
}
|
|
if (c2364_8.has(r19.hostname) && "s" in r19.query && c2364_9.has(r19.pathname)) {
|
|
const query = r19.query;
|
|
for (const key in query) {
|
|
if (key !== "s") {
|
|
delete r19.query[key];
|
|
}
|
|
}
|
|
return {
|
|
payload: r19.query.s,
|
|
url: format(r19)
|
|
};
|
|
}
|
|
return null;
|
|
}
|