Files
discord-decomp/modules/recent_avatars/RecentAvatarUtils.tsx
T
2026-11-01 12:12:55 +02:00

129 lines
4.4 KiB
TypeScript

// Metro module 7951 (f7952).
import { Endpoints } from "../../Constants";
import * as _AvatarUtils from "../../utils/AvatarUtils";
import { isAnimatedIconHash } from "../../utils/AvatarUtils";
import { getBestMediaProxySize, getDevicePixelRatio } from "../image_upload/ImageLoaderUtils";
import Module1464 from "../../_bundle/Module1464";
import { intl, t } from "../../intl/index.native";
import { AssetOriginTypes } from "./RecentAvatarsTypes";
import { assertNever } from "../../utils/GlobalUtils";
const getArchivedAvatarURL = function getArchivedAvatarURL(a0) {
const { userId, avatarId, storageHash, canAnimate = false } = a0;
let allowWebp = a0.allowWebp;
if (allowWebp === void 0) {
allowWebp = true;
}
const size = a0.size;
const CDN_HOST = window.GLOBAL_ENV.CDN_HOST;
const r8 = CDN_HOST != null ? `https://${CDN_HOST}` : location.protocol + window.GLOBAL_ENV.API_ENDPOINT;
const r33 = canAnimate === void 0 ? false : canAnimate;
if (allowWebp === void 0) {
allowWebp = true;
}
const r10 = r33 && isAnimatedIconHash(storageHash) ? allowWebp ? _AvatarUtils.SUPPORTS_WEBP ? "webp" : "gif" : "gif" : window.GLOBAL_ENV.CDN_HOST == null ? "jpg" : allowWebp ? _AvatarUtils.SUPPORTS_WEBP ? "webp" : "png" : "png";
const r64 = {
size: getBestMediaProxySize(size * getDevicePixelRatio())
};
if (r10 === "webp" && canAnimate && isAnimatedIconHash(storageHash)) {
r64.animated = true;
}
return `${r8}${Endpoints.ARCHIVED_AVATAR(userId, avatarId, storageHash, r10)}?${Module1464.stringify(r64)}`;
};
export function getImageFormat({ storageHash, canAnimate = false, allowWebp = true }) {
return canAnimate && isAnimatedIconHash(storageHash) ? allowWebp ? _AvatarUtils.SUPPORTS_WEBP ? "webp" : "gif" : "gif" : window.GLOBAL_ENV.CDN_HOST == null ? "jpg" : allowWebp ? _AvatarUtils.SUPPORTS_WEBP ? "webp" : "png" : "png";
}
export { getArchivedAvatarURL };
export function generateAvatarDescription(a0) {
const r3 = a0 == null ? {} : a0;
let filename = r3.filename;
let assetOrigin = r3.assetOrigin;
if (assetOrigin === void 0) {
assetOrigin = AssetOriginTypes.NEW_ASSET;
}
if (assetOrigin !== AssetOriginTypes.ARCHIVED_ASSET) {
if (filename == null) {
filename = intl.string(t.lqaIxI);
}
return intl.formatToPlainString(assetOrigin === AssetOriginTypes.EDITED_ARCHIVED_ASSET ? t.eC2sZi : t.DYil93, {
name: filename,
dateTime: new Date().toLocaleString(intl.currentLocale, {
year: "numeric",
day: "numeric",
month: "long",
hour: "numeric",
minute: "numeric"
})
});
}
}
export function generateRecentAvatarFileDetails(a0, a1) {
let type;
let SUPPORTS_WEBP = _AvatarUtils.SUPPORTS_WEBP;
if (SUPPORTS_WEBP === void 0) {
SUPPORTS_WEBP = true;
}
const r20 = isAnimatedIconHash(a0) ? SUPPORTS_WEBP ? _AvatarUtils.SUPPORTS_WEBP ? "webp" : "gif" : "gif" : window.GLOBAL_ENV.CDN_HOST == null ? "jpg" : SUPPORTS_WEBP ? _AvatarUtils.SUPPORTS_WEBP ? "webp" : "png" : "png";
const r49 = {
filename: `${a1 == null ? intl.string(t.lqaIxI) : a1.split(",")[0]}.${r20}`,
type: null
};
if (r20 === "gif") {
type = "image/gif";
} else if (r20 === "png") {
type = "image/png";
} else if (r20 === "jpg") {
type = "image/jpeg";
} else {
type = "image/webp";
if (r20 !== "webp") {
assertNever(r20);
type = void 0;
}
}
r49.type = type;
return r49;
}
export function createPendingImage({ assetOrigin = AssetOriginTypes.NEW_ASSET, imageUri, description, originalAsset, originalMd5 }) {
if (AssetOriginTypes.NEW_ASSET === assetOrigin) {
return {
assetOrigin,
imageUri,
description,
originalMd5
};
}
if (AssetOriginTypes.EDITED_ARCHIVED_ASSET === assetOrigin) {
return {
assetOrigin,
imageUri,
description,
originalAsset,
originalMd5
};
}
if (AssetOriginTypes.ARCHIVED_ASSET === assetOrigin) {
return {
assetOrigin,
imageUri,
originalAsset
};
}
assertNever(assetOrigin);
}
export function getPendingAvatarSrc({ userId, image, size = 80, canAnimate = true }) {
let r12 = image;
if (image != null) {
r12 = image;
if (typeof r12 !== "string") {
r12 = image.assetOrigin === AssetOriginTypes.ARCHIVED_ASSET ? getArchivedAvatarURL({
userId,
avatarId: image.originalAsset.id,
storageHash: image.originalAsset.storageHash,
size,
canAnimate
}) : image.imageUri;
}
}
return r12;
}