Files
discord-decomp/modules/quests/lib/AssetUtils.tsx
T
2026-11-01 12:12:55 +02:00

405 lines
12 KiB
TypeScript

// Metro module 9479 (f9480).
import { CDN_URL_BASE, QUESTS_CDN_URL_BASE } from "../QuestConstants";
import { MEDIA_PROXY_MAX_TARGET_RESOLUTION } from "../../../Constants";
import Module9480 from "../../../_bundle/Module9480";
import Module9481 from "../../../_bundle/Module9481";
import Module9482 from "../../../_bundle/Module9482";
import Module9483 from "../../../_bundle/Module9483";
import { getQuestPrimaryReward } from "../utils/QuestRewardUtils";
import { QuestRewardTypes } from "../../../_bundle/Module5990";
import Module9491 from "../../../_bundle/Module9491";
import Module9492 from "../../../_bundle/Module9492";
import { FirstPartyQuestTaskTypes } from "../../../_bundle/Module5040";
import URLUtils from "../../../utils/URLUtils";
import getDevicePixelRatio_native from "../../../utils/getDevicePixelRatio.native";
let c6253_6, _excluded, c6253_8, c6253_10, c6253_11, getMimetype, getAssetUrlWithMediaProxyQueryParams, convertVideoToFirstFrameImageWithMediaProxy;
const resolveAsset = function resolveAsset(id, a1, a2) {
let url;
if (a1.startsWith("blob:")) {
let r41 = a1.split("?", 1).at(0);
if (r41 == null) {
r41 = a1;
}
url = r41;
} else {
url = a1.includes("/") ? `${CDN_URL_BASE}${a1}` : `${QUESTS_CDN_URL_BASE}${id}${a2?.theme != null ? `/${a2.theme}` : ""}/${a1}`;
}
const mimetype = getMimetype(a1);
return {
url,
mimetype,
isAnimated: mimetype != null && _excluded.includes(mimetype)
};
};
getMimetype = function getMimetype(a0) {
const r5 = a0.startsWith("blob:");
const r16 = URLUtils.toURLSafe(a0);
const r2 = r16 == null;
if (r5) {
let r40 = r2 ? void 0 : r16.searchParams.get("mimetype");
if (r40 == null) {
r40 = void 0;
}
return r40 != null ? decodeURIComponent(r40) : null;
}
let r18 = void 0;
if (!r2) {
const r19 = r16.searchParams.get("format");
r18 = r19 == null ? void 0 : r19.toLowerCase();
}
if (r18 == null) {
const r23 = c6253_6.exec(a0);
const r24 = r23 == null;
let r25 = void 0;
if (!r24) {
const r26 = r23[1];
r25 = r26 == null ? void 0 : r26.toLowerCase();
}
r18 = r25;
}
switch (r18) {
case "webm":
return "video/webm";
case "mp4":
return "video/mp4";
case "webp":
return "image/webp";
case "jpg":
case "jpeg":
return "image/jpeg";
case "png":
return "image/png";
case "gif":
return "image/gif";
case "svg":
return "image/svg+xml";
case "txt":
return "text/plain";
case "vtt":
return "text/vtt";
case "ts":
return "video/mp2t";
case "m3u8":
return "application/x-mpegURL";
default:
return null;
}
};
getAssetUrlWithMediaProxyQueryParams = function getAssetUrlWithMediaProxyQueryParams(assetUrl, r3 = {}) {
if (assetUrl.startsWith("blob:")) {
return assetUrl;
}
const r20 = URLUtils.toURLSafe(assetUrl);
let r22 = assetUrl;
if (r20 != null) {
if (r3.format != null) {
r20.searchParams.set("format", r3.format);
}
if (r3.width != null) {
r20.searchParams.set("width", `${Math.min(Math.ceil(r3.width), MEDIA_PROXY_MAX_TARGET_RESOLUTION)}`);
}
if (r3.height != null) {
r20.searchParams.set("height", `${Math.min(Math.ceil(r3.height), MEDIA_PROXY_MAX_TARGET_RESOLUTION)}`);
}
r22 = r20.toString();
}
return r22;
};
convertVideoToFirstFrameImageWithMediaProxy = function convertVideoToFirstFrameImageWithMediaProxy(assetUrl, a1) {
if (assetUrl.startsWith("blob:")) {
return assetUrl;
}
const r5 = URLUtils.toURLSafe(assetUrl);
const r1 = r5 == null;
let r22 = null;
if (!r1) {
r5.searchParams.set("format", "webp");
if (a1 != null) {
r5.searchParams.set("width", `${Math.min(Math.ceil(a1.width), MEDIA_PROXY_MAX_TARGET_RESOLUTION)}`);
r5.searchParams.set("height", `${Math.min(Math.ceil(a1.height), MEDIA_PROXY_MAX_TARGET_RESOLUTION)}`);
}
r22 = r5.toString();
}
return r22;
};
c6253_6 = /\.([a-zA-Z0-9]+)$/;
_excluded = ["video/mp4", "video/webm"];
c6253_8 = {
HERO: "hero",
HERO_IMAGE: "hero_image",
HERO_VIDEO: "hero_video",
QUEST_BAR_HERO: "quest_bar_hero",
QUEST_BAR_HERO_VIDEO: "quest_bar_hero_video",
QUEST_BAR_HERO_IMAGE: "quest_bar_hero_image",
REWARD: "reward",
REWARD_IMAGE: "reward_image",
GAME_TILE: "game_tile",
LOGO_TYPE: "logo_type",
COSPONSOR_LOGO_TYPE: "cosponsor_logo_type",
VIDEO_PLAYER_VIDEO: "video_player_video",
VIDEO_PLAYER_VIDEO_LOW_RES: "video_player_video_low_res",
VIDEO_PLAYER_VIDEO_HLS: "video_player_video_hls",
VIDEO_PLAYER_THUMBNAIL: "video_player_thumbnail",
VIDEO_PLAYER_CAPTION: "video_player_caption",
VIDEO_PLAYER_TRANSCRIPT: "video_player_transcript"
};
const r19 = {
VIDEO: "video",
VIDEO_LOW_RES: "videoLowRes",
VIDEO_HLS: "videoHls"
};
const r18 = {
VIDEO: "url",
THUMBNAIL: "thumbnail",
CAPTION: "caption",
TRANSCRIPT: "transcript"
};
const r57 = {
TIER_1: 1,
1: "TIER_1",
TIER_2: 2,
2: "TIER_2",
TIER_3: 3,
3: "TIER_3",
TIER_4: 4,
4: "TIER_4"
};
const r64 = {};
r64[c6253_8.VIDEO_PLAYER_VIDEO] = {
variant: r19.VIDEO,
property: r18.VIDEO
};
r64[c6253_8.VIDEO_PLAYER_VIDEO_LOW_RES] = {
variant: r19.VIDEO_LOW_RES,
property: r18.VIDEO
};
r64[c6253_8.VIDEO_PLAYER_VIDEO_HLS] = {
variant: r19.VIDEO_HLS,
property: r18.VIDEO
};
r64[c6253_8.VIDEO_PLAYER_THUMBNAIL] = {
variant: r19.VIDEO,
property: r18.THUMBNAIL
};
r64[c6253_8.VIDEO_PLAYER_CAPTION] = {
variant: r19.VIDEO,
property: r18.CAPTION
};
r64[c6253_8.VIDEO_PLAYER_TRANSCRIPT] = {
variant: r19.VIDEO,
property: r18.TRANSCRIPT
};
c6253_10 = r64;
const r86 = {};
r86[r57.TIER_1] = Module9480;
r86[r57.TIER_2] = Module9481;
r86[r57.TIER_3] = Module9482;
r86[r57.TIER_4] = Module9483;
c6253_11 = r86;
export { c6253_6 as EXTENSION_RE };
export { _excluded as ANIMATED_MIMETYPES };
export { c6253_8 as QuestAssetType };
export { resolveAsset };
export { r57 as OrbsValueTier };
export function getQuestAsset(a0, a1, a2, a3, a4) {
let r0, r1, hero;
L72: {
if (c6253_8.HERO === a1) {
a0.config.assets.heroVideo;
hero = a0.config.assets.hero;
r0 = false;
r1 = false;
} else if (c6253_8.HERO_IMAGE === a1) {
hero = a0.config.assets.hero;
r0 = false;
r1 = false;
} else if (c6253_8.HERO_VIDEO === a1) {
const heroVideo = a0.config.assets.heroVideo;
const r158 = heroVideo == null;
r0 = false;
r1 = false;
hero = heroVideo;
if (r158) {
return null;
}
} else if (c6253_8.QUEST_BAR_HERO === a1) {
a0.config.assets.questBarHeroVideo;
hero = a0.config.assets.questBarHero;
r0 = false;
r1 = false;
} else if (c6253_8.QUEST_BAR_HERO_VIDEO === a1) {
const questBarHeroVideo = a0.config.assets.questBarHeroVideo;
const r148 = questBarHeroVideo == null;
r0 = false;
r1 = false;
hero = questBarHeroVideo;
if (r148) {
return null;
}
} else if (c6253_8.QUEST_BAR_HERO_IMAGE === a1) {
hero = a0.config.assets.questBarHero;
r0 = false;
r1 = false;
} else if (c6253_8.REWARD === a1) {
const questPrimaryReward2 = getQuestPrimaryReward(a0);
if (questPrimaryReward2.type === QuestRewardTypes.VIRTUAL_CURRENCY) {
const url = a4 != null ? c6253_11[a4] : void 0;
return url != null ? {
url,
mimetype: "video/webm",
isAnimated: true
} : a3 ? {
url: Module9491,
mimetype: "video/mp4",
isAnimated: true
} : {
url: Module9492,
mimetype: "video/webm",
isAnimated: true
};
}
questPrimaryReward2.assetVideo;
hero = questPrimaryReward2.asset;
r0 = false;
r1 = false;
} else if (c6253_8.REWARD_IMAGE === a1) {
const questPrimaryReward = getQuestPrimaryReward(a0);
if (questPrimaryReward.type === QuestRewardTypes.VIRTUAL_CURRENCY) {
return null;
}
hero = questPrimaryReward.asset;
r0 = false;
r1 = false;
} else if (c6253_8.GAME_TILE === a1) {
if (a2 === "dark" && a0.config.assets.gameTileDark != null) {
hero = a0.config.assets.gameTileDark;
r0 = false;
r1 = false;
break L72;
}
if (a2 === "light" && a0.config.assets.gameTileLight != null) {
hero = a0.config.assets.gameTileLight;
r0 = false;
r1 = false;
break L72;
}
hero = a0.config.assets.gameTile;
r0 = false;
r1 = true;
} else if (c6253_8.LOGO_TYPE === a1) {
if (a2 === "dark" && a0.config.assets.logotypeDark != null) {
hero = a0.config.assets.logotypeDark;
r0 = false;
r1 = false;
break L72;
}
if (a2 === "light" && a0.config.assets.logotypeLight != null) {
hero = a0.config.assets.logotypeLight;
r0 = false;
r1 = false;
break L72;
}
hero = a0.config.assets.logotype;
r0 = false;
r1 = true;
} else if (c6253_8.COSPONSOR_LOGO_TYPE === a1) {
if (a0.config.cosponsorMetadata == null) {
return null;
}
if (a2 === "dark" && a0.config.cosponsorMetadata.logotypeDark != null) {
hero = a0.config.cosponsorMetadata.logotypeDark;
r0 = false;
r1 = false;
break L72;
}
if (a2 === "light" && a0.config.cosponsorMetadata.logotypeLight != null) {
hero = a0.config.cosponsorMetadata.logotypeLight;
r0 = false;
r1 = false;
break L72;
}
hero = a0.config.cosponsorMetadata.logotype;
r0 = false;
r1 = true;
} else {
if (c6253_8.VIDEO_PLAYER_VIDEO !== a1 && c6253_8.VIDEO_PLAYER_VIDEO_LOW_RES !== a1 && c6253_8.VIDEO_PLAYER_VIDEO_HLS !== a1 && c6253_8.VIDEO_PLAYER_THUMBNAIL !== a1 && c6253_8.VIDEO_PLAYER_CAPTION !== a1) {
const VIDEO_PLAYER_TRANSCRIPT = c6253_8.VIDEO_PLAYER_TRANSCRIPT;
r0 = false;
r1 = false;
hero = void 0;
if (VIDEO_PLAYER_TRANSCRIPT !== a1) {
break L72;
}
}
if (!("taskConfigV2" in a0.config)) {
return null;
}
const r43 = a0.config.taskConfigV2.tasks[a3 ? FirstPartyQuestTaskTypes.WATCH_VIDEO_ON_MOBILE : FirstPartyQuestTaskTypes.WATCH_VIDEO];
const r45 = c6253_10[a1];
const r3 = r43 == null;
let r47 = void 0;
if (!r3) {
const r50 = r43.assets[r45.variant];
r47 = r50 == null ? void 0 : r50[r45.property];
}
const r53 = r47 == null;
r0 = true;
r1 = false;
hero = r47;
if (r53) {
return null;
}
}
}
const r171 = resolveAsset(a0.id, hero, {
theme: r1 ? a2 : void 0
});
return r0 ? r171.mimetype != null ? r171 : null : r171;
}
export function buildUrl(a0, a1, a2) {
if (a1.startsWith("blob:")) {
let r41 = a1.split("?", 1).at(0);
if (r41 == null) {
r41 = a1;
}
return r41;
}
return a1.includes("/") ? `${CDN_URL_BASE}${a1}` : `${QUESTS_CDN_URL_BASE}${a0}${a2?.theme != null ? `/${a2.theme}` : ""}/${a1}`;
}
export function resolveOptionalAdCreativeCdnUrl(a0) {
if (a0 != null) {
return a0.startsWith("http://") ? a0 : a0.startsWith("https://") ? a0 : a0.startsWith("blob:") ? a0 : `${CDN_URL_BASE}${a0}`;
}
}
export function resolveAdCreativeCdnUrl(a0) {
return a0.startsWith("http://") ? a0 : a0.startsWith("https://") ? a0 : a0.startsWith("blob:") ? a0 : `${CDN_URL_BASE}${a0}`;
}
export { getMimetype };
export function getDevicePixelScaledDimensions(a0, a1) {
const devicePixelRatio_native = getDevicePixelRatio_native();
return devicePixelRatio_native < 3 ? {
width: a0,
height: a1
} : {
width: a0 * devicePixelRatio_native,
height: a1 * devicePixelRatio_native
};
}
export { getAssetUrlWithMediaProxyQueryParams };
export function getScaledImageUrl({ assetUrl, width, height }) {
const devicePixelRatio_native = getDevicePixelRatio_native();
return getAssetUrlWithMediaProxyQueryParams(assetUrl, {
width: width * devicePixelRatio_native,
height: height * devicePixelRatio_native,
format: "webp"
});
}
export { convertVideoToFirstFrameImageWithMediaProxy };
export function getScaledFirstFrameImageUrl({ assetUrl, width, height }) {
const devicePixelRatio_native = getDevicePixelRatio_native();
return convertVideoToFirstFrameImageWithMediaProxy(assetUrl, {
width: width * devicePixelRatio_native,
height: height * devicePixelRatio_native
});
}