Files
discord-decomp/sources/modules/messages/SignedAttachmentLinkUtils.tsx
2026-07-28 01:06:53 +03:00

217 lines
11 KiB
TypeScript

/* Metro module 9598; source: modules/messages/SignedAttachmentLinkUtils.tsx; dependencies: [5, 661, 672, 1471, 507, 2] */
import Module00005 from '../../by-id/module-00005.js'; /* Metro dependency 5 */
import Durations from '../../utils/Durations.tsx'; /* Metro dependency 672 */
import URLUtils from '../../utils/URLUtils.tsx'; /* Metro dependency 1471 */
import * as FileImportTrackerModule from '../../by-id/module-00002-FileImportTracker.js'; /* Metro dependency 2 */
import * as ConstantsModule from '../../Constants.tsx'; /* Metro dependency 661 */
function _fun75228(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#75228, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:6, offset: 0x01da70f0, size: 648 bytes, params: 8, frame: 26
const env0_0 = require;
const isAttachmentUrl2 = isAttachmentUrl;
const closure2 = function({searchParams}) {
var value = searchParams.get('ex');
searchParams = global.parseInt;
var r2 = value ?? '';
value = undefined;
var int = searchParams(r2, 16);
return (0, global.isNaN)(int) ? value : int * importDefault(dependencyMap[2]).Millis.SECOND;
};
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
let value = undefined;
const closure3 = function(a0) {
return a0 == null ? undefined : a0.split(':')[0];
};
let Set = global.Set;
let set = new Set(['/attachments/', '/ephemeral-attachments/']);
Set = global.Set;
set = new Set(['/external/']);
const Millis = (Durations).Millis;
const HOUR = Millis.HOUR;
const env0_7 = 1 * HOUR;
Set = global.Set;
let GLOBAL_ENV = global.window.GLOBAL_ENV;
const CDN_HOST = GLOBAL_ENV.CDN_HOST;
items2 = [CDN_HOST];
GLOBAL_ENV = global.window.GLOBAL_ENV;
const MEDIA_PROXY_ENDPOINT = GLOBAL_ENV.MEDIA_PROXY_ENDPOINT;
items2[1] = MEDIA_PROXY_ENDPOINT == null ? value : MEDIA_PROXY_ENDPOINT.substring(2);
const value7 = items2.map(closure3);
let filter = value7.filter;
let Boolean = global.Boolean;
set = new Set(Reflect.apply(filter, value7, [Boolean]));
Set = global.Set;
GLOBAL_ENV = global.window.GLOBAL_ENV;
const IMAGE_PROXY_ENDPOINTS = GLOBAL_ENV.IMAGE_PROXY_ENDPOINTS;
let r12 = IMAGE_PROXY_ENDPOINTS == null ? value : IMAGE_PROXY_ENDPOINTS.split(',');
r12 = r12 ?? [];
const value13 = r12.map(function(a0) {
return a0.substring(2);
}).map(closure3);
filter = value13.filter;
Boolean = global.Boolean;
set = new Set(Reflect.apply(filter, value13, [Boolean]));
(FileImportTrackerModule).fileFinishedImporting('modules/messages/SignedAttachmentLinkUtils.tsx');
exports.isAttachmentUrl = isAttachmentUrl2;
exports.isExternalProxiedAttachmentUrl = isExternalProxiedAttachmentUrl;
exports.removeSignedUrlParameters = removeSignedUrlParameters;
exports.getSignedAttachmentExpiration = closure2;
exports.messageHasExpiredAttachmentUrl = messageHasExpiredAttachmentUrl;
exports.maybeRefreshAttachmentUrl = function() {
return _maybeRefreshAttachmentUrl.apply(this, arguments);
};
return value;
function isAttachmentUrl(a0) { // fn#75229, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:612, offset: 0x01da7378, size: 86 bytes, params: 2, frame: 13
const env0_0 = a0;
const binding = env0_8;
const value2 = binding.has(a0.hostname);
const Array = global.Array;
let value = Array.from(env0_5);
value = value.some(_fun75230);
return value2 ? value : !!value2;
function _fun75230(a0) { // fn#75230, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:686, offset: 0x01da73ce, size: 29 bytes, params: 2, frame: 11
return env0_0.pathname.startsWith(a0);
}
}
function shouldRefreshAttachmentUrl(a0) { // fn#75232, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:877, offset: 0x01da7460, size: 57 bytes, params: 2, frame: 13
const signedAttachmentExpiration = getSignedAttachmentExpiration(a0);
return signedAttachmentExpiration == null || signedAttachmentExpiration <= global.Date.now() + env0_7;
}
function isAttachmentExpired({url}) { // fn#75233, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:987, offset: 0x01da7499, size: 64 bytes, params: 2, frame: 13
const value2 = (URLUtils).toURLSafe(url);
return value2 != null && shouldRefreshAttachmentUrl(value2);
}
function isEmbedMediaExpiredAttachment(a0) { // fn#75234, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:1096, offset: 0x01da74d9, size: 93 bytes, params: 2, frame: 14
var r0;
var isAttachmentUrl2;
if (a0 == null) {
return false;
}
const defaultImport = URLUtils;
const value2 = defaultImport.toURLSafe(a0.url);
const value3 = value2 != null;
if (value3) {
isAttachmentUrl2 = isAttachmentUrl(value2);
r0 = isAttachmentUrl2 ? shouldRefreshAttachmentUrl(value2) : !!isAttachmentUrl2;
} else {
r0 = value3;
}
return r0;
}
function embedHasExpiredAttachmentUrl(a0) { // fn#75235, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:1259, offset: 0x01da7536, size: 81 bytes, params: 2, frame: 16
let r0 = isEmbedMediaExpiredAttachment(a0.image) || a0.images?.some(isEmbedMediaExpiredAttachment);
r0 = !r0 ? isEmbedMediaExpiredAttachment(a0.video) : r0;
return r0;
}
function _refreshAttachmentUrl() { // fn#75236, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:1459, offset: 0x01da7587, size: 50 bytes, params: 1, frame: 14
return Module00005(_fun75238).apply(this, arguments);
function* _fun75238(a0) { // fn#75238, original name: ?anon_0_, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:1524, offset: 0x01da75c4, size: 154 bytes, params: 2, frame: 16
if (false) {
return undefined;
}
value = environment.__proto__.__proto__;
const binding = env2_0;
const value3 = undefined;
const HTTP = binding(env2_2[4]).HTTP;
const post = HTTP.post;
const ATTACHMENTS_REFRESH_URLS = env2_4.ATTACHMENTS_REFRESH_URLS;
yield Reflect.apply(post, HTTP, [{url: ATTACHMENTS_REFRESH_URLS, body: {attachment_urls: [a0]},
rejectWithError: false}]);
value = undefined;
if (false) {
return value;
}
return value.ok ? value.body.refreshed_urls[0].refreshed : value3;
}
}
function _maybeRefreshAttachmentUrl() { // fn#75239, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:1727, offset: 0x01da765e, size: 50 bytes, params: 1, frame: 14
return Module00005(_fun75241).apply(this, arguments);
function* _fun75241(a0) { // fn#75241, original name: ?anon_0_, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:1802, offset: 0x01da769b, size: 113 bytes, params: 2, frame: 15
var value7;
const value = a0;
if (false) {
return undefined;
}
const value6 = env2_1(env2_2[3]).toURLSafe(value);
if (value6 != null) {
if (env2_12(value6)) {
yield refreshAttachmentUrl(value);
value7 = undefined;
if (false) {
return value7;
}
return value7 ?? value;
}
}
return value;
function refreshAttachmentUrl() { // fn#75242, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:1917, offset: 0x00eedcb2, size: 30 bytes, params: 1, frame: 13
return env3_16.apply(this, arguments);
}
}
}
function isExternalProxiedAttachmentUrl(a0) { // fn#75245, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:2222, offset: 0x01da7743, size: 86 bytes, params: 2, frame: 13
const env0_0 = a0;
const binding = env0_9;
const value2 = binding.has(a0.hostname);
const Array = global.Array;
let value = Array.from(env0_6);
value = value.some(_fun75246);
return value2 ? value : !!value2;
function _fun75246(a0) { // fn#75246, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:2311, offset: 0x01da73ce, size: 29 bytes, params: 2, frame: 11
return env0_0.pathname.startsWith(a0);
}
}
function removeSignedUrlParameters(a0) { // fn#75247, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:2383, offset: 0x01da7799, size: 105 bytes, params: 2, frame: 15
var r3;
var property;
var searchParams;
var value3;
let value = URLUtils;
value = value.toURLSafe(a0);
if (value == null) {
return a0;
}
const items2 = ['ex', 'is', 'hm'];
let length = items2.length;
const value2 = 0;
if (value2 < length) {
r3 = value2;
reducibleLoop2: while (true) {
property = items2[r3];
searchParams = value.searchParams;
searchParams.delete(property);
value3 = typeof r3 === 'bigint' ? r3 + 1n : +r3 + 1;
length = items2.length;
if (value3 < length) {
r3 = value3;
continue reducibleLoop2;
}
break reducibleLoop2;
}
}
return value;
}
function messageHasExpiredAttachmentUrl(a0) { // fn#75248, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:9784:2656, offset: 0x01da7802, size: 53 bytes, params: 2, frame: 13
const attachments = a0.attachments;
return attachments.some(isAttachmentExpired) || a0.embeds.some(embedHasExpiredAttachmentUrl);
}
}
global.__d(_fun75228, 9598, [5, 661, 672, 1471, 507,
2]) /* metro module 9598, dependencies: [5, 661, 672, 1471, 507, 2] */;