165 lines
4.8 KiB
TypeScript
165 lines
4.8 KiB
TypeScript
// Metro module 9599 (f9600).
|
|
import { Endpoints } from "../../Constants";
|
|
import Durations from "../../utils/Durations";
|
|
import { isImageProxyURL } from "../image_proxy/ImageProxyUtils";
|
|
import URLUtils from "../../utils/URLUtils";
|
|
import { HTTP, rejectWithMigratedError } from "../../_bundle/sendRequest";
|
|
function $mk82857($env) {
|
|
return (a0) => $env[0].pathname.startsWith(a0);
|
|
}
|
|
let isAttachmentExpired, isEmbedMediaExpiredAttachment, embedHasExpiredAttachmentUrl, c6341_5, c6341_6, c6341_7;
|
|
let env6341 = {};
|
|
const shouldRefreshAttachmentUrl = function shouldRefreshAttachmentUrl(a0) {
|
|
let r10 = a0.searchParams.get("ex");
|
|
const r6 = parseInt;
|
|
if (r10 == null) {
|
|
r10 = "";
|
|
}
|
|
const r7 = r6(r10, 16);
|
|
const r15 = isNaN(r7) ? void 0 : r7 * Durations.Millis.SECOND;
|
|
return r15 == null || r15 <= Date.now() + c6341_6;
|
|
};
|
|
isAttachmentExpired = function isAttachmentExpired(a0) {
|
|
const r13 = URLUtils.toURLSafe(a0.url);
|
|
let r2 = r13 != null;
|
|
if (r2) {
|
|
let r17 = r13.searchParams.get("ex");
|
|
const r19 = parseInt;
|
|
if (r17 == null) {
|
|
r17 = "";
|
|
}
|
|
const r20 = r19(r17, 16);
|
|
const r22 = isNaN(r20) ? void 0 : r20 * Durations.Millis.SECOND;
|
|
r2 = r22 == null || r22 <= Date.now() + c6341_6;
|
|
}
|
|
return r2;
|
|
};
|
|
isEmbedMediaExpiredAttachment = function isEmbedMediaExpiredAttachment(a0) {
|
|
if (a0 == null) {
|
|
return false;
|
|
}
|
|
const r17 = URLUtils.toURLSafe(a0.url);
|
|
let r3 = r17 != null;
|
|
if (r3) {
|
|
let env17334;
|
|
const r11 = env17334 = {};
|
|
env17334[0] = r17;
|
|
const r20 = c6341_7.has(r17.hostname);
|
|
const r26 = Array.from(c6341_5).some($mk82857(r11));
|
|
let r29 = !!(!!r20 && r26);
|
|
if (r29) {
|
|
let r33 = r17.searchParams.get("ex");
|
|
const r34 = parseInt;
|
|
if (r33 == null) {
|
|
r33 = "";
|
|
}
|
|
const r35 = r34(r33, 16);
|
|
const r38 = isNaN(r35) ? void 0 : r35 * Durations.Millis.SECOND;
|
|
r29 = r38 == null || r38 <= Date.now() + c6341_6;
|
|
}
|
|
r3 = r29;
|
|
}
|
|
return r3;
|
|
};
|
|
embedHasExpiredAttachmentUrl = function embedHasExpiredAttachmentUrl(a0) {
|
|
let r9 = isEmbedMediaExpiredAttachment(a0.image);
|
|
if (!r9) {
|
|
const images = a0.images;
|
|
r9 = images == null ? void 0 : images.some(isEmbedMediaExpiredAttachment);
|
|
}
|
|
if (!r9) {
|
|
r9 = isEmbedMediaExpiredAttachment(a0.video);
|
|
}
|
|
return r9;
|
|
};
|
|
env6341[12] = function _refreshAttachmentUrl() {
|
|
const r8 = async (c26481_0) => {
|
|
let c30116_0 = await HTTP.post({
|
|
url: Endpoints.ATTACHMENTS_REFRESH_URLS,
|
|
body: {
|
|
attachment_urls: [c26481_0]
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
return c30116_0.ok ? c30116_0.body.refreshed_urls[0].refreshed : void 0;
|
|
};
|
|
env6341[12] = r8;
|
|
return r8.apply(this, arguments);
|
|
};
|
|
c6341_5 = new Set(["/attachments/", "/ephemeral-attachments/"]);
|
|
c6341_6 = 1 * Durations.Millis.HOUR;
|
|
const r39 = Set;
|
|
const r13 = [window.GLOBAL_ENV.CDN_HOST, ,];
|
|
const MEDIA_PROXY_ENDPOINT = window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT;
|
|
const r47 = MEDIA_PROXY_ENDPOINT == null ? void 0 : MEDIA_PROXY_ENDPOINT.substring(2);
|
|
export function isAttachmentUrl(a0) {
|
|
let env17333;
|
|
const r2 = env17333 = {};
|
|
env17333[0] = a0;
|
|
const r7 = c6341_7.has(a0.hostname);
|
|
const r15 = Array.from(c6341_5).some($mk82857(r2));
|
|
return !!r7 && r15;
|
|
}
|
|
export function getSignedAttachmentExpiration(a0) {
|
|
let r7 = a0.searchParams.get("ex");
|
|
const r9 = parseInt;
|
|
if (r7 == null) {
|
|
r7 = "";
|
|
}
|
|
const r11 = r9(r7, 16);
|
|
return isNaN(r11) ? void 0 : r11 * Durations.Millis.SECOND;
|
|
}
|
|
r13[1] = r47;
|
|
c6341_7 = new r39(r13.map(function getHostWithoutPort(item) {
|
|
return item == null ? void 0 : item.split(":")[0];
|
|
}).filter(Boolean));
|
|
export function isExternalProxiedAttachmentUrl(a0) {
|
|
return isImageProxyURL(a0);
|
|
}
|
|
export function removeSignedUrlParameters(a0) {
|
|
const r23 = URLUtils.toURLSafe(a0);
|
|
if (r23 == null) {
|
|
return a0;
|
|
}
|
|
for (const item of ["ex", "is", "hm"]) {
|
|
r23.searchParams.delete(item);
|
|
}
|
|
return r23;
|
|
}
|
|
export function messageHasExpiredAttachmentUrl(a0) {
|
|
return a0.attachments.some(isAttachmentExpired) || a0.embeds.some(embedHasExpiredAttachmentUrl);
|
|
}
|
|
export async function maybeRefreshAttachmentUrl(value) {
|
|
let r52;
|
|
let value2, c26482_2;
|
|
L17: {
|
|
L16: {
|
|
let env30117;
|
|
const r12 = env30117 = {
|
|
$parent: env6341
|
|
};
|
|
c26482_2 = r12;
|
|
env30117[0] = value;
|
|
env30117[1] = void 0;
|
|
const r28 = URLUtils.toURLSafe(value);
|
|
if (r28 == null) {
|
|
break L17;
|
|
}
|
|
if (shouldRefreshAttachmentUrl(r28)) {
|
|
env30117[1] = await (function refreshAttachmentUrl() {
|
|
return env6341[12].apply(this, arguments);
|
|
})(value);
|
|
value2 = env30117[1];
|
|
if (value2 == null) {
|
|
value2 = env30117[0];
|
|
}
|
|
r52 = value2;
|
|
break L16;
|
|
}
|
|
return value;
|
|
}
|
|
return r52;
|
|
}
|
|
return value;
|
|
}
|