decord/alpha/source/utils/URLUtils.tsx

324 lines
9.3 KiB
TypeScript
Raw Permalink Normal View History

2026-10-09 10:00:15 +00:00
// Module ID: 1384
// Function ID: 1385
// Name: URLUtils
2026-10-09 10:00:15 +00:00
// Dependencies: [1085, 1385, 1386, 1384, 1388, 12, 2]
2026-07-20 16:05:17 +00:00
2026-10-09 10:00:15 +00:00
// Module 1384 (URLUtils)
import _modDef12 from "module_12" /* 12 */;
2026-10-03 08:58:59 +00:00
import Constants from "Constants" /* 1085 */;
2026-10-09 10:00:15 +00:00
import URLUtilsDefault from "URLUtils" /* 1384 */;
import urlParseAll from "urlParse" /* 1386 */;
import GlobalUtils from "GlobalUtils" /* 1388 */;
import ip from "ip" /* 1385 */;
import size from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-07-29 08:29:29 +00:00
function isDiscordProxiedAssetUrl(url, arg1, arg2) {
2026-10-03 08:58:59 +00:00
const tmp = null != arg1 && null != arg2 && arg1 !== arg2;
2026-07-20 16:05:17 +00:00
if (tmp) {
2026-07-29 08:29:29 +00:00
if (null == url) {
2026-07-20 16:05:17 +00:00
return false;
} else {
2026-10-03 08:58:59 +00:00
const obj2 = URLUtilsDefault;
url = obj2.toURLSafe(url);
2026-07-29 08:29:29 +00:00
let tmp9 = null != url;
if (tmp9) {
2026-10-03 08:58:59 +00:00
const obj = GlobalUtils;
const result = obj.isDiscordBackendDevelopment();
2026-07-29 08:29:29 +00:00
let tmp5 = !result;
if (result) {
2026-10-03 08:58:59 +00:00
tmp5 = "localhost" !== url.hostname && "127.0.0.1" !== url.hostname;
const tmp6 = "localhost" !== url.hostname && "127.0.0.1" !== url.hostname;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (!tmp5) {
tmp5 = "4000" !== url.port;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let isMatch = !tmp5;
if (tmp5) {
isMatch = re7.test(url.hostname);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
tmp9 = isMatch;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp9;
2026-07-20 16:05:17 +00:00
}
} else {
return false;
}
}
const Routes = Constants.Routes;
2026-07-23 10:11:24 +00:00
const re5 = /(?:^|\.)(?:discordapp|discord|discordmerch)\.com$/i;
const re6 = /^.*\.discordapp\.net$/;
const re7 = /^.*\.media\.discordapp\.net$/;
const set = new Set(["media.tenor.com", "media.tenor.co", "c.tenor.com", "static.klipy.com", "media.giphy.com", "i.giphy.com"]);
const regExp = new RegExp("(?:(?:(?:[a-z]+:)?//)|www\\.)(?:[^\\s:@]+(?::[^\\s@]*)?@)?(?:localhost|" + ip.v4().source + "|(?:[a-z\\u00a1-\\uffff0-9-_]+\\.)+(?:(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:[/?#][^\\s\"]*)?", "ig");
2026-07-20 16:05:17 +00:00
const items = [window.GLOBAL_ENV.CDN_HOST, window.GLOBAL_ENV.INVITE_HOST, window.GLOBAL_ENV.GIFT_CODE_HOST, window.GLOBAL_ENV.GUILD_TEMPLATE_HOST];
const set1 = new Set(items);
2026-10-03 08:58:59 +00:00
let obj = {
2026-07-20 16:05:17 +00:00
URL_REGEX: regExp,
makeUrl(BILLING_LOGIN_HANDOFF, arg1) {
2026-07-29 08:29:29 +00:00
if (arg1 == null) {
2026-10-03 08:58:59 +00:00
let INVITE_HOST;
const obj = GlobalUtils;
2026-07-29 08:29:29 +00:00
if (!obj.isDiscordFrontendDevelopment()) {
const _location = location;
2026-10-03 08:58:59 +00:00
INVITE_HOST = location.host;
2026-07-29 08:29:29 +00:00
}
const _location2 = location;
const _HermesInternal = HermesInternal;
return "" + location.protocol + "//" + INVITE_HOST + BILLING_LOGIN_HANDOFF;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
INVITE_HOST = window.GLOBAL_ENV.INVITE_HOST;
},
isOriginalContentTypeDifferent(arg0, arg1) {
return null != arg0 && null != arg1 && arg0 !== arg1;
},
isDiscordHostname(hostname) {
let flag = arg1;
if (arg1 === undefined) {
flag = false;
}
let tmp = null != hostname;
if (tmp) {
let isMatch = re5.test(hostname);
2026-07-29 08:29:29 +00:00
if (!isMatch) {
if (flag) {
flag = set1.has(hostname.toLowerCase());
}
isMatch = flag;
}
tmp = isMatch;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp;
2026-07-20 16:05:17 +00:00
},
isDiscordLocalhost(host, hostname) {
2026-10-03 08:58:59 +00:00
let tmp = null != host && null != hostname;
2026-07-20 16:05:17 +00:00
if (tmp) {
const _window = window;
tmp = window.location.host === host;
}
return tmp;
},
2026-07-29 08:29:29 +00:00
isDiscordProtocol(protocol) {
2026-10-03 08:58:59 +00:00
return null != protocol && "discord:" === protocol;
2026-07-29 08:29:29 +00:00
},
isDiscordUrl(ctaLink, arg1) {
let flag = arg1;
if (arg1 === undefined) {
flag = false;
}
if (null != ctaLink) {
2026-10-03 08:58:59 +00:00
const obj = URLUtilsDefault;
const toURLSafeResult = obj.toURLSafe(ctaLink);
2026-07-29 08:29:29 +00:00
let hostname;
if (toURLSafeResult != null) {
hostname = toURLSafeResult.hostname;
}
if (null != hostname) {
if (flag === undefined) {
flag = false;
}
let tmp5 = null != hostname;
if (tmp5) {
let isMatch = re5.test(hostname);
2026-07-29 08:29:29 +00:00
if (!isMatch) {
if (flag) {
flag = set1.has(hostname.toLowerCase());
}
isMatch = flag;
}
tmp5 = isMatch;
}
if (tmp5) {
return true;
}
}
}
return false;
},
isDiscordUri(arg0) {
let tmp = null != arg0;
if (tmp) {
2026-10-03 08:58:59 +00:00
const obj = urlParseAll;
const protocol = obj.parse(arg0).protocol;
tmp = null != protocol && "discord:" === protocol;
const tmp4 = null != protocol && "discord:" === protocol;
2026-07-29 08:29:29 +00:00
}
return tmp;
},
2026-07-20 16:05:17 +00:00
isDiscordCdnUrl(src) {
let tmp = null != src;
if (tmp) {
const _window = window;
2026-10-03 08:58:59 +00:00
const obj = urlParseAll;
tmp = obj.parse(src).hostname === window.GLOBAL_ENV.CDN_HOST;
2026-07-20 16:05:17 +00:00
}
return tmp;
},
2026-08-04 08:36:32 +00:00
isDiscordDirectAssetUrl(shareURI) {
if (null == shareURI) {
2026-07-29 08:29:29 +00:00
return false;
} else {
2026-10-03 08:58:59 +00:00
const obj2 = URLUtilsDefault;
const toURLSafeResult = obj2.toURLSafe(shareURI);
2026-07-29 08:29:29 +00:00
let tmp9 = null != toURLSafeResult;
if (tmp9) {
2026-10-03 08:58:59 +00:00
const obj = GlobalUtils;
const result = obj.isDiscordBackendDevelopment();
2026-07-29 08:29:29 +00:00
let tmp3 = !result;
if (result) {
2026-10-03 08:58:59 +00:00
tmp3 = "localhost" !== toURLSafeResult.hostname && "127.0.0.1" !== toURLSafeResult.hostname;
const tmp4 = "localhost" !== toURLSafeResult.hostname && "127.0.0.1" !== toURLSafeResult.hostname;
2026-07-29 08:29:29 +00:00
}
let tmp5 = !tmp3;
if (tmp3) {
const _window = window;
2026-10-03 08:58:59 +00:00
const isMatch = toURLSafeResult.hostname === window.GLOBAL_ENV.CDN_HOST || re6.test(toURLSafeResult.hostname);
2026-07-29 08:29:29 +00:00
tmp5 = isMatch;
}
tmp9 = tmp5;
}
return tmp9;
}
},
2026-07-20 16:05:17 +00:00
isDiscordProxiedAssetUrl,
2026-07-29 08:29:29 +00:00
isAllowedGifProviderUrl(url) {
if (null == url) {
return false;
} else {
2026-10-03 08:58:59 +00:00
const obj = URLUtilsDefault;
const toURLSafeResult = obj.toURLSafe(url);
const hasItem = null != toURLSafeResult && set.has(toURLSafeResult.hostname);
2026-07-29 08:29:29 +00:00
return hasItem;
2026-07-20 16:05:17 +00:00
}
},
isDiscordAssetUrl(url, arg1, arg2) {
2026-07-29 08:29:29 +00:00
let flag = false;
if (null != url) {
2026-10-03 08:58:59 +00:00
const obj = URLUtilsDefault;
const toURLSafeResult = obj.toURLSafe(url);
2026-07-29 08:29:29 +00:00
let tmp4 = null != toURLSafeResult;
if (tmp4) {
2026-10-03 08:58:59 +00:00
const obj2 = GlobalUtils;
const result = obj2.isDiscordBackendDevelopment();
2026-07-29 08:29:29 +00:00
let tmp7 = !result;
if (result) {
2026-10-03 08:58:59 +00:00
tmp7 = "localhost" !== toURLSafeResult.hostname && "127.0.0.1" !== toURLSafeResult.hostname;
const tmp8 = "localhost" !== toURLSafeResult.hostname && "127.0.0.1" !== toURLSafeResult.hostname;
2026-07-29 08:29:29 +00:00
}
let tmp9 = !tmp7;
if (tmp7) {
const _window = window;
2026-10-03 08:58:59 +00:00
const isMatch = toURLSafeResult.hostname === window.GLOBAL_ENV.CDN_HOST || re6.test(toURLSafeResult.hostname);
2026-07-29 08:29:29 +00:00
tmp9 = isMatch;
}
tmp4 = tmp9;
}
flag = tmp4;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let tmp13 = flag;
if (!tmp13) {
let tmp17 = isDiscordProxiedAssetUrl(url, arg1, arg2);
if (!tmp17) {
let flag2 = false;
if (null != url) {
2026-10-03 08:58:59 +00:00
const obj3 = URLUtilsDefault;
const toURLSafeResult1 = obj3.toURLSafe(url);
const hasItem = null != toURLSafeResult1 && set.has(toURLSafeResult1.hostname);
2026-07-29 08:29:29 +00:00
flag2 = hasItem;
}
tmp17 = flag2;
}
tmp13 = tmp17;
}
return tmp13;
},
isDiscordUrlOrUri(url) {
let flag = false;
if (null != url) {
2026-10-03 08:58:59 +00:00
const obj = URLUtilsDefault;
const toURLSafeResult = obj.toURLSafe(url);
2026-07-29 08:29:29 +00:00
let hostname;
if (toURLSafeResult != null) {
hostname = toURLSafeResult.hostname;
}
flag = false;
if (null != hostname) {
let tmp5 = null != hostname;
if (tmp5) {
tmp5 = re5.test(hostname) || false;
2026-10-03 08:58:59 +00:00
re5.test(hostname) || false;
2026-07-29 08:29:29 +00:00
}
flag = false;
if (tmp5) {
flag = true;
}
}
}
if (!flag) {
let tmp8 = null != url;
if (tmp8) {
2026-10-03 08:58:59 +00:00
const obj2 = urlParseAll;
const protocol = obj2.parse(url).protocol;
tmp8 = null != protocol && "discord:" === protocol;
const tmp11 = null != protocol && "discord:" === protocol;
2026-07-29 08:29:29 +00:00
}
flag = tmp8;
}
return flag;
2026-07-20 16:05:17 +00:00
},
isAppRoute(pathname) {
const formatted = pathname.toLowerCase();
2026-10-03 08:58:59 +00:00
const startsWithResult = formatted.startsWith("/channels/") || formatted.startsWith(Routes.ACTIVITY);
2026-07-20 16:05:17 +00:00
return startsWithResult;
},
format(arg0) {
2026-10-03 08:58:59 +00:00
const obj = urlParseAll;
return obj.format(arg0);
2026-07-20 16:05:17 +00:00
},
formatPathWithQuery(pathname, arg1) {
2026-10-03 08:58:59 +00:00
let obj2;
const obj = { pathname, query: obj2.pickBy(arg1) };
const format = urlParseAll.format;
urlParseAll;
obj2 = _modDef12;
return format(obj);
2026-07-20 16:05:17 +00:00
},
formatSearch(arg0) {
2026-10-03 08:58:59 +00:00
let obj2;
const obj = { query: obj2.pickBy(arg0) };
const format = urlParseAll.format;
urlParseAll;
obj2 = _modDef12;
return format(obj);
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
safeParseWithQuery(target) {
try {
2026-10-03 08:58:59 +00:00
const obj = urlParseAll;
return obj.parse(target, true);
2026-07-29 08:29:29 +00:00
} catch (err) {
return null;
}
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
toURLSafe(url, arg1) {
try {
const _URL = URL;
2026-10-03 08:58:59 +00:00
const self = this;
const self2 = this;
2026-07-29 08:29:29 +00:00
const uRL = new URL(url, arg1);
return uRL;
} catch (err) {
return null;
}
2026-07-20 16:05:17 +00:00
},
safeDecodeURIComponent(parts) {
2026-07-29 08:29:29 +00:00
try {
const _decodeURIComponent = decodeURIComponent;
return decodeURIComponent(parts);
2026-07-29 08:29:29 +00:00
} catch (err) {
return null;
}
2026-07-20 16:05:17 +00:00
}
};
2026-10-03 08:58:59 +00:00
let result = size.fileFinishedImporting("utils/URLUtils.tsx");
export default obj;