Files
discord-decomp/sources/utils/URLUtils.tsx
T
2026-07-27 16:20:00 +03:00

254 lines
12 KiB
TypeScript

/* Metro module 1471; source: utils/URLUtils.tsx; dependencies: [661, 1472, 1473, 1471, 1360, 22, 2] */
function _fun16801(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#16801, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:6, offset: 0x00e5a213, size: 685 bytes, params: 8, frame: 29
var RegExp;
const env0_0 = require;
const closure = function(a0, a1) {
return a0 != null && a1 != null && a0 !== a1;
};
const closure2 = isDiscordHostname;
const closure3 = function(a0) {
return a0 != null && a0 === 'discord:';
};
const closure4 = isDiscordDirectAssetUrl;
const closure5 = isDiscordProxiedAssetUrl;
const closure6 = isAllowedGifProviderUrl;
const closure7 = isDiscordUrl;
const closure8 = isDiscordUri;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_4 = (require(661) /* metro dependency 661: Constants */).Routes;
const env0_5 = RegExp('(?:^|\\.)(?:discordapp|discord|discordmerch)\\.com$', 'i');
const env0_6 = RegExp('^.*\\.discordapp\\.net$', '');
const env0_7 = RegExp('^.*\\.media\\.discordapp\\.net$', '');
let Set = global.Set;
let set = new Set(['media.tenor.com', 'media.tenor.co', 'c.tenor.com', 'static.klipy.com', 'media.giphy.com',
'i.giphy.com']);
set = importDefault(1472) /* metro dependency 1472 */;
const source = set.v4().source;
RegExp = global.RegExp;
const regExp = new RegExp('(?:(?:(?:[a-z]+:)?//)|www\\.)(?:[^\\s:@]+(?::[^\\s@]*)?@)?(?:localhost|' + source + '|(?:[a-z\\u00a1-\\uffff0-9-_]+\\.)+(?:(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:[/?#][^\\s"]*)?',
'ig');
Set = global.Set;
let GLOBAL_ENV = global.window.GLOBAL_ENV;
const CDN_HOST = GLOBAL_ENV.CDN_HOST;
object = [CDN_HOST];
GLOBAL_ENV = global.window.GLOBAL_ENV;
const INVITE_HOST = GLOBAL_ENV.INVITE_HOST;
object[1] = INVITE_HOST;
GLOBAL_ENV = global.window.GLOBAL_ENV;
const GIFT_CODE_HOST = GLOBAL_ENV.GIFT_CODE_HOST;
object[2] = GIFT_CODE_HOST;
GLOBAL_ENV = global.window.GLOBAL_ENV;
const GUILD_TEMPLATE_HOST = GLOBAL_ENV.GUILD_TEMPLATE_HOST;
object[3] = GUILD_TEMPLATE_HOST;
object = {URL_REGEX: new Set(object), makeUrl: makeUrl, isOriginalContentTypeDifferent: closure,
isDiscordHostname: closure2, isDiscordLocalhost: function(a0, a1) {
return a0 != null && a1 != null && global.window.location.host === a0;
}, isDiscordProtocol: closure3, isDiscordUrl: closure7, isDiscordUri: closure8, isDiscordCdnUrl: isDiscordCdnUrl,
isDiscordDirectAssetUrl: closure4, isDiscordProxiedAssetUrl: closure5, isAllowedGifProviderUrl: closure6,
isDiscordAssetUrl: isDiscordAssetUrl, isDiscordUrlOrUri: isDiscordUrlOrUri, isAppRoute: isAppRoute,
format: format_16816, formatPathWithQuery: formatPathWithQuery, formatSearch: formatSearch,
safeParseWithQuery: safeParseWithQuery, toURLSafe: function(a0, a1) {
var URL;
var prototype;
var value;
var value2;
var error;
try {
URL = global.URL;
prototype = URL.prototype;
value = Object.create(prototype, {constructor: {value: URL}});
value2 = new URL(a0, a1);
value = value2 instanceof Object ? value2 : value;
} catch (error) {
return null;
}
return value;
}, safeDecodeURIComponent: function(a0) {
var decodeURIComponent;
var value;
var error;
try {
decodeURIComponent = global.decodeURIComponent;
value = decodeURIComponent(a0);
} catch (error) {
return null;
}
return value;
}};
(require(2) /* metro dependency 2 */).fileFinishedImporting('utils/URLUtils.tsx');
exports.default = object;
}
function isDiscordHostname(a0) { // fn#16803, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:776, offset: 0x00e5a4dc, size: 78 bytes, params: 2, frame: 15
const value = a1;
return a0 != null && (env0_5.test(a0) || (value !== undefined ? value : false) && env0_9.has(a0.toLowerCase()));
}
function isDiscordDirectAssetUrl(a0) { // fn#16805, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:978, offset: 0x00e5a542, size: 203 bytes, params: 2, frame: 15
var r2;
var r0;
var isDiscordBackendDevelopment2;
if (a0 == null) {
return false;
}
const value2 = (importDefault(1471) /* metro dependency 1471: URLUtils */).toURLSafe(a0);
const value3 = value2 != null;
if (value3) {
isDiscordBackendDevelopment2 = (require(1360) /* metro dependency 1360: GlobalUtils */).isDiscordBackendDevelopment();
r2 = isDiscordBackendDevelopment2 ? value2.hostname !== 'localhost' && value2.hostname !== '127.0.0.1' : !isDiscordBackendDevelopment2;
r0 = r2 ? value2.hostname === global.window.GLOBAL_ENV.CDN_HOST || env0_6.test(value2.hostname) : !r2;
} else {
r0 = value3;
}
return r0;
}
function isDiscordProxiedAssetUrl(a0, a1, a2) { // fn#16806, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:1236, offset: 0x00e5a60d, size: 209 bytes, params: 4, frame: 16
var r4;
var r0;
var value2;
var value3;
var isDiscordBackendDevelopment2;
if (isOriginalContentTypeDifferent(a1, a2)) {
if (a0 == null) {
return false;
}
value2 = (importDefault(1471) /* metro dependency 1471: URLUtils */).toURLSafe(a0);
value3 = value2 != null;
if (value3) {
isDiscordBackendDevelopment2 = (require(1360) /* metro dependency 1360: GlobalUtils */).isDiscordBackendDevelopment();
r4 = isDiscordBackendDevelopment2 ? value2.hostname !== 'localhost' && value2.hostname !== '127.0.0.1' : !isDiscordBackendDevelopment2;
r4 = !r4 ? value2.port !== '4000' : r4;
r0 = r4 ? env0_7.test(value2.hostname) : !r4;
} else {
r0 = value3;
}
return r0;
}
return false;
}
function isAllowedGifProviderUrl(a0) { // fn#16807, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:1522, offset: 0x00e5a6de, size: 78 bytes, params: 2, frame: 14
if (a0 == null) {
return false;
}
const value2 = (importDefault(1471) /* metro dependency 1471: URLUtils */).toURLSafe(a0);
return value2 != null && env0_8.has(value2.hostname);
}
function isDiscordUrl(a0) { // fn#16808, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:1639, offset: 0x00e5a72c, size: 94 bytes, params: 2, frame: 17
const value = a1;
const value2 = undefined;
if (a0 != null) {
var value3 = (importDefault(1471) /* metro dependency 1471: URLUtils */).toURLSafe(a0);
var hostname = value3 == null ? value2 : value3.hostname;
if (hostname == null) {
return false;
}
if (isDiscordHostname(hostname, value !== value2 ? value : false)) {
return true;
}
}
return false;
}
function isDiscordUri(a0) { // fn#16809, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:1791, offset: 0x00e5a78a, size: 65 bytes, params: 2, frame: 14
var r0;
var isDiscordProtocolBinding;
let value = a0 != null;
if (value) {
isDiscordProtocolBinding = isDiscordProtocol;
value = importAll(1473) /* metro dependency 1473 */;
value = isDiscordProtocolBinding(value.parse(a0).protocol);
r0 = value;
} else {
r0 = value;
}
return r0;
}
function makeUrl(a0, a1) { // fn#16810, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:1904, offset: 0x00e5a7cb, size: 126 bytes, params: 3, frame: 17
var r1;
let value = a1;
if (value != null) {
r1 = value;
} else {
value = require(1360) /* metro dependency 1360: GlobalUtils */;
value = value.isDiscordFrontendDevelopment();
r1 = value;
}
return '' + global.location.protocol + '//' + (r1 ? global.window.GLOBAL_ENV.INVITE_HOST : global.location.host) + a0;
}
function isDiscordCdnUrl(a0) { // fn#16812, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:2372, offset: 0x00e5a878, size: 80 bytes, params: 2, frame: 13
var r0;
let value = a0 != null;
if (value) {
value = importAll(1473) /* metro dependency 1473 */;
value = value.parse(a0).hostname === global.window.GLOBAL_ENV.CDN_HOST;
r0 = value;
} else {
r0 = value;
}
return r0;
}
function isDiscordAssetUrl(a0, a1, a2) { // fn#16813, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:2636, offset: 0x00e5a8c8, size: 72 bytes, params: 4, frame: 17
var r0;
var isDiscordProxiedAssetUrl2;
const isDiscordDirectAssetUrl2 = isDiscordDirectAssetUrl(a0);
if (isDiscordDirectAssetUrl2) {
r0 = !!isDiscordDirectAssetUrl2;
} else {
isDiscordProxiedAssetUrl2 = isDiscordProxiedAssetUrl(a0, a1, a2);
r0 = isDiscordProxiedAssetUrl2 ? !!isDiscordProxiedAssetUrl2 : !!isAllowedGifProviderUrl(a0);
}
return r0;
}
function isDiscordUrlOrUri(a0) { // fn#16814, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:2791, offset: 0x00e5a910, size: 31 bytes, params: 2, frame: 13
return isDiscordUrl(a0) || isDiscordUri(a0);
}
function isAppRoute(a0) { // fn#16815, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:2838, offset: 0x00e5a92f, size: 59 bytes, params: 2, frame: 12
const value = a0.toLowerCase();
return value.startsWith('/channels/') || value.startsWith(Routes.ACTIVITY);
}
function format_16816(a0) { // fn#16816, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:2932, offset: 0x00e5a96a, size: 40 bytes, params: 2, frame: 11
return (importAll(1473) /* metro dependency 1473 */).format(a0);
}
function formatPathWithQuery(a0, a1) { // fn#16817, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:2973, offset: 0x00e5a992, size: 82 bytes, params: 3, frame: 15
const moduleValue = importAll(1473) /* metro dependency 1473 */;
const format = moduleValue.format;
const object2 = {pathname: a0};
object2.query = (importDefault(22) /* metro dependency 22 */).pickBy(a1);
return Reflect.apply(format, moduleValue, [object2]);
}
function formatSearch(a0) { // fn#16818, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:3046, offset: 0x00e5a9e4, size: 74 bytes, params: 2, frame: 15
const moduleValue = importAll(1473) /* metro dependency 1473 */;
const format = moduleValue.format;
const object2 = {};
object2.query = (importDefault(22) /* metro dependency 22 */).pickBy(a0);
return Reflect.apply(format, moduleValue, [object2]);
}
function safeParseWithQuery(a0) { // fn#16819, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:1598:3091, offset: 0x00e5aa2e, size: 53 bytes, params: 2, frame: 13
var value;
var property;
var error;
try {
value = environment;
property = dependencyMap[2];
value = importAll(property);
value = value.parse(a0, true);
} catch (error) {
return null;
}
return value;
}