decord/source/modules/build_overrides/BuildOverrideUtils.tsx

203 lines
6.7 KiB
TypeScript
Raw Normal View History

2026-08-24 06:08:38 +00:00
// Module ID: 4294
// Function ID: 4295
2026-07-29 08:29:29 +00:00
// Name: Version
2026-08-24 06:08:38 +00:00
// Dependencies: [4295, 676, 1626, 500, 1487, 530, 1489, 4296, 2]
2026-07-29 08:29:29 +00:00
// Exports: getAPIEndpoint, getBuildOverride, getBuildOverrideExperiments, getBuildOverrideMeta, isBuildOverrideLink, isManualBuildOverrideLink, manualOverrideLinkMeta, probablyHasBuildOverride, validateURL
2026-07-20 16:05:17 +00:00
2026-08-24 06:08:38 +00:00
// Module 4294 (Version)
import sendRequest from "sendRequest" /* 530 */;
import ME from "ME" /* 676 */;
import isDiscordProxiedAssetUrlDefault from "isDiscordProxiedAssetUrl" /* 1487 */;
import UrlAll from "Url" /* 1489 */;
import BUILD_OVERRIDE_TARGET_NAMES from "BUILD_OVERRIDE_TARGET_NAMES" /* 4295 */;
import parseDefault from "parse" /* 4296 */;
import getConstants from "getConstants" /* 1626 */;
import set from "set" /* 500 */;
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
let closure_4 = BUILD_OVERRIDE_TARGET_NAMES.BUILD_OVERRIDE_COOKIE_NAME;
const PRIMARY_DOMAIN = ME.PRIMARY_DOMAIN;
2026-07-29 08:29:29 +00:00
getConstants = getConstants.getConstants();
if (set.isAndroid()) {
let Version = getConstants.Version.split(" - ")[0];
const str = getConstants.Version;
} else {
2026-08-24 06:08:38 +00:00
const _module2 = set;
2026-07-29 08:29:29 +00:00
if (_module2.isIOS()) {
Version = getConstants.Version;
}
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
function getAPIEndpoint(c5) {
return "" + location.protocol + "//" + location.host + c5;
}
function isManualBuildOverrideLink(iter) {
let isMatch = null != iter;
2026-07-20 16:05:17 +00:00
if (isMatch) {
2026-07-29 08:29:29 +00:00
isMatch = regExp1.test(iter);
2026-07-20 16:05:17 +00:00
}
return isMatch;
}
2026-07-29 08:29:29 +00:00
function manualOverrideLinkMeta(str) {
const match = str.match(regExp1);
2026-07-20 16:05:17 +00:00
if (null != match) {
if (2 === match.length) {
2026-08-24 06:08:38 +00:00
let obj = set;
2026-07-29 08:29:29 +00:00
obj = { targetBuildOverride: null, validForUserIds: null, expiresAt: "Mon, 1 Jan 2038 00:00:00 GMT" };
2026-07-20 16:05:17 +00:00
obj = {};
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
obj1 = { type: "branch", id: null };
2026-07-29 08:29:29 +00:00
obj1[1] = match[1];
2026-07-20 16:05:17 +00:00
obj["discord_" + obj.getNativePlatform()] = obj1;
2026-07-29 08:29:29 +00:00
obj[0] = obj;
obj[1] = [];
2026-07-20 16:05:17 +00:00
return obj;
}
}
return null;
}
const regExp = new RegExp("^https://(?:ptb\\.|canary\\.)?(discordapp|discord)\\.com/__development/link?[\\S]+$", "i");
const regExp1 = new RegExp("^dev://branch/([\\w-./]+)$", "i");
2026-07-23 10:11:24 +00:00
set = new Set(["canary.discord.com", "ptb.discord.com", "discord.com", "canary.discordapp.com", "ptb.discordapp.com", "discordapp.com"]);
const set1 = new Set(["/__development/link", "/__development/link/"]);
const result = set.fileFinishedImporting("modules/build_overrides/BuildOverrideUtils.tsx");
2026-07-20 16:05:17 +00:00
export const APP_VERSION = Version;
export { getAPIEndpoint };
2026-07-29 08:29:29 +00:00
export const getBuildOverride = function getBuildOverride() {
2026-08-24 06:08:38 +00:00
let obj = isDiscordProxiedAssetUrlDefault;
2026-07-29 08:29:29 +00:00
const safeParseWithQueryResult = obj.safeParseWithQuery("" + location.protocol + "//" + location.host + "/__development/build_overrides");
2026-07-20 16:05:17 +00:00
if (null == safeParseWithQueryResult) {
let resolved = Promise.resolve(null);
} else {
safeParseWithQueryResult.search = null;
if (Version) {
2026-07-29 08:29:29 +00:00
safeParseWithQueryResult.query.version = tmp3;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
const HTTP = sendRequest.HTTP;
2026-07-29 08:29:29 +00:00
obj = { url: null, oldFormErrors: true, rejectWithError: false };
2026-08-24 06:08:38 +00:00
obj[0] = UrlAll.format(safeParseWithQueryResult);
2026-07-20 16:05:17 +00:00
const value = HTTP.get(obj);
resolved = value.then((body) => body.body || null, () => null);
2026-08-24 06:08:38 +00:00
const obj3 = UrlAll;
2026-07-20 16:05:17 +00:00
}
return resolved;
};
export const getBuildOverrideMeta = function getBuildOverrideMeta(url) {
2026-07-29 08:29:29 +00:00
let isMatch = null != url;
if (isMatch) {
isMatch = regExp1.test(url);
}
if (isMatch) {
const match = url.match(regExp1);
let tmp13 = null;
if (null != match) {
tmp13 = null;
if (2 === match.length) {
let obj = { targetBuildOverride: null, validForUserIds: null, expiresAt: "Mon, 1 Jan 2038 00:00:00 GMT" };
obj = {};
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
obj1 = { type: "branch", id: null };
2026-07-29 08:29:29 +00:00
obj1[1] = match[1];
2026-08-24 06:08:38 +00:00
obj["discord_" + set.getNativePlatform()] = obj1;
2026-07-29 08:29:29 +00:00
obj[0] = obj;
obj[1] = [];
tmp13 = obj;
2026-08-24 06:08:38 +00:00
const obj4 = set;
2026-07-29 08:29:29 +00:00
}
}
return Promise.resolve(tmp13);
2026-07-20 16:05:17 +00:00
} else {
2026-08-24 06:08:38 +00:00
obj = isDiscordProxiedAssetUrlDefault;
2026-07-20 16:05:17 +00:00
const safeParseWithQueryResult = obj.safeParseWithQuery(url);
if (null == safeParseWithQueryResult) {
let resolved = Promise.resolve(null);
} else {
safeParseWithQueryResult.search = null;
safeParseWithQueryResult.query.meta = "true";
if (Version) {
2026-07-29 08:29:29 +00:00
safeParseWithQueryResult.query.version = tmp16;
2026-07-20 16:05:17 +00:00
}
const _window = window;
safeParseWithQueryResult.host = window.location.host;
2026-08-24 06:08:38 +00:00
const HTTP = sendRequest.HTTP;
2026-07-29 08:29:29 +00:00
let obj2 = { url: null, oldFormErrors: true, rejectWithError: false };
2026-08-24 06:08:38 +00:00
obj2 = UrlAll;
2026-07-29 08:29:29 +00:00
obj2[0] = obj2.format(safeParseWithQueryResult);
const value = HTTP.get(obj2);
2026-07-20 16:05:17 +00:00
resolved = value.then((body) => body.body || null, () => null);
}
return resolved;
}
};
export const probablyHasBuildOverride = function probablyHasBuildOverride() {
return -1 !== cookie.indexOf("" + closure_4 + "=");
};
export const getBuildOverrideExperiments = function getBuildOverrideExperiments() {
2026-07-29 08:29:29 +00:00
try {
2026-08-24 06:08:38 +00:00
let experiments = parseDefault;
2026-07-29 08:29:29 +00:00
const _window = window;
const tmp5 = experiments.parse(window.document.cookie)[closure_4];
if (null == tmp5) {
experiments = {};
} else {
const _JSON = JSON;
const _atob = atob;
experiments = JSON.parse(atob(str.substring(str.indexOf(".") + 1))).$meta.experiments;
if (experiments == null) {
experiments = {};
}
}
return experiments;
} catch (err) {
return {};
2026-07-20 16:05:17 +00:00
}
};
export const isBuildOverrideLink = function isBuildOverrideLink(target) {
let isMatch = null != target;
if (isMatch) {
isMatch = regExp.test(target);
}
return isMatch;
};
export { isManualBuildOverrideLink };
export { manualOverrideLinkMeta };
2026-07-29 08:29:29 +00:00
export const validateURL = function validateURL(target) {
let isMatch = null != target;
if (isMatch) {
isMatch = regExp1.test(target);
}
if (isMatch) {
let obj = { payload: null, url: null };
obj[1] = target;
2026-07-20 16:05:17 +00:00
return obj;
} else {
2026-08-24 06:08:38 +00:00
obj = isDiscordProxiedAssetUrlDefault;
2026-07-29 08:29:29 +00:00
const url = obj.safeParseWithQuery(target);
2026-07-20 16:05:17 +00:00
if (null == url) {
return null;
} else {
if (set.has(url.hostname)) {
if ("s" in url.query) {
if (set1.has(url.pathname)) {
for (const key10021 in url.query) {
2026-07-23 10:11:24 +00:00
let tmp11 = key10021;
2026-07-20 16:05:17 +00:00
if ("s" === key10021) {
continue;
} else {
let query = url.query;
2026-07-23 10:11:24 +00:00
delete tmp[tmp2];
continue;
2026-07-20 16:05:17 +00:00
}
continue;
}
2026-07-29 08:29:29 +00:00
obj = { payload: null, url: null };
obj[0] = url.query.s;
2026-08-24 06:08:38 +00:00
obj[1] = UrlAll.format(url);
2026-07-20 16:05:17 +00:00
return obj;
}
}
}
return null;
}
}
};