decord/source/utils/URLUtils.tsx

345 lines
9.6 KiB
TypeScript
Raw Normal View History

2026-08-15 05:55:55 +00:00
// Module ID: 1487
// Function ID: 1488
2026-07-29 08:29:29 +00:00
// Name: isDiscordProxiedAssetUrl
2026-08-15 05:55:55 +00:00
// Dependencies: [676, 1488, 1489, 1487, 1370, 12, 2]
2026-07-20 16:05:17 +00:00
2026-08-15 05:55:55 +00:00
// Module 1487 (isDiscordProxiedAssetUrl)
2026-08-24 06:08:38 +00:00
import applyDefault from "apply" /* 12 */;
import ME from "ME" /* 676 */;
import isDiscordFrontendDevelopment from "isDiscordFrontendDevelopment" /* 1370 */;
import isDiscordProxiedAssetUrlDefault from "isDiscordProxiedAssetUrl" /* 1487 */;
import ipDefault from "ip" /* 1488 */;
import UrlAll from "Url" /* 1489 */;
import set from "set" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-07-29 08:29:29 +00:00
function isDiscordProxiedAssetUrl(url, 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-08-24 06:08:38 +00:00
url = isDiscordProxiedAssetUrlDefault.toURLSafe(url);
2026-07-29 08:29:29 +00:00
let tmp9 = null != url;
if (tmp9) {
2026-08-24 06:08:38 +00:00
const result = isDiscordFrontendDevelopment.isDiscordBackendDevelopment();
2026-07-29 08:29:29 +00:00
let tmp5 = !result;
if (result) {
let tmp6 = "localhost" !== url.hostname;
if (tmp6) {
tmp6 = "127.0.0.1" !== url.hostname;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
tmp5 = tmp6;
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) {
2026-07-20 16:05:17 +00:00
isMatch = regex3.test(url.hostname);
}
2026-07-29 08:29:29 +00:00
tmp9 = isMatch;
2026-08-24 06:08:38 +00:00
const obj = isDiscordFrontendDevelopment;
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;
}
2026-07-29 08:29:29 +00:00
tmp = null != arg1 && null != arg2 && arg1 !== arg2;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
const Routes = ME.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$/;
let set = new Set(["media.tenor.com", "media.tenor.co", "c.tenor.com", "static.klipy.com", "media.giphy.com", "i.giphy.com"]);
2026-08-24 06:08:38 +00:00
const regExp = new RegExp("(?:(?:(?:[a-z]+:)?//)|www\\.)(?:[^\\s:@]+(?::[^\\s@]*)?@)?(?:localhost|" + ipDefault.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-07-23 10:11:24 +00:00
let result = set.fileFinishedImporting("utils/URLUtils.tsx");
2026-07-20 16:05:17 +00:00
export default {
URL_REGEX: regExp,
makeUrl(BILLING_LOGIN_HANDOFF, arg1) {
2026-07-29 08:29:29 +00:00
if (arg1 == null) {
if (!obj.isDiscordFrontendDevelopment()) {
const _location = location;
let INVITE_HOST = location.host;
}
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 = regex.test(hostname);
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) {
let tmp = null != host;
if (tmp) {
tmp = null != hostname;
}
if (tmp) {
const _window = window;
tmp = window.location.host === host;
}
return tmp;
},
2026-07-29 08:29:29 +00:00
isDiscordProtocol(protocol) {
let tmp = null != protocol;
if (tmp) {
tmp = "discord:" === protocol;
}
return tmp;
},
isDiscordUrl(ctaLink, arg1) {
let flag = arg1;
if (arg1 === undefined) {
flag = false;
}
if (null != ctaLink) {
2026-08-24 06:08:38 +00:00
const toURLSafeResult = isDiscordProxiedAssetUrlDefault.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 = regex.test(hostname);
if (!isMatch) {
if (flag) {
flag = set1.has(hostname.toLowerCase());
}
isMatch = flag;
}
tmp5 = isMatch;
}
if (tmp5) {
return true;
}
}
2026-08-24 06:08:38 +00:00
const obj = isDiscordProxiedAssetUrlDefault;
2026-07-29 08:29:29 +00:00
}
return false;
},
isDiscordUri(arg0) {
let tmp = null != arg0;
if (tmp) {
2026-08-24 06:08:38 +00:00
const protocol = UrlAll.parse(arg0).protocol;
2026-07-29 08:29:29 +00:00
let tmp4 = null != protocol;
if (tmp4) {
tmp4 = "discord:" === protocol;
}
tmp = tmp4;
2026-08-24 06:08:38 +00:00
const obj = UrlAll;
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-08-24 06:08:38 +00:00
tmp = UrlAll.parse(src).hostname === window.GLOBAL_ENV.CDN_HOST;
const obj = UrlAll;
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-08-24 06:08:38 +00:00
const toURLSafeResult = isDiscordProxiedAssetUrlDefault.toURLSafe(shareURI);
2026-07-29 08:29:29 +00:00
let tmp9 = null != toURLSafeResult;
if (tmp9) {
2026-08-24 06:08:38 +00:00
const result = isDiscordFrontendDevelopment.isDiscordBackendDevelopment();
2026-07-29 08:29:29 +00:00
let tmp3 = !result;
if (result) {
let tmp4 = "localhost" !== toURLSafeResult.hostname;
if (tmp4) {
tmp4 = "127.0.0.1" !== toURLSafeResult.hostname;
}
tmp3 = tmp4;
}
let tmp5 = !tmp3;
if (tmp3) {
const _window = window;
let isMatch = toURLSafeResult.hostname === window.GLOBAL_ENV.CDN_HOST;
if (!isMatch) {
isMatch = regex2.test(toURLSafeResult.hostname);
}
tmp5 = isMatch;
}
tmp9 = tmp5;
2026-08-24 06:08:38 +00:00
const obj = isDiscordFrontendDevelopment;
2026-07-29 08:29:29 +00:00
}
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-08-24 06:08:38 +00:00
const toURLSafeResult = isDiscordProxiedAssetUrlDefault.toURLSafe(url);
2026-07-29 08:29:29 +00:00
let hasItem = null != toURLSafeResult;
if (hasItem) {
hasItem = set.has(toURLSafeResult.hostname);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return hasItem;
2026-07-20 16:05:17 +00:00
}
},
2026-07-29 08:29:29 +00:00
isDiscordAssetUrl(url) {
let flag = false;
if (null != url) {
2026-08-24 06:08:38 +00:00
const toURLSafeResult = isDiscordProxiedAssetUrlDefault.toURLSafe(url);
2026-07-29 08:29:29 +00:00
let tmp4 = null != toURLSafeResult;
if (tmp4) {
2026-08-24 06:08:38 +00:00
const result = isDiscordFrontendDevelopment.isDiscordBackendDevelopment();
2026-07-29 08:29:29 +00:00
let tmp7 = !result;
if (result) {
let tmp8 = "localhost" !== toURLSafeResult.hostname;
if (tmp8) {
tmp8 = "127.0.0.1" !== toURLSafeResult.hostname;
}
tmp7 = tmp8;
}
let tmp9 = !tmp7;
if (tmp7) {
const _window = window;
let isMatch = toURLSafeResult.hostname === window.GLOBAL_ENV.CDN_HOST;
if (!isMatch) {
isMatch = regex2.test(toURLSafeResult.hostname);
}
tmp9 = isMatch;
}
tmp4 = tmp9;
2026-08-24 06:08:38 +00:00
const obj2 = isDiscordFrontendDevelopment;
2026-07-29 08:29:29 +00:00
}
flag = tmp4;
2026-08-24 06:08:38 +00:00
const obj = isDiscordProxiedAssetUrlDefault;
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-08-24 06:08:38 +00:00
const toURLSafeResult1 = isDiscordProxiedAssetUrlDefault.toURLSafe(url);
2026-07-29 08:29:29 +00:00
let hasItem = null != toURLSafeResult1;
if (hasItem) {
hasItem = set.has(toURLSafeResult1.hostname);
}
flag2 = hasItem;
2026-08-24 06:08:38 +00:00
const obj3 = isDiscordProxiedAssetUrlDefault;
2026-07-29 08:29:29 +00:00
}
tmp17 = flag2;
}
tmp13 = tmp17;
}
return tmp13;
},
isDiscordUrlOrUri(url) {
let flag = false;
if (null != url) {
2026-08-24 06:08:38 +00:00
const toURLSafeResult = isDiscordProxiedAssetUrlDefault.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 = regex.test(hostname) || false;
const tmp7 = regex.test(hostname) || false;
}
flag = false;
if (tmp5) {
flag = true;
}
}
2026-08-24 06:08:38 +00:00
const obj = isDiscordProxiedAssetUrlDefault;
2026-07-29 08:29:29 +00:00
}
if (!flag) {
let tmp8 = null != url;
if (tmp8) {
2026-08-24 06:08:38 +00:00
const protocol = UrlAll.parse(url).protocol;
2026-07-29 08:29:29 +00:00
let tmp11 = null != protocol;
if (tmp11) {
tmp11 = "discord:" === protocol;
}
tmp8 = tmp11;
2026-08-24 06:08:38 +00:00
const obj2 = UrlAll;
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();
let startsWithResult = formatted.startsWith("/channels/");
if (!startsWithResult) {
startsWithResult = formatted.startsWith(Routes.ACTIVITY);
}
return startsWithResult;
},
format(arg0) {
2026-08-24 06:08:38 +00:00
return UrlAll.format(arg0);
2026-07-20 16:05:17 +00:00
},
formatPathWithQuery(pathname) {
2026-08-24 06:08:38 +00:00
let obj = UrlAll;
obj = { pathname, query: applyDefault.pickBy(arg1) };
2026-07-20 16:05:17 +00:00
return obj.format(obj);
},
formatSearch(arg0) {
2026-08-24 06:08:38 +00:00
let obj = UrlAll;
obj = { query: applyDefault.pickBy(arg0) };
2026-07-20 16:05:17 +00:00
return obj.format(obj);
},
2026-07-29 08:29:29 +00:00
safeParseWithQuery(target) {
try {
2026-08-24 06:08:38 +00:00
return UrlAll.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;
const uRL = new URL(url, arg1);
return uRL;
} catch (err) {
return null;
}
2026-07-20 16:05:17 +00:00
},
safeDecodeURIComponent(hash) {
2026-07-29 08:29:29 +00:00
try {
const _decodeURIComponent = decodeURIComponent;
return decodeURIComponent(hash);
} catch (err) {
return null;
}
2026-07-20 16:05:17 +00:00
}
};