Files
discord-decomp/sources/utils/FileUtils.tsx
T
2026-07-28 01:06:53 +03:00

354 lines
17 KiB
TypeScript

/* Metro module 4655; source: utils/FileUtils.tsx; dependencies: [1867, 1878, 661, 1880, 22, 4656, 4657, 3802, 4136, 1244, 2] */
import GuildStore from '../stores/GuildStore.tsx'; /* Metro dependency 1867 */
import UserStore from '../stores/UserStore.tsx'; /* Metro dependency 1878 */
import PremiumUtils from './PremiumUtils.tsx'; /* Metro dependency 3802 */
import Module04656 from '../by-id/module-04656.js'; /* Metro dependency 4656 */
import * as FileImportTrackerModule from '../by-id/module-00002-FileImportTracker.js'; /* Metro dependency 2 */
import * as ConstantsModule from '../Constants.tsx'; /* Metro dependency 661 */
import * as IndexNativeModule from '../intl/index.native.tsx'; /* Metro dependency 1244 */
import * as FileSizeUtilsModule from './FileSizeUtils.tsx'; /* Metro dependency 4136 */
import * as FileUploadPowerupHoldoutExperimentModule from '../modules/premium/powerups/experiments/FileUploadPowerupHoldoutExperiment.tsx'; /* Metro dependency 4657 */
function _fun40174(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#40174, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:6, offset: 0x010f8628, size: 928 bytes, params: 8, frame: 28
const env0_0 = require;
const _arrayLikeToArray_40177 = function(a0, a1) {
var r0;
var r1;
var r2;
var value3;
var length;
var value5;
var value = undefined;
var value2 = value == null;
reducibleJoin2: while (true) {
if (value2) {
r0 = value2;
break reducibleJoin2;
}
value3 = value > a0.length;
r0 = value3;
break reducibleJoin2;
}
reducibleJoin4: while (true) {
if (r0) {
length = a0.length;
r1 = length;
break reducibleJoin4;
}
r1 = value;
break reducibleJoin4;
}
value = (0, global.Array)(r1);
var value4 = 0;
if (value4 < r1) {
r2 = value4;
reducibleLoop5: while (true) {
value[r2] = a0[r2];
value5 = typeof r2 === 'bigint' ? r2 + 1n : +r2 + 1;
if (value5 < r1) {
r2 = value5;
continue reducibleLoop5;
}
break reducibleLoop5;
}
}
return value;
};
const closure = function(a0, a1, a2) {
var File = global.File;
var value = Object.create(File.prototype, {constructor: {value: File}});
var value2 = new File([a0], a1, {type: a2});
return value2 instanceof Object ? value2 : value;
};
const classifyFileName2 = classifyFileName;
const maxFileSize2 = maxFileSize;
const getUploadFileSizeSum2 = getUploadFileSizeSum;
const getMaxRequestSize2 = getMaxRequestSize;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
let value = ConstantsModule;
const GuildFeatures = value.GuildFeatures;
const env0_6 = value.MAX_ATTACHMENT_SIZE;
value = require(1880) /* metro dependency 1880: PremiumConstants */;
const MAX_GUILD_FILE_SIZE_50_MB = value.MAX_GUILD_FILE_SIZE_50_MB;
const MAX_GUILD_FILE_SIZE_100_MB = value.MAX_GUILD_FILE_SIZE_100_MB;
const MAX_GUILD_FILE_SIZE_250_MB = value.MAX_GUILD_FILE_SIZE_250_MB;
const env0_7 = value.MAX_PREMIUM_TIER_2_ATTACHMENT_SIZE;
const items3 = [{reType: RegExp('^image\\/vnd.adobe.photoshop', ''), klass: 'photoshop'}];
items3[1] = {reType: RegExp('^image\\/svg\\+xml', ''), klass: 'webcode'};
items3[2] = {reType: RegExp('^image\\/', ''), klass: 'image'};
items3[3] = {reType: RegExp('^video\\/', ''), klass: 'video'};
items3[4] = {reName: RegExp('\\.pdf$', ''), klass: 'acrobat'};
items3[5] = {reName: RegExp('\\.ae', ''), klass: 'ae'};
items3[6] = {reName: RegExp('\\.sketch$', ''), klass: 'sketch'};
items3[7] = {reName: RegExp('\\.ai$', ''), klass: 'ai'};
items3[8] = {reName: RegExp('\\.(?:rar|zip|7z|tar|tar\\.gz)$', ''), klass: 'archive'};
items3[9] = {reName: RegExp('\\.(?:c\\+\\+|cpp|cc|c|h|hpp|mm|m|json|js|ts|rb|rake|py|asm|fs|pyc|dtd|cgi|bat|rss|java|graphml|idb|lua|o|gml|prl|sls|conf|cmake|make|sln|vbe|cxx|wbf|vbs|r|wml|php|bash|applescript|fcgi|yaml|ex|exs|sh|ml|actionscript)$',
''), klass: 'code'};
items3[10] = {reName: RegExp('\\.(?:txt|rtf|doc|docx|md|pages|ppt|pptx|pptm|key|log)$', ''), klass: 'document'};
items3[11] = {reName: RegExp('\\.(?:xls|xlsx|numbers|csv)$', ''), klass: 'spreadsheet'};
items3[12] = {reName: RegExp('\\.(?:html|xhtml|htm|xml|xsd|css|styl)$', ''), klass: 'webcode'};
items3[13] = {reName: RegExp('\\.(?:mp3|ogg|opus|wav|aiff|flac)$', ''), klass: 'audio'};
const MAX_FILE_SIZE_250_MB = GuildFeatures.MAX_FILE_SIZE_250_MB;
const items2 = [[MAX_FILE_SIZE_250_MB, MAX_GUILD_FILE_SIZE_250_MB]];
const MAX_FILE_SIZE_100_MB = GuildFeatures.MAX_FILE_SIZE_100_MB;
items2[1] = [MAX_FILE_SIZE_100_MB, MAX_GUILD_FILE_SIZE_100_MB];
const MAX_FILE_SIZE_50_MB = GuildFeatures.MAX_FILE_SIZE_50_MB;
items2[2] = [MAX_FILE_SIZE_50_MB, MAX_GUILD_FILE_SIZE_50_MB];
(FileImportTrackerModule).fileFinishedImporting('utils/FileUtils.tsx');
exports.transformNativeFile = transformNativeFile;
exports.makeFile = closure;
exports.classifyFile = function(a0) {
return classifyFileName(a0.name, a0.type);
};
exports.classifyFileName = classifyFileName2;
exports.sizeString = sizeString;
exports.maxFileSize = maxFileSize2;
exports.anyFileTooLarge = anyFileTooLarge;
exports.getUploadFileSizeSum = getUploadFileSizeSum2;
exports.uploadSumTooLarge = function(a0) {
var value2 = getUploadFileSizeSum(a0);
getMaxRequestSize();
return value2 > 524288000;
};
exports.getMaxRequestSize = getMaxRequestSize2;
exports.fileUploadLimitRoadblockDescription = fileUploadLimitRoadblockDescription;
function _createForOfIteratorHelperLoose_40175(a0, a1) { // fn#40175, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:315, offset: 0x010f89c8, size: 370 bytes, params: 3, frame: 20
var r6;
var r9;
var r5;
var value3;
var regexp;
const env0_0 = a0;
const Symbol = global.Symbol;
let value = typeof Symbol !== 'undefined';
let r1 = value && a0[global.Symbol.iterator];
r1 = !r1 ? a0['@@iterator'] : r1;
if (r1) {
value = r1.call(a0);
return value.next.bind(value);
}
const Array = global.Array;
if (Array.isArray(a0)) {
if (r1) {
}
return _fun40176;
}
value = undefined;
if (a0) {
if (typeof a0 === 'string') {
value = _arrayLikeToArray_40177(a0, value);
r5 = value;
} else {
value3 = ({}).toString.call(a0).slice(8, -1);
r6 = value3 === 'Object' && a0.constructor;
r9 = r6 ? a0.constructor.name : value3;
if (r9 === 'Map') {
r6 = global.Array.from(a0);
} else if (r9 === 'Set') {
r6 = global.Array.from(a0);
} else if (r9 === 'Arguments') {
value = _arrayLikeToArray_40177(a0, value);
r6 = value;
} else {
regexp = RegExp('^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$', '');
if (regexp.test(r9)) {
value = _arrayLikeToArray_40177(a0, value);
r6 = value;
} else {
r6 = value;
}
}
r5 = r6;
}
} else {
r5 = value;
}
if (r5) {
if (r5) {
}
return _fun40176;
}
const TypeError = global.TypeError;
throw new TypeError('Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.');
function _fun40176() { // fn#40176, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:886, offset: 0x00c39d73, size: 69 bytes, params: 1, frame: 5
return env0_1 >= env0_0.length ? {done: true} : {done: false,
value: env0_0[typeof env0_1 === 'bigint' ? env0_1 : +env0_1]};
}
}
function classifyFileName(a0, a1) { // fn#40179, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:2148, offset: 0x010f8b75, size: 120 bytes, params: 3, frame: 16
let env0_0 = a0;
const env0_1 = a1;
env0_0 = a0?.toLowerCase() ?? '';
value = Reflect.apply((importDefault(22) /* metro dependency 22 */).find, value, [env0_8, _fun40180]);
return value != null ? value.klass : 'unknown';
function _fun40180(a0) { // fn#40180, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:2261, offset: 0x010f8bed, size: 104 bytes, params: 2, frame: 14
var r0;
if (a0.reType == null) {
r0 = a0.reName != null && env0_0 !== '';
r0 = r0 && a0.reName.test(env0_0);
} else if (require != null) {
r0 = a0.reType.test(require);
} else {
r0 = a0.reName != null && env0_0 !== '';
r0 = r0 && a0.reName.test(env0_0);
}
return r0;
}
}
function maxFileSize(a0) { // fn#40181, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:2469, offset: 0x010f8c55, size: 118 bytes, params: 2, frame: 16
const userMaxFileSize = (PremiumUtils).getUserMaxFileSize(UserStore.getCurrentUser());
if (a0 == null) {
return userMaxFileSize;
}
const guild = GuildStore.getGuild(a0);
const r3 = guild != null ? getGuildMaxFileSize(guild) : MAX_ATTACHMENT_SIZE;
const Math = global.Math;
return Math.max(r3, userMaxFileSize);
function getGuildMaxFileSize(a0) { // fn#40182, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:2600, owner: maxFileSize.getGuildMaxFileSize, offset: 0x010f8ccb, size: 99 bytes, params: 2, frame: 15
const env0_0 = a0;
const FileUploadPowerupHoldoutExperiment = (FileUploadPowerupHoldoutExperimentModule).FileUploadPowerupHoldoutExperiment;
const getConfig = FileUploadPowerupHoldoutExperiment.getConfig;
const env0_1 = Reflect.apply(getConfig, FileUploadPowerupHoldoutExperiment,
[{location: 'getGuildMaxFileSize'}]).enabled;
return env1_9.reduce(_fun40183, MAX_ATTACHMENT_SIZE);
function _fun40183(a0, a1) { // fn#40183, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:2751, offset: 0x010f8d2e, size: 137 bytes, params: 3, frame: 16
var r0;
var r1;
var r2;
var item3;
var value4;
const value = a0;
const iterator = a1[Symbol.iterator]();
const iterator2 = iterator.next;
let item2 = Reflect.apply(iterator2, iterator, []);
let item = item2.value;
item2 = item2.done ? undefined : iterator;
const value2 = undefined;
const value3 = item2 === value2;
const r5 = value3 ? value2 : item;
if (value3) {
r0 = item2;
r1 = value3;
r2 = value2;
} else {
item3 = Reflect.apply(iterator2, item2, []);
item = item3.value;
item3 = item3.done ? undefined : item2;
value4 = item3 === value2;
if (value4) {
r0 = item3;
r1 = value4;
r2 = value2;
} else {
r0 = item3;
r1 = value4;
r2 = item;
}
}
if (!r1) {
r0.return();
}
return enabled && r5 === GuildFeatures.MAX_FILE_SIZE_250_MB ? value : env0_0.features.has(r5) && r2 > value ? r2 : value;
}
}
}
function getUploadFileSizeSum(a0) { // fn#40184, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:2852, offset: 0x010f8db7, size: 70 bytes, params: 2, frame: 16
var r2;
var r3;
var r0;
var value4;
var size;
var value5;
var value6;
const value = _createForOfIteratorHelperLoose_40175(a0);
const value2 = value();
let done = value2.done;
const value3 = 0;
if (done) {
r0 = value3;
} else {
r2 = value3;
for (r3 = value2; true; r3 = value6) {
value4 = r3.value;
size = value4.size;
value5 = r2 + size;
value6 = value();
done = value6.done;
if (done) {
r0 = value5;
break;
}
r2 = value5;
}
}
return r0;
}
function getMaxRequestSize() { // fn#40185, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:2977, offset: 0x010f8dfd, size: 40 bytes, params: 1, frame: 9
const currentUser = UserStore.getCurrentUser();
if (currentUser != null) {
currentUser.isStaff();
}
return 524288000;
}
function transformNativeFile(a0, a1) { // fn#40186, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:3146, offset: 0x010f8e25, size: 77 bytes, params: 3, frame: 17
var r0;
var makeFileBinding;
var buffer;
var filename;
let value = a0;
const value2 = a1;
const File = global.File;
if (value instanceof File) {
r0 = value;
} else {
makeFileBinding = makeFile;
buffer = value.data.buffer;
filename = value.filename;
value = 'text/plain';
value = makeFileBinding(buffer, filename, value2 ?? value);
r0 = value;
}
return r0;
}
function sizeString(a0) { // fn#40188, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:3419, offset: 0x010f8e90, size: 41 bytes, params: 2, frame: 11
return (Module04656).filesize(a0);
}
function anyFileTooLarge(a0, a1) { // fn#40189, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:3516, offset: 0x010f8eb9, size: 62 bytes, params: 3, frame: 12
const env0_0 = maxFileSize(a1);
const Array = global.Array;
return Array.from(a0).some(_fun40190);
function _fun40190({size}) { // fn#40190, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:3594, offset: 0x010f8ef7, size: 21 bytes, params: 2, frame: 2
return size > env0_0;
}
}
function fileUploadLimitRoadblockDescription({guildId, onClick, maxSize}) { // fn#40192, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:4833:3835, offset: 0x010f8f31, size: 204 bytes, params: 2, frame: 20
let formatSize = FileSizeUtilsModule.formatSize;
const value4 = Reflect.apply(formatSize, FileSizeUtilsModule,
[(maxSize ?? maxFileSize(guildId)) / 1024, {useKibibytes: true}]);
formatSize = FileSizeUtilsModule.formatSize;
let value = MAX_PREMIUM_TIER_2_ATTACHMENT_SIZE / 1024;
value = Reflect.apply(formatSize, FileSizeUtilsModule, [value, {useKibibytes: true}]);
const intl = (IndexNativeModule).intl;
return intl.format((IndexNativeModule).t.tRuxk9, {maxSize: value4,
premiumMaxSize: value, onClick: onClick});
}
}
global.__d(_fun40174, 4655, [1867, 1878, 661, 1880, 22, 4656, 4657, 3802, 4136, 1244,
2]) /* metro module 4655, dependencies: [1867, 1878, 661, 1880, 22, 4656, 4657, 3802, 4136, 1244, 2] */;