400 lines
14 KiB
TypeScript
400 lines
14 KiB
TypeScript
// Metro module 6150 (f6151).
|
|
import * as _Module17 from "react-native";
|
|
import { AbortCodes, NOOP } from "../../../Constants";
|
|
import { DEFAULT_MOBILE_PRE_COMPRESSION_MAX_ATTACHMENT_SIZE, FileUploadErrorTypes } from "../../../modules/messages/MessageConstants";
|
|
import Logger from "../../../modules/debug/Logger";
|
|
import UploaderBase from "../UploaderBase";
|
|
import BackgroundTaskManager_native from "../../../modules/messages/BackgroundTaskManager.native";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { getKestrelConfig, getEffectiveKestrelLimit } from "../../../modules/media_uploads/experiments/KestrelExperiment";
|
|
import { getFileSize } from "../../../utils/native/UploadUtils";
|
|
import { getUploadTarget } from "../UploadTargets";
|
|
import UploaderQueue from "../UploaderQueue";
|
|
import { isAndroid } from "../../../utils/PlatformUtils";
|
|
import stageAttachmentFiles from "../stageAttachmentFiles";
|
|
import { CloudUploadStatus } from "../CloudUpload";
|
|
import { UploadPlatform } from "../Upload";
|
|
import Module12 from "../../../_bundle/Module12";
|
|
function $mk114879($env) {
|
|
return () => {
|
|
const r2 = $env[0];
|
|
r2.startUpload();
|
|
return r2;
|
|
};
|
|
}
|
|
function $mk114880($env) {
|
|
return (a0) => a0.status === CloudUploadStatus.COMPLETED;
|
|
}
|
|
let c3892_11, prototype;
|
|
let env3892 = {};
|
|
const { NativeEventEmitter, NativeModules } = _Module17;
|
|
const c3892_8 = new Logger("CloudUploader(Native).tsx");
|
|
const c3892_9 = new NativeEventEmitter(NativeModules.MediaManager);
|
|
class CloudUploader extends UploaderBase {
|
|
mediaEventSubscriptions = new Map();
|
|
uploadItems = new Map();
|
|
preCompressionFileSizes = [];
|
|
async uploadFiles(a0) {
|
|
let r40, r116, r202, r241, r256, r281, r345;
|
|
let env15519 = {
|
|
$parent: env3892
|
|
};
|
|
env15519[3] = this;
|
|
env15519[1] = a0;
|
|
env15519[2] = () => {
|
|
const r1 = env15519[3];
|
|
return Reflect.get(Object.getPrototypeOf(prototype), "upload", r1);
|
|
};
|
|
env15519[0] = this;
|
|
let c25719_0, files, c25719_2, c25719_3, c25719_4;
|
|
let c25719_5 = 0;
|
|
const r15 = env15519;
|
|
L30: {
|
|
L29: {
|
|
L28: {
|
|
L27: {
|
|
try {
|
|
let env29672;
|
|
c25719_3 = r15;
|
|
const r50 = env29672 = {
|
|
$parent: r15
|
|
};
|
|
c25719_2 = r50;
|
|
env29672[0] = void 0;
|
|
env29672[1] = void 0;
|
|
env29672[2] = void 0;
|
|
env29672[3] = void 0;
|
|
env29672[4] = void 0;
|
|
env29672[5] = void 0;
|
|
env29672[6] = void 0;
|
|
env29672[7] = void 0;
|
|
env29672[0] = BackgroundTaskManager_native.backgroundTaskIdentifierInvalid;
|
|
env15519[0].once("start", async () => {
|
|
let c31393_0 = env29672;
|
|
env29672[0] = await BackgroundTaskManager_native.startBackgroundTask({
|
|
title: intl.string(t["B/HSDd"]),
|
|
content: intl.formatToPlainString(t.D0noUt, {
|
|
count: env15519[1].length
|
|
})
|
|
});
|
|
if (env15519[0]._aborted) {
|
|
BackgroundTaskManager_native.endBackgroundTask(env29672[0]);
|
|
}
|
|
});
|
|
const onCompleteTask = () => {
|
|
BackgroundTaskManager_native.endBackgroundTask(env29672[0]);
|
|
const r11 = env15519[0];
|
|
const r13 = env29672[1];
|
|
r11.removeListener("complete", r13);
|
|
r11.removeListener("error", r13);
|
|
};
|
|
env29672[1] = onCompleteTask;
|
|
env15519[0].once("error", onCompleteTask);
|
|
env15519[0].once("complete", onCompleteTask);
|
|
env29672[2] = new Promise((c31394_0, c31394_1) => {
|
|
const r4 = env15519[0];
|
|
r4.once("error", (a0, a1, a2, a3) => {
|
|
c31394_1({
|
|
file: a0,
|
|
code: a1,
|
|
responseBody: a2,
|
|
reason: a3
|
|
});
|
|
});
|
|
r4.once("complete", () => {
|
|
const r3 = env15519[0];
|
|
if (!r3._errored) {
|
|
c31394_0(r3.files);
|
|
}
|
|
});
|
|
});
|
|
c25719_5 = 1;
|
|
const r69 = env15519[0];
|
|
const files3 = env15519[1];
|
|
r69.files = files3;
|
|
(0, env15519[2])().call(env15519[0], files3);
|
|
env15519[0]._file.attachmentsCount = files3.length;
|
|
env15519[0]._handleStart(void 0);
|
|
env29672[3] = getKestrelConfig({
|
|
location: "CloudUploader.native.uploadFiles"
|
|
});
|
|
env29672[4] = 0;
|
|
const files2 = env15519[0].files;
|
|
files = files2;
|
|
const r93 = files2[Symbol.iterator]();
|
|
files = r93.next;
|
|
c25719_0 = r93;
|
|
const r95 = files;
|
|
let r96 = c25719_0;
|
|
const r97 = r96 === void 0 ? void 0 : (r40 = r95.call(r96)).done ? r96 = void 0 : r40.value;
|
|
c25719_0 = r96;
|
|
if (r96 === void 0) {
|
|
c3892_8.log(`${env15519[0].id} queued`);
|
|
UploaderQueue.enqueue($mk114879(env15519));
|
|
r116 = env29672[2];
|
|
c25719_5 = 0;
|
|
break L30;
|
|
}
|
|
c25719_5 = 2;
|
|
env29672[5] = r97;
|
|
let r135 = await getFileSize(env29672[5].item.uri);
|
|
while (true) {
|
|
env29672[6] = r135;
|
|
env15519[0].preCompressionFileSizes.push(env29672[6]);
|
|
env29672[5].preCompressionSize = env29672[6];
|
|
env29672[4] = env29672[4] + env29672[6];
|
|
env15519[0]._file.totalPreCompressionSize = env29672[4];
|
|
env15519[0]._file.currentSize = env29672[4];
|
|
env29672[7] = getUploadTarget(env29672[5].item.target);
|
|
if (env29672[6] > Math.max(env29672[7].getMaxFileSize(env29672[5].channelId), DEFAULT_MOBILE_PRE_COMPRESSION_MAX_ATTACHMENT_SIZE)) {
|
|
env15519[0]._handleError({
|
|
code: AbortCodes.ENTITY_TOO_LARGE,
|
|
reason: {
|
|
type: FileUploadErrorTypes.PRECOMPRESSION_INDIVIDUAL_FILE_TOO_LARGE
|
|
}
|
|
});
|
|
r202 = env29672[2];
|
|
c25719_5 = 1;
|
|
const r203 = c25719_0;
|
|
if (r203 !== void 0 && typeof r203.return === "function") {
|
|
r203.return();
|
|
}
|
|
c25719_5 = 0;
|
|
break L29;
|
|
}
|
|
if (env29672[3].enabled) {
|
|
if (env29672[6] > getEffectiveKestrelLimit(env29672[3], env29672[7].getMaxFileSize(env29672[5].channelId))) {
|
|
env15519[0]._handleError({
|
|
code: AbortCodes.ENTITY_TOO_LARGE,
|
|
reason: {
|
|
type: FileUploadErrorTypes.PRECOMPRESSION_INDIVIDUAL_FILE_TOO_LARGE
|
|
}
|
|
});
|
|
r241 = env29672[2];
|
|
c25719_5 = 1;
|
|
const r242 = c25719_0;
|
|
if (r242 !== void 0 && typeof r242.return === "function") {
|
|
r242.return();
|
|
}
|
|
c25719_5 = 0;
|
|
break;
|
|
}
|
|
}
|
|
if (env29672[4] > env29672[7].getMaxTotalAttachmentSize()) {
|
|
env15519[0]._handleError({
|
|
code: AbortCodes.ENTITY_TOO_LARGE,
|
|
reason: {
|
|
type: FileUploadErrorTypes.PRECOMPRESSION_SUM_TOO_LARGE
|
|
}
|
|
});
|
|
r256 = env29672[2];
|
|
c25719_5 = 1;
|
|
const r257 = c25719_0;
|
|
if (r257 !== void 0 && typeof r257.return === "function") {
|
|
r257.return();
|
|
}
|
|
c25719_5 = 0;
|
|
break L28;
|
|
}
|
|
c25719_5 = 1;
|
|
const r259 = files;
|
|
let r260 = c25719_0;
|
|
const r261 = r260 === void 0 ? void 0 : (r40 = r259.call(r260)).done ? r260 = void 0 : r40.value;
|
|
c25719_0 = r260;
|
|
if (r260 === void 0) {
|
|
c3892_8.log(`${env15519[0].id} queued`);
|
|
UploaderQueue.enqueue($mk114879(env15519));
|
|
r281 = env29672[2];
|
|
c25719_5 = 0;
|
|
break L27;
|
|
}
|
|
c25719_5 = 2;
|
|
env29672[5] = r261;
|
|
r135 = await getFileSize(env29672[5].item.uri);
|
|
}
|
|
} catch ($e) {
|
|
const r48 = $e;
|
|
let r8 = r48;
|
|
c25719_4 = r48;
|
|
let r49 = c25719_5;
|
|
if (r49 !== 0) {
|
|
while (true) {
|
|
if (r49 === 1) {
|
|
try {
|
|
const r329 = c25719_4;
|
|
c25719_5 = 0;
|
|
env29672[8] = r329;
|
|
c3892_8.log(`${env15519[0].id} failed in CloudUploader uploadFiles ${env29672[8]}`);
|
|
env15519[0]._handleException(env29672[8]);
|
|
r345 = env29672[2];
|
|
} catch (r326) {
|
|
r8 = r326;
|
|
c25719_4 = r326;
|
|
r49 = c25719_5;
|
|
if (r49 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return r345;
|
|
}
|
|
try {
|
|
const r321 = c25719_4;
|
|
c25719_5 = 1;
|
|
const r323 = c25719_0;
|
|
if (r323 !== void 0 && typeof r323.return === "function") {
|
|
try {
|
|
r323.return();
|
|
} catch {}
|
|
}
|
|
throw r321;
|
|
} catch (r320) {
|
|
r8 = r320;
|
|
c25719_4 = r320;
|
|
r49 = c25719_5;
|
|
if (r49 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r241;
|
|
}
|
|
return r281;
|
|
}
|
|
return r256;
|
|
}
|
|
return r202;
|
|
}
|
|
return r116;
|
|
}
|
|
async startUpload() {
|
|
const _this = this;
|
|
let c25720_0, c25720_1, c25720_2;
|
|
let c25720_3 = 0;
|
|
const r19 = void 0;
|
|
const r18 = env3892;
|
|
L28: {
|
|
L25: {
|
|
L26: {
|
|
try {
|
|
let env29673;
|
|
c25720_1 = r19;
|
|
const r40 = env29673 = {
|
|
$parent: r18
|
|
};
|
|
c25720_0 = r40;
|
|
if (_this._aborted) {
|
|
_this._handleAborted();
|
|
break L28;
|
|
}
|
|
_this._handleStart(NOOP);
|
|
c25720_3 = 1;
|
|
if (isAndroid()) {
|
|
_this.observeCompressionProgress(_this.files);
|
|
}
|
|
if (await _this.compressAndCheckFileSize()) {
|
|
_this.setUploadingTextForUI();
|
|
await stageAttachmentFiles(_this.files, true, _this._recomputeProgress.bind(_this));
|
|
if (_this.files.length === 0) {
|
|
c3892_8.log(`All uploads cancelled for ${_this.id}`);
|
|
_this._handleComplete();
|
|
c25720_3 = 0;
|
|
break L26;
|
|
}
|
|
if (_this.files.every($mk114880(env3892))) {
|
|
const items = _this._file.items;
|
|
if (items != null) {
|
|
items.forEach((item) => {
|
|
item.item.progress = 100;
|
|
});
|
|
}
|
|
_this._file = {
|
|
..._this._file,
|
|
progress: 100
|
|
};
|
|
_this.emit("progress", _this._file);
|
|
c3892_8.log(`All uploads complete for ${_this.id}`);
|
|
_this._handleComplete();
|
|
c25720_3 = 0;
|
|
break L25;
|
|
}
|
|
throw new Error("Not all attachments were uploaded successfully");
|
|
}
|
|
c25720_3 = 0;
|
|
} catch ($e) {
|
|
const r38 = $e;
|
|
let r8 = r38;
|
|
c25720_2 = r38;
|
|
if (c25720_3 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r195 = c25720_2;
|
|
c25720_3 = 0;
|
|
env29673[0] = r195;
|
|
_this._handleException(env29673[0]);
|
|
break L25;
|
|
} catch (r191) {
|
|
r8 = r191;
|
|
c25720_2 = r191;
|
|
if (c25720_3 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
}
|
|
observeCompressionProgress(a0) {
|
|
a0.forEach(({ item }) => {
|
|
if (item.platform === UploadPlatform.REACT_NATIVE) {
|
|
item.compressionProgress = 0;
|
|
this.uploadItems.set(item.uri, item);
|
|
}
|
|
});
|
|
this.mediaEventSubscriptions.set(this._file.id, c3892_9.addListener("compression-progress", ({ uri, progress }) => {
|
|
if (this.uploadItems.has(uri)) {
|
|
this.uploadItems.get(uri).compressionProgress = progress;
|
|
const compressionProgress = Module12.meanBy([...this.uploadItems.values()], "compressionProgress");
|
|
if (compressionProgress >= 100) {
|
|
const r37 = this.mediaEventSubscriptions.get(this._file.id);
|
|
if (r37 != null) {
|
|
r37.remove();
|
|
}
|
|
this.mediaEventSubscriptions.delete(this._file.id);
|
|
this.uploadItems.clear();
|
|
const items = this._file.items;
|
|
if (items != null) {
|
|
items.forEach((item) => {
|
|
item.item.compressionProgress = 100;
|
|
});
|
|
}
|
|
this._file = {
|
|
...this._file,
|
|
compressionProgress: 100
|
|
};
|
|
} else {
|
|
this._file = {
|
|
...this._file,
|
|
compressionProgress
|
|
};
|
|
}
|
|
this.emit("compression-progress", this._file);
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
const prototype2 = CloudUploader.prototype;
|
|
c3892_11 = CloudUploader;
|
|
prototype = prototype2;
|
|
export default CloudUploader;
|