decord/alpha/source/modules/messages/AttachmentUrlUtils.tsx

282 lines
8.6 KiB
TypeScript
Raw Permalink Normal View History

2026-10-12 06:59:38 +00:00
// Module ID: 9318
// Function ID: 9319
// Name: AttachmentUrlUtils
2026-10-10 08:08:14 +00:00
// Dependencies: [5, 5426, 1085, 1102, 2036, 2035, 1384, 1295, 2]
2026-08-24 06:08:38 +00:00
// Exports: getSignedAttachmentExpiration, isAttachmentPathUrl, isExternalProxiedAttachmentUrl, maybeRefreshAttachmentUrl, messageHasExpiredAttachmentUrl, removeSignedUrlParameters
2026-07-20 16:05:17 +00:00
2026-10-12 06:59:38 +00:00
// Module 9318 (AttachmentUrlUtils)
2026-10-03 08:58:59 +00:00
import Constants from "Constants" /* 1085 */;
import DurationsDefault from "Durations" /* 1102 */;
2026-10-09 10:00:15 +00:00
import HTTPUtils from "HTTPUtils" /* 1295 */;
import URLUtilsDefault from "URLUtils" /* 1384 */;
import ImageProxyUtils from "ImageProxyUtils" /* 2035 */;
import UrlHostUtils from "UrlHostUtils" /* 2036 */;
2026-10-10 08:08:14 +00:00
import AttachmentUrlConstants from "AttachmentUrlConstants" /* 5426 */;
2026-10-03 08:58:59 +00:00
import _asyncToGenerator from "_asyncToGenerator" /* 5 */;
import size from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-10-03 08:58:59 +00:00
let hostname;
2026-10-13 12:43:34 +00:00
const f101293 = (arr) => {
2026-10-03 08:58:59 +00:00
hostname = hostname.hostname;
let flag = true;
if (hostname !== arr) {
const _HermesInternal2 = HermesInternal;
flag = true;
if (!hostname.endsWith("." + arr)) {
const index = arr.indexOf(".");
const index1 = hostname.indexOf(".");
flag = false;
if (-1 !== index) {
2026-09-02 09:53:35 +00:00
flag = false;
2026-10-03 08:58:59 +00:00
if (-1 !== index1) {
const substr = hostname.substring(index1 + 1);
2026-09-02 09:53:35 +00:00
flag = false;
2026-10-03 08:58:59 +00:00
if (substr === arr.substring(index + 1)) {
const substr1 = hostname.substring(0, index1);
const _HermesInternal = HermesInternal;
const combined = "" + arr.substring(0, index) + "-";
flag = substr1.startsWith(combined) && substr1.length > combined.length;
substr1.startsWith(combined) && substr1.length > combined.length;
2026-09-02 09:53:35 +00:00
}
}
}
}
2026-10-03 08:58:59 +00:00
}
return flag;
};
2026-10-13 12:43:34 +00:00
const f101294 = (item) => {
2026-10-03 08:58:59 +00:00
pathname = pathname.pathname;
return pathname.startsWith(item);
};
function isRefreshableAttachmentUrl(toURLSafeResult) {
let closure_0 = toURLSafeResult;
2026-10-13 12:43:34 +00:00
let tmp2 = closure_7.some(f101293) || false;
closure_7.some(f101293) || false;
2026-08-24 06:08:38 +00:00
if (tmp2) {
let pathname = toURLSafeResult.pathname;
2026-10-03 08:58:59 +00:00
let tmp4 = !pathname.startsWith("/external/");
pathname.startsWith("/external/");
if (tmp4) {
const searchParams = toURLSafeResult.searchParams;
2026-08-24 06:08:38 +00:00
let hasItem = searchParams.has("ex");
if (!hasItem) {
const _Array = Array;
2026-10-03 08:58:59 +00:00
closure_0 = toURLSafeResult;
2026-08-24 06:08:38 +00:00
const arr = Array.from(ATTACHMENT_PATH_PREFIXES);
2026-10-13 12:43:34 +00:00
const someResult = arr.some(f101294);
hasItem = (obj.some(f101293) || false) && someResult;
(closure_7.some(f101293) || false) && someResult;
2026-08-24 06:08:38 +00:00
}
tmp4 = hasItem;
}
tmp2 = tmp4;
}
return tmp2;
}
2026-07-29 08:29:29 +00:00
function shouldRefreshAttachmentUrl(searchParams) {
2026-07-20 16:05:17 +00:00
searchParams = searchParams.searchParams;
2026-07-29 08:29:29 +00:00
let str = searchParams.get("ex");
2026-10-03 08:58:59 +00:00
const _parseInt = parseInt;
2026-07-29 08:29:29 +00:00
if (str == null) {
str = "";
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const _parseIntResult = _parseInt(str, 16);
2026-07-20 16:05:17 +00:00
let result;
2026-10-03 08:58:59 +00:00
if (!isNaN(_parseIntResult)) {
result = _parseIntResult * DurationsDefault.Millis.SECOND;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let tmp5 = null == result;
if (!tmp5) {
2026-07-20 16:05:17 +00:00
const _Date = Date;
2026-07-29 08:29:29 +00:00
tmp5 = result <= Date.now() + HOUR;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp5;
2026-07-20 16:05:17 +00:00
}
function isAttachmentExpired(url) {
2026-10-03 08:58:59 +00:00
obj = URLUtilsDefault;
const toURLSafeResult = obj.toURLSafe(url.url);
2026-07-29 08:29:29 +00:00
let tmp4 = null != toURLSafeResult;
if (tmp4) {
const searchParams = toURLSafeResult.searchParams;
let str2 = searchParams.get("ex");
2026-10-03 08:58:59 +00:00
const _parseInt = parseInt;
2026-07-29 08:29:29 +00:00
if (str2 == null) {
str2 = "";
}
2026-10-03 08:58:59 +00:00
const _parseIntResult = _parseInt(str2, 16);
2026-07-29 08:29:29 +00:00
const _isNaN = isNaN;
let result;
2026-10-03 08:58:59 +00:00
if (!isNaN(_parseIntResult)) {
result = _parseIntResult * DurationsDefault.Millis.SECOND;
2026-07-29 08:29:29 +00:00
}
let tmp8 = null == result;
if (!tmp8) {
const _Date = Date;
tmp8 = result <= Date.now() + HOUR;
}
tmp4 = tmp8;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmp4;
2026-07-20 16:05:17 +00:00
}
function isEmbedMediaExpiredAttachment(image) {
if (null == image) {
return false;
} else {
2026-10-03 08:58:59 +00:00
obj = URLUtilsDefault;
const toURLSafeResult = obj.toURLSafe(image.url);
2026-08-24 06:08:38 +00:00
let tmp8 = null != toURLSafeResult;
2026-10-03 08:58:59 +00:00
const tmp9 = importDefault;
2026-08-24 06:08:38 +00:00
if (tmp8) {
let tmp2 = isRefreshableAttachmentUrl(toURLSafeResult);
if (tmp2) {
2026-07-29 08:29:29 +00:00
const searchParams = toURLSafeResult.searchParams;
let str2 = searchParams.get("ex");
2026-10-03 08:58:59 +00:00
const _parseInt = parseInt;
2026-07-29 08:29:29 +00:00
if (str2 == null) {
str2 = "";
}
2026-10-03 08:58:59 +00:00
const _parseIntResult = _parseInt(str2, 16);
2026-07-29 08:29:29 +00:00
const _isNaN = isNaN;
let result;
2026-10-03 08:58:59 +00:00
if (!isNaN(_parseIntResult)) {
result = _parseIntResult * tmp9(1102).Millis.SECOND;
2026-07-29 08:29:29 +00:00
}
2026-08-24 06:08:38 +00:00
let tmp6 = null == result;
if (!tmp6) {
2026-07-29 08:29:29 +00:00
const _Date = Date;
2026-08-24 06:08:38 +00:00
tmp6 = result <= Date.now() + HOUR;
2026-07-29 08:29:29 +00:00
}
2026-08-24 06:08:38 +00:00
tmp2 = tmp6;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
tmp8 = tmp2;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
return tmp8;
2026-07-20 16:05:17 +00:00
}
}
function embedHasExpiredAttachmentUrl(image) {
2026-07-29 08:29:29 +00:00
let tmpResult = isEmbedMediaExpiredAttachment(image.image);
if (!tmpResult) {
2026-07-20 16:05:17 +00:00
const images = image.images;
let someResult;
2026-07-29 08:29:29 +00:00
if (images != null) {
someResult = images.some(tmp);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
tmpResult = someResult;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (!tmpResult) {
tmpResult = tmp(image.video);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return tmpResult;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
let obj = function _refreshAttachmentUrl() {
obj = _asyncToGenerator(async (arg0) => {
let c1;
let c2;
let items;
let obj4;
let obj8;
let closure_0 = arg0;
const HTTP = HTTPUtils.HTTP;
const request = { url: constants.ATTACHMENTS_REFRESH_URLS, body: obj4, rejectWithError: obj8.rejectWithMigratedError() };
obj4 = { attachment_urls: items };
items = [closure_0];
const post = HTTP.post;
obj8 = HTTPUtils;
await post(request);
return arg1.body.refreshed_urls[0].refreshed;
});
return obj(...arguments);
};
2026-10-03 08:58:59 +00:00
obj = function _maybeRefreshAttachmentUrl() {
obj = _asyncToGenerator(async (arg0) => {
let c3;
let c4;
let closure_2;
function refreshAttachmentUrl() {
return closure_1_13(...arguments);
}
2026-10-03 08:58:59 +00:00
let closure_0 = arg0;
const obj8 = URLUtilsDefault;
const toURLSafeResult = obj8.toURLSafe(closure_0);
if (null == toURLSafeResult) {
return closure_0;
}
2026-10-03 08:58:59 +00:00
if (!shouldRefreshAttachmentUrl(toURLSafeResult)) {
return closure_0;
}
const value = (await refreshAttachmentUrl(closure_0)) ?? closure_0;
return value;
});
return obj(...arguments);
};
2026-10-03 08:58:59 +00:00
const ATTACHMENT_PATH_PREFIXES = AttachmentUrlConstants.ATTACHMENT_PATH_PREFIXES;
const Endpoints = Constants.Endpoints;
const HOUR = DurationsDefault.Millis.HOUR;
2026-07-23 10:11:24 +00:00
let items = [window.GLOBAL_ENV.CDN_HOST, ];
2026-10-03 08:58:59 +00:00
let str = window.GLOBAL_ENV.MEDIA_PROXY_ENDPOINT;
2026-07-20 16:05:17 +00:00
let substr;
2026-10-03 08:58:59 +00:00
if (str != null) {
substr = str.substring(2);
2026-07-20 16:05:17 +00:00
}
items[1] = substr;
2026-08-24 06:08:38 +00:00
function isAttachmentPathUrl(toURLSafeResult) {
2026-10-03 08:58:59 +00:00
let closure_0 = toURLSafeResult;
2026-08-24 06:08:38 +00:00
const arr = Array.from(ATTACHMENT_PATH_PREFIXES);
2026-10-13 12:43:34 +00:00
const someResult = arr.some(f101294);
const tmp2 = (closure_7.some(f101293) || false) && someResult;
2026-10-03 08:58:59 +00:00
return tmp2;
2026-07-29 08:29:29 +00:00
}
function getSignedAttachmentExpiration(searchParams) {
searchParams = searchParams.searchParams;
let str = searchParams.get("ex");
2026-10-03 08:58:59 +00:00
const _parseInt = parseInt;
2026-07-29 08:29:29 +00:00
if (str == null) {
str = "";
}
2026-10-03 08:58:59 +00:00
const _parseIntResult = _parseInt(str, 16);
2026-07-29 08:29:29 +00:00
let result;
2026-10-03 08:58:59 +00:00
if (!isNaN(_parseIntResult)) {
result = _parseIntResult * DurationsDefault.Millis.SECOND;
2026-07-29 08:29:29 +00:00
}
return result;
}
2026-10-03 08:58:59 +00:00
const mapped = items.map(UrlHostUtils.getHostWithoutPort);
let closure_7 = mapped.filter((item) => null != item && "" !== item);
let result = size.fileFinishedImporting("modules/messages/AttachmentUrlUtils.tsx");
2026-07-20 16:05:17 +00:00
2026-08-24 06:08:38 +00:00
export { isAttachmentPathUrl };
export { isRefreshableAttachmentUrl };
2026-07-20 16:05:17 +00:00
export const isExternalProxiedAttachmentUrl = function isExternalProxiedAttachmentUrl(toURLSafeResult) {
2026-10-03 08:58:59 +00:00
obj = ImageProxyUtils;
return obj.isImageProxyURL(toURLSafeResult);
2026-07-20 16:05:17 +00:00
};
export const removeSignedUrlParameters = function removeSignedUrlParameters(toURLSafeResult) {
2026-10-03 08:58:59 +00:00
obj = URLUtilsDefault;
toURLSafeResult = obj.toURLSafe(toURLSafeResult);
2026-07-20 16:05:17 +00:00
if (null == toURLSafeResult) {
return toURLSafeResult;
} else {
2026-07-23 10:11:24 +00:00
const items = ["ex", "is", "hm"];
2026-07-29 08:29:29 +00:00
for (const item10012 of items) {
let searchParams = toURLSafeResult.searchParams;
let deleteResult = searchParams.delete(item10012);
continue;
2026-07-20 16:05:17 +00:00
}
return toURLSafeResult;
}
};
export { getSignedAttachmentExpiration };
export const messageHasExpiredAttachmentUrl = function messageHasExpiredAttachmentUrl(attachments) {
attachments = attachments.attachments;
let someResult = attachments.some(isAttachmentExpired);
if (!someResult) {
const embeds = attachments.embeds;
someResult = embeds.some(embedHasExpiredAttachmentUrl);
}
return someResult;
};
export const maybeRefreshAttachmentUrl = function maybeRefreshAttachmentUrl() {
2026-10-03 08:58:59 +00:00
return obj(...arguments);
2026-07-20 16:05:17 +00:00
};