decord/alpha/source/modules/image_proxy/ImageProxyUtils.tsx

119 lines
3.9 KiB
TypeScript
Raw Normal View History

2026-10-03 08:58:59 +00:00
// Module ID: 2022
// Function ID: 2023
// Name: ImageProxyUtils
2026-10-03 08:58:59 +00:00
// Dependencies: [2023, 1437, 1371, 2]
2026-08-25 06:04:03 +00:00
// Exports: getSizedImageAssetURL, isImageProxyURL
2026-07-20 16:05:17 +00:00
2026-10-03 08:58:59 +00:00
// Module 2022 (ImageProxyUtils)
import URLUtilsDefault from "URLUtils" /* 1371 */;
import ImageLoaderUtils from "ImageLoaderUtils" /* 1437 */;
import UrlHostUtils from "UrlHostUtils" /* 2023 */;
import size_mod from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-08-25 06:04:03 +00:00
function getSizedImageProxyURL(value, size) {
2026-10-03 08:58:59 +00:00
let format;
let keepAspectRatio;
const obj = URLUtilsDefault;
const str = obj.toURLSafe(value);
2026-08-25 06:04:03 +00:00
if (null != str) {
2026-10-03 08:58:59 +00:00
let startsWithResult = _Set1.has(str.hostname);
2026-08-25 06:04:03 +00:00
if (startsWithResult) {
const pathname = str.pathname;
startsWithResult = pathname.startsWith("/external/");
}
if (startsWithResult) {
if (null != size.size) {
const _String = String;
2026-10-03 08:58:59 +00:00
size = size.size;
const getBestMediaProxySize = ImageLoaderUtils.getBestMediaProxySize;
ImageLoaderUtils;
const obj2 = ImageLoaderUtils;
2026-10-03 08:58:59 +00:00
const StringResult = String(getBestMediaProxySize(size * obj2.getDevicePixelRatio()));
2026-08-25 06:04:03 +00:00
const searchParams = str.searchParams;
const result = searchParams.set("width", StringResult);
const searchParams2 = str.searchParams;
const result1 = searchParams2.set("height", StringResult);
}
({ keepAspectRatio, format } = size);
if (null != keepAspectRatio) {
const searchParams3 = str.searchParams;
const _String2 = String;
const result2 = searchParams3.set("keep_aspect_ratio", String(keepAspectRatio));
}
if (null != format) {
const searchParams4 = str.searchParams;
const result3 = searchParams4.set("format", format);
}
return str.toString();
}
}
return value;
}
2026-10-03 08:58:59 +00:00
let str = window.GLOBAL_ENV.IMAGE_PROXY_ENDPOINTS;
2026-07-29 08:29:29 +00:00
let parts;
2026-10-03 08:58:59 +00:00
const _Set = Set;
if (str != null) {
2026-07-29 08:29:29 +00:00
parts = str.split(",");
}
if (parts == null) {
parts = [];
}
2026-07-20 16:05:17 +00:00
function isImageProxyURL(hostname) {
2026-10-03 08:58:59 +00:00
let startsWithResult = _Set1.has(hostname.hostname);
2026-07-29 08:29:29 +00:00
if (startsWithResult) {
2026-07-20 16:05:17 +00:00
const pathname = hostname.pathname;
startsWithResult = pathname.startsWith("/external/");
}
return startsWithResult;
}
const mapped = parts.map((item) => item.substring(2));
const mapped1 = mapped.map(UrlHostUtils.getHostWithoutPort);
2026-10-03 08:58:59 +00:00
const _Set1 = new _Set(mapped1.filter(Boolean));
let size = size_mod;
let result = size.fileFinishedImporting("modules/image_proxy/ImageProxyUtils.tsx");
2026-07-20 16:05:17 +00:00
export { isImageProxyURL };
2026-08-25 06:04:03 +00:00
export { getSizedImageProxyURL };
export const getSizedImageAssetURL = function getSizedImageAssetURL(value, size) {
2026-10-03 08:58:59 +00:00
const obj = URLUtilsDefault;
const str = obj.toURLSafe(value);
2026-08-25 06:04:03 +00:00
if (null == str) {
return value;
} else {
2026-10-03 08:58:59 +00:00
let startsWithResult = _Set1.has(str.hostname);
2026-07-29 08:29:29 +00:00
if (startsWithResult) {
const pathname = str.pathname;
startsWithResult = pathname.startsWith("/external/");
}
if (startsWithResult) {
return getSizedImageProxyURL(value, size);
2026-08-25 06:04:03 +00:00
} else {
2026-10-03 08:58:59 +00:00
const tmpResult = URLUtilsDefault;
2026-08-25 06:04:03 +00:00
if (tmpResult.isDiscordCdnUrl(value)) {
if (null != size.size) {
const _String = String;
2026-10-03 08:58:59 +00:00
size = size.size;
const getBestMediaProxySize = ImageLoaderUtils.getBestMediaProxySize;
ImageLoaderUtils;
const obj3 = ImageLoaderUtils;
2026-10-03 08:58:59 +00:00
const StringResult = String(getBestMediaProxySize(size * obj3.getDevicePixelRatio()));
const _Number2 = Number;
const searchParams2 = str.searchParams;
const NumberResult = Number(searchParams2.get("size"));
if (NumberResult > 0) {
const _Number = Number;
if (Number(StringResult) > NumberResult) {
return value;
}
}
const searchParams = str.searchParams;
const result = searchParams.set("size", StringResult);
2026-08-25 06:04:03 +00:00
}
return str.toString();
} else {
return value;
2026-07-20 16:05:17 +00:00
}
}
}
};