decord/source/lib/uploader/UploaderBase.tsx

442 lines
15 KiB
TypeScript
Raw Normal View History

2026-08-25 06:04:03 +00:00
// Module ID: 7443
// Function ID: 7444
2026-07-29 08:29:29 +00:00
// Name: _fileSize
2026-08-25 06:04:03 +00:00
// Dependencies: [5, 676, 4373, 3, 652, 12, 4999, 5004, 4961, 4962, 2]
2026-07-20 16:05:17 +00:00
2026-08-25 06:04:03 +00:00
// Module 7443 (_fileSize)
2026-08-24 06:08:38 +00:00
import timestampDefault from "timestamp" /* 3 */;
import applyDefault from "apply" /* 12 */;
import closure_3 from "asyncGeneratorStep" /* 5 */;
import { AbortCodes } from "ME" /* 676 */;
2026-08-25 06:04:03 +00:00
import { FileUploadErrorTypes } from "MESSAGE_GROUP_SPACING" /* 4373 */;
2026-08-24 06:08:38 +00:00
import { EventEmitter } from "EventEmitter" /* 652 */;
2026-07-23 10:11:24 +00:00
2026-08-24 06:08:38 +00:00
const require = arg1;
let closure_6 = new timestampDefault("UploaderBase.tsx");
2026-07-29 08:29:29 +00:00
class UploaderBase extends EventEmitter {
constructor() {
tmp3 = new UploaderBase(tmp2, new.target, new.target, tmp);
// ThrowIfThisInitialized (0x7c)
closure_0 = tmp3;
tmp3._aborted = false;
tmp3._errored = false;
tmp3.files = [];
tmp3._lastUpdate = 0;
tmp3._loaded = 0;
tmp3.alreadyStarted = false;
tmp3._handleStart = function _handleStart(_cancel) {
2026-08-24 06:08:38 +00:00
lib._cancel = _cancel;
if (!lib.alreadyStarted) {
2026-07-29 08:29:29 +00:00
obj.emit("start", obj._file);
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
lib.alreadyStarted = true;
2026-07-29 08:29:29 +00:00
};
tmp3._handleProgress = function _handleProgress(loaded, total, arg2) {
2026-08-24 06:08:38 +00:00
const lib = arg2;
2026-07-29 08:29:29 +00:00
const timestamp = Date.now();
2026-08-24 06:08:38 +00:00
let obj = lib(closure_1_2[8]);
const rounded = Math.floor((loaded - lib._loaded) / ((timestamp - lib._lastUpdate) / 1000));
2026-07-29 08:29:29 +00:00
if (null != arg2) {
const items = obj2._file.items;
if (items != null) {
const item = items.forEach((item) => {
item.item.progress = table[item.id];
});
}
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
lib._lastUpdate = timestamp;
lib._loaded = loaded;
2026-07-29 08:29:29 +00:00
obj = {};
const merged = Object.assign(obj2._file);
obj.currentSize = total;
obj.progress = obj.calculateProgress(loaded, total);
obj.rate = rounded;
2026-08-24 06:08:38 +00:00
lib._file = obj;
lib.emit("progress", lib._file);
2026-07-29 08:29:29 +00:00
};
2026-08-24 06:08:38 +00:00
tmp3._handleException = function _handleException(closure_0) {
2026-07-29 08:29:29 +00:00
let obj = { reason: null };
2026-08-24 06:08:38 +00:00
obj = { type: closure_1_5.ERROR_SOURCE_UNKNOWN, msg: closure_0.toString() };
2026-07-29 08:29:29 +00:00
obj[0] = obj;
2026-08-24 06:08:38 +00:00
lib._handleError(obj);
2026-07-29 08:29:29 +00:00
};
tmp3._handleAborted = function _handleAborted() {
2026-08-24 06:08:38 +00:00
const result = lib.clearProcessingMessageInterval();
2026-07-29 08:29:29 +00:00
};
tmp3._handleError = function _handleError(arg0) {
({ code, reason, body } = arg0);
2026-08-24 06:08:38 +00:00
const result = lib.clearProcessingMessageInterval();
if (!lib._aborted) {
2026-07-29 08:29:29 +00:00
obj._errored = true;
const _JSON = JSON;
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
closure_1_6.log("_handleError: " + code + " (" + JSON.stringify(reason) + ") for " + obj.id);
2026-07-29 08:29:29 +00:00
obj.emit("error", obj._file, code, body, reason);
obj.removeAllListeners();
2026-07-20 16:05:17 +00:00
}
};
2026-07-29 08:29:29 +00:00
tmp3._handleComplete = function _handleComplete(arg0) {
2026-08-24 06:08:38 +00:00
const result = lib.clearProcessingMessageInterval();
closure_1_6.log("_handleComplete for " + lib.id);
lib.emit("complete", lib._file, arg0);
lib.removeAllListeners();
2026-07-29 08:29:29 +00:00
};
obj = require("apply");
tmp3.id = obj.uniqueId("Uploader");
2026-08-08 06:10:11 +00:00
tmp3._file = { id: tmp3.id, currentSize: 0, totalPreCompressionSize: 0, compressionProgress: 0, progress: 0, rate: 0, hasImage: false, hasVideo: false, attachmentsCount: 0, items: "channel" };
2026-07-29 08:29:29 +00:00
return tmp3;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
const prototype = UploaderBase.prototype;
prototype["_fileSize"] = function _fileSize() {
const files = this.files;
return files.reduce((arg0, currentSize) => {
let num = currentSize.currentSize;
if (num == null) {
num = 0;
}
return arg0 + num;
}, 0);
};
prototype["compressAndCheckFileSize"] = function compressAndCheckFileSize() {
const self = this;
return callback(function*() {
if (c9 === 2) {
c9 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp8 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
2026-07-20 16:05:17 +00:00
} else {
2026-08-25 06:04:03 +00:00
return { value: "HermesInternal", done: "HermesInternal" };
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} else {
try {
c9 = 2;
if (0 === c8) {
if (arg0 === 1) {
c9 = 3;
throw arg1;
} else if (arg0 === 2) {
c9 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
closure_5 = tmp4;
closure_4 = tmp6;
2026-07-29 08:29:29 +00:00
let store;
let files;
2026-08-24 06:08:38 +00:00
c2 = undefined;
2026-07-29 08:29:29 +00:00
let effectiveKestrelLimit;
2026-08-24 06:08:38 +00:00
const first = closure_1_0.files[0];
2026-07-29 08:29:29 +00:00
let target;
if (first != null) {
const item = first.item;
if (item != null) {
target = item.target;
}
}
2026-08-24 06:08:38 +00:00
const uploadTarget = closure_1_0(closure_1_2[6]).getUploadTarget(target);
2026-07-29 08:29:29 +00:00
store = uploadTarget;
2026-08-24 06:08:38 +00:00
if (closure_1_0.files.length > uploadTarget.getMaxAttachmentsCount()) {
2026-07-29 08:29:29 +00:00
const _HermesInternal2 = HermesInternal;
2026-08-24 06:08:38 +00:00
closure_1_6.log("Too many attachments for " + closure_1_0.id);
obj1 = { code: null };
obj1[0] = closure_1_4.TOO_MANY_ATTACHMENTS;
closure_1_0._handleError(obj1);
2026-07-29 08:29:29 +00:00
c9 = 3;
return { value: false, done: true };
} else {
2026-08-24 06:08:38 +00:00
files = closure_1_0(closure_1_2[7]).getKestrelConfig({ location: "UploaderBase.compressAndCheckFileSize" });
2026-07-29 08:29:29 +00:00
const _HermesInternal3 = HermesInternal;
2026-08-24 06:08:38 +00:00
closure_1_6.log("compressing files for " + closure_1_0.id);
files = closure_1_0.files;
2026-07-29 08:29:29 +00:00
store = files[Symbol.iterator]();
2026-08-24 06:08:38 +00:00
const obj15 = closure_1_0(closure_1_2[7]);
2026-07-29 08:29:29 +00:00
}
2026-08-24 06:08:38 +00:00
const obj14 = closure_1_0(closure_1_2[6]);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} else if (1 === tmp9) {
2026-08-24 06:08:38 +00:00
c7 = 0;
2026-07-29 08:29:29 +00:00
store.return();
throw closure_6;
} else if (2 === tmp9) {
c7 = 1;
closure_4 = closure_6;
2026-08-24 06:08:38 +00:00
closure_1_0._handleException(closure_4);
2026-07-29 08:29:29 +00:00
c7 = 0;
store.return();
c9 = 3;
return { value: false, done: true };
} else if (arg0 === 1) {
c9 = 3;
throw arg1;
} else if (arg0 === 2) {
c7 = 0;
store.return();
c9 = 3;
const obj2 = { value: null, done: true };
obj2[0] = arg1;
return obj2;
} else if (c2.isCancelled()) {
2026-07-20 16:05:17 +00:00
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
closure_1_6.log("compressAndCheckFileSize() file has been cancelled for compression - " + c2.id);
2026-07-29 08:29:29 +00:00
c7 = 0;
} else {
const currentSize = c2.currentSize;
c2 = currentSize;
if (currentSize == null) {
c2 = 0;
}
if (0 === c2) {
const obj3 = { code: null };
2026-08-24 06:08:38 +00:00
obj3[0] = closure_1_4.ENTITY_EMPTY;
2026-07-29 08:29:29 +00:00
store._handleError(obj3);
c7 = 0;
store.return();
c9 = 3;
return { value: false, done: true };
2026-07-20 16:05:17 +00:00
} else {
2026-08-24 06:08:38 +00:00
effectiveKestrelLimit = closure_1_0(closure_1_2[7]).getEffectiveKestrelLimit(files, store.getMaxFileSize(c2.channelId));
2026-07-29 08:29:29 +00:00
const currentSize2 = c2.currentSize;
effectiveKestrelLimit = currentSize2;
if (currentSize2 == null) {
effectiveKestrelLimit = 0;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (effectiveKestrelLimit > effectiveKestrelLimit) {
obj = { code: null, reason: null };
2026-08-24 06:08:38 +00:00
obj[0] = closure_1_4.ENTITY_TOO_LARGE;
2026-07-29 08:29:29 +00:00
const obj4 = { type: null };
2026-08-24 06:08:38 +00:00
obj4[0] = closure_1_5.POSTCOMPRESSION_INDIVIDUAL_FILE_TOO_LARGE;
2026-07-29 08:29:29 +00:00
obj[1] = obj4;
store._handleError(obj);
c7 = 0;
store.return();
c9 = 3;
return { value: false, done: true };
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
c7 = 0;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
const obj13 = closure_1_0(closure_1_2[7]);
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
if (store === undefined) {
let flag = store._fileSize() <= store.getMaxTotalAttachmentSize();
if (!flag) {
const obj5 = { code: null, reason: null };
2026-08-24 06:08:38 +00:00
obj5[0] = closure_1_4.ENTITY_TOO_LARGE;
2026-07-29 08:29:29 +00:00
const obj6 = { type: null };
2026-08-24 06:08:38 +00:00
obj6[0] = closure_1_5.POSTCOMPRESSION_SUM_TOO_LARGE;
2026-07-29 08:29:29 +00:00
obj5[1] = obj6;
2026-08-24 06:08:38 +00:00
closure_1_0._handleError(obj5);
2026-07-29 08:29:29 +00:00
flag = false;
}
c9 = 3;
const obj7 = { value: null, done: true };
obj7[0] = flag;
return obj7;
} else {
c2 = tmp46;
c7 = 2;
c8 = 3;
c9 = 1;
const obj8 = { value: null, done: false };
obj8[0] = c2.reactNativeCompressAndExtractData();
return obj8;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} catch (tmp65) {
closure_6 = tmp65;
if (tmp5 === c7) {
c9 = tmp3;
throw tmp65;
} else if (tmp2 === tmp67) {
c8 = tmp2;
} else {
c8 = tmp;
2026-07-20 16:05:17 +00:00
}
}
}
2026-07-29 08:29:29 +00:00
})();
};
prototype["setUploadingTextForUI"] = function setUploadingTextForUI() {
const files = this.files;
const files2 = this.files;
const someResult = files.some((isImage) => isImage.isImage);
const _fileSizeResult = this._fileSize();
2026-08-24 06:08:38 +00:00
logger.log("setUploadingTextForUI - total content: " + _fileSizeResult + " bytes and " + this.files.length + " attachments for " + this.id);
2026-07-29 08:29:29 +00:00
const obj = {};
const merged = Object.assign(this._file);
obj.totalPostCompressionSize = _fileSizeResult;
obj.currentSize = _fileSizeResult;
obj.hasVideo = files2.some((isVideo) => isVideo.isVideo);
obj.hasImage = someResult;
obj.attachmentsCount = this.files.length;
obj.items = this.files;
this._file = obj;
};
prototype["_recomputeProgress"] = function _recomputeProgress() {
const result = this._recomputeProgressTotal();
({ loaded, total } = result);
this._handleProgress(loaded, total, this._recomputeProgressByFile());
};
prototype["_recomputeProgressTotal"] = function _recomputeProgressTotal() {
2026-08-24 06:08:38 +00:00
const obj = {
loaded: files.reduce((arg0, loaded) => {
let num = loaded.loaded;
if (num == null) {
num = 0;
}
return arg0 + num;
}, 0),
total: this._fileSize()
};
files = this.files;
2026-07-29 08:29:29 +00:00
return obj;
};
prototype["_recomputeProgressByFile"] = function _recomputeProgressByFile() {
let obj = {};
const files = this.files;
const item = files.forEach((id) => {
2026-08-24 06:08:38 +00:00
obj = obj(closure_1_2[8]);
2026-07-29 08:29:29 +00:00
obj[id.id] = obj.calculateProgress(id.loaded, id.currentSize);
2026-07-20 16:05:17 +00:00
});
2026-07-29 08:29:29 +00:00
return obj;
};
prototype["_addAttachmentsToPayload"] = function _addAttachmentsToPayload(arg0, arg1, arg2) {
const merged = Object.assign(arg0);
2026-08-24 06:08:38 +00:00
applyDefault;
2026-07-29 08:29:29 +00:00
const items = [...arg2];
2026-08-24 06:08:38 +00:00
return applyDefault.set({}, arg1, items);
2026-07-29 08:29:29 +00:00
};
prototype["clearProcessingMessageInterval"] = function clearProcessingMessageInterval() {
const self = this;
if (null != this.processingMessageChangeInterval) {
const _clearInterval = clearInterval;
clearInterval(self.processingMessageChangeInterval);
self.processingMessageChangeInterval = undefined;
}
};
prototype["cancel"] = function cancel() {
const self = this;
2026-08-24 06:08:38 +00:00
logger.log("cancel() for " + this.id);
2026-07-29 08:29:29 +00:00
if (!this._aborted) {
self._aborted = true;
const _cancel = self._cancel;
if (_cancel != null) {
_cancel();
}
const files = self.files;
const item = files.forEach((cancel) => cancel.cancel());
self._handleComplete();
}
};
prototype["cancelItem"] = function cancelItem(itemId) {
2026-08-24 06:08:38 +00:00
closure_0 = itemId;
2026-07-29 08:29:29 +00:00
const self = this;
return callback(function*() {
if (c4 === 2) {
c4 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp5 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
2026-07-20 16:05:17 +00:00
} else {
2026-08-25 06:04:03 +00:00
return { value: "HermesInternal", done: "HermesInternal" };
2026-07-29 08:29:29 +00:00
}
} else {
try {
c4 = 2;
if (0 === c3) {
if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
closure_2 = tmp3;
closure_1 = tmp2;
closure_0 = undefined;
2026-07-29 08:29:29 +00:00
const _HermesInternal = HermesInternal;
2026-08-24 06:08:38 +00:00
closure_1_6.log("Cancel called for " + closure_1_1.id + " for item " + closure_1_0);
const files = closure_1_1.files;
2026-07-29 08:29:29 +00:00
const found = files.find((id) => id.id === closure_0);
closure_0 = found;
if (null != found) {
if (!found.isCancelled()) {
2026-08-24 06:08:38 +00:00
const files1 = closure_1_1.files;
2026-07-29 08:29:29 +00:00
const index = files1.indexOf(found);
closure_0 = 0;
2026-08-24 06:08:38 +00:00
const files2 = closure_1_1.files;
2026-07-29 08:29:29 +00:00
const items = [];
closure_0 = HermesBuiltin.arraySpread(files2.slice(0, index), closure_0);
2026-08-24 06:08:38 +00:00
const files3 = closure_1_1.files;
2026-07-29 08:29:29 +00:00
closure_0 = HermesBuiltin.arraySpread(files3.slice(index + 1), closure_0);
2026-08-24 06:08:38 +00:00
closure_1_1.files = items;
obj1 = {};
const merged = Object.assign(closure_1_1._file);
obj1.items = closure_1_1.files;
closure_1_1._file = obj1;
let obj2 = closure_1_0(closure_1_2[9]);
2026-07-29 08:29:29 +00:00
c3 = 1;
c4 = 1;
obj2 = { value: null, done: false };
obj2[0] = obj2.cancelGetAttachmentFile(found);
return obj2;
}
}
c4 = 3;
}
} else if (arg0 === 1) {
c4 = 3;
throw arg1;
} else if (arg0 !== 2) {
closure_0.cancel();
closure_1.emit("cancel-upload-item", closure_1._file);
if (0 === closure_1.files.length) {
closure_1.cancel();
}
}
c4 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} catch (tmp31) {
c4 = tmp;
throw tmp31;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
})();
};
prototype["upload"] = function upload(arg0) {
const self = this;
if (null != this._cancel) {
const _Error = Error;
2026-08-24 06:08:38 +00:00
error = new Error("Uploader.upload(...): An upload is already in progress.");
2026-07-29 08:29:29 +00:00
throw error;
} else {
const _Date = Date;
self._lastUpdate = Date.now();
self._loaded = 0;
const obj = { id: null, currentSize: 0, totalPreCompressionSize: 0, compressionProgress: 0, progress: 0, rate: 0, hasImage: false, hasVideo: false, attachmentsCount: 0, items: null };
obj[0] = self.id;
obj[9] = arg0;
self._file = obj;
}
};
2026-08-24 06:08:38 +00:00
const tmp2 = new timestampDefault("UploaderBase.tsx");
let result = require("set").fileFinishedImporting("lib/uploader/UploaderBase.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default UploaderBase;