decord/alpha/source/utils/UploadUtils.tsx

339 lines
8.6 KiB
TypeScript
Raw Permalink Normal View History

2026-10-12 06:59:38 +00:00
// Module ID: 7760
// Function ID: 7761
// Name: UploadUtils
2026-10-12 06:59:38 +00:00
// Dependencies: [7761, 7762, 7759, 2]
// Exports: getAttachmentPayload, getFile, getFileContentLength, getFileData, getMaxTotalAttachmentSize
2026-07-20 16:05:17 +00:00
2026-10-12 06:59:38 +00:00
// Module 7760 (UploadUtils)
import UploadPlatform from "UploadPlatform" /* 7759 */;
import NitroFileUploadExperiments from "NitroFileUploadExperiments" /* 7761 */;
import clipPayloadUtils from "clipPayloadUtils" /* 7762 */;
import size from "module_2" /* 2 */;
2026-08-24 06:08:38 +00:00
2026-10-03 08:58:59 +00:00
let reName;
let obj = {
reName: /\.jpe?g$/i,
name(arg0) {
return "image" + arg0 + ".jpg";
2026-07-20 16:05:17 +00:00
},
2026-10-03 08:58:59 +00:00
type: "image/jpeg"
};
const items = [
obj,
2026-07-29 08:29:29 +00:00
{
reName: /\.jfif$/i,
name(arg0) {
return "image" + arg0 + ".jpg";
},
type: "image/jpeg"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.png$/i,
name(arg0) {
return "image" + arg0 + ".png";
},
type: "image/png"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.gif$/i,
name(arg0) {
return "image" + arg0 + ".gif";
},
type: "image/gif"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.webp$/i,
name(arg0) {
return "image" + arg0 + ".webp";
},
type: "image/webp"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.avif$/i,
name(arg0) {
return "image" + arg0 + ".avif";
},
type: "image/avif"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.heic$/i,
name(arg0) {
return "image" + arg0 + ".heic";
},
type: "image/heic"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.heif$/i,
name(arg0) {
return "image" + arg0 + ".heif";
},
type: "image/heif"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.dng$/i,
name(arg0) {
return "image" + arg0 + ".dng";
},
type: "image/x-adobe-dng"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.mov$/i,
name(arg0) {
return "video" + arg0 + ".mov";
},
type: "video/quicktime"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.qt$/i,
name(arg0) {
return "video" + arg0 + ".qt";
},
type: "video/quicktime"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.avi$/i,
name(arg0) {
return "video" + arg0 + ".avi";
},
type: "video/x-msvideo"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.mp4$/i,
name(arg0) {
return "video" + arg0 + ".mp4";
},
type: "video/mp4"
2026-07-20 16:05:17 +00:00
},
2026-07-29 08:29:29 +00:00
{
reName: /\.webm$/i,
name(arg0) {
return "video" + arg0 + ".webm";
},
type: "image/webm"
}
];
let c3 = 524288000;
let c4 = 1073741824;
const result = size.fileFinishedImporting("utils/UploadUtils.tsx");
2026-07-20 16:05:17 +00:00
export const MAX_TOTAL_ATTACHMENT_SIZE = 524288000;
export const MAX_TOTAL_ATTACHMENT_SIZE_1GB = 1073741824;
2026-07-20 16:05:17 +00:00
export const MAX_TOTAL_ATTACHMENT_SIZE_MB = 500;
export const getMaxTotalAttachmentSize = function getMaxTotalAttachmentSize(location) {
2026-10-03 08:58:59 +00:00
const _location = location.location;
const obj = NitroFileUploadExperiments;
return obj.getNitroFileUploadRolloutConfig({ location: _location }).enabled ? c4 : c3;
};
export const getAttachmentPayload = function getAttachmentPayload(id, index, name) {
2026-10-03 08:58:59 +00:00
let filename;
let tmp = index;
if (index === undefined) {
2026-07-20 16:05:17 +00:00
tmp = null;
}
let str1;
2026-07-29 08:29:29 +00:00
if (tmp != null) {
str1 = tmp.toString();
2026-07-20 16:05:17 +00:00
}
if (str1 == null) {
str1 = id.id;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const obj = { id: str1, filename, uploaded_filename: id.uploadedFilename };
if (null != id.description) {
obj.description = id.description;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
filename = name;
2026-07-29 08:29:29 +00:00
if (name == null) {
filename = id.filename;
2026-07-20 16:05:17 +00:00
}
if (id.spoiler) {
2026-07-20 16:05:17 +00:00
obj.is_spoiler = true;
}
2026-10-03 08:58:59 +00:00
const tmp3 = "durationSecs" in id && null != id.durationSecs;
2026-07-20 16:05:17 +00:00
if (tmp3) {
obj.duration_secs = id.durationSecs;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const tmp4 = "waveform" in id && null != id.waveform;
2026-07-20 16:05:17 +00:00
if (tmp4) {
obj.waveform = id.waveform;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const tmp5 = "isThumbnail" in id && true === id.isThumbnail;
2026-07-20 16:05:17 +00:00
if (tmp5) {
obj.is_thumbnail = id.isThumbnail;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const tmp6 = "clip" in id && null != id.clip;
2026-07-20 16:05:17 +00:00
if (tmp6) {
obj.is_clip = true;
obj.title = id.clip.name;
obj.application_id = id.clip.applicationId;
2026-10-03 08:58:59 +00:00
const obj2 = clipPayloadUtils;
obj.clip_created_at = obj2.getClipCreatedAt(id.clip.createdAt);
const obj3 = clipPayloadUtils;
obj.clip_participant_ids = obj3.getClipParticipantIds(id.clip.users);
obj.clip_remote_id = id.clip.remoteClipId;
2026-10-03 08:58:59 +00:00
const obj4 = clipPayloadUtils;
obj.clip_events_timeline = obj4.getClipEventsTimeline(id.clip);
const obj5 = clipPayloadUtils;
obj.clip_sync_timestamp = obj5.getClipSyncTimestamp(id.clip);
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const tmp9 = "item" in id && null != id.item && id.item.platform === UploadPlatform.UploadPlatform.WEB && "mimeType" in id && null != id.mimeType;
2026-07-20 16:05:17 +00:00
if (tmp9) {
obj.original_content_type = id.mimeType;
2026-07-20 16:05:17 +00:00
}
return obj;
};
export const getFileData = function getFileData(arg0) {
2026-10-03 08:58:59 +00:00
let closure_0 = arg0;
2026-07-23 10:11:24 +00:00
let xMLHttpRequest = new XMLHttpRequest();
2026-10-03 08:58:59 +00:00
const promise = new Promise((arg0, arg1) => {
let closure_1;
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
xMLHttpRequest = arg1;
2026-07-23 10:11:24 +00:00
xMLHttpRequest.open("GET", closure_0, true);
2026-07-20 16:05:17 +00:00
xMLHttpRequest.responseType = "blob";
xMLHttpRequest.onabort = (arg0) => closure_1(arg0);
xMLHttpRequest.onerror = (arg0) => closure_1(arg0);
xMLHttpRequest.ontimeout = (arg0) => closure_1(arg0);
2026-07-20 16:05:17 +00:00
xMLHttpRequest.onload = () => {
let data;
2026-10-03 08:58:59 +00:00
const tmp = closure_0;
if (xMLHttpRequest != null) {
const response = xMLHttpRequest.response;
2026-07-29 08:29:29 +00:00
if (response != null) {
2026-07-20 16:05:17 +00:00
data = response.data;
}
}
2026-10-03 08:58:59 +00:00
return tmp(data);
2026-07-20 16:05:17 +00:00
};
xMLHttpRequest.send();
});
2026-10-03 08:58:59 +00:00
return promise;
2026-07-20 16:05:17 +00:00
};
export const getFileContentLength = function getFileContentLength(arg0) {
2026-10-03 08:58:59 +00:00
let closure_0 = arg0;
const promise = new Promise((arg0, onerror) => {
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
2026-10-03 08:58:59 +00:00
let closure_1 = onerror;
2026-07-20 16:05:17 +00:00
const xMLHttpRequest = new XMLHttpRequest();
2026-07-23 10:11:24 +00:00
xMLHttpRequest.open("HEAD", closure_0, true);
2026-10-03 08:58:59 +00:00
xMLHttpRequest.onload = function() {
2026-07-20 16:05:17 +00:00
if (xMLHttpRequest.status >= 200) {
2026-10-03 08:58:59 +00:00
if (xMLHttpRequest.status < 300) {
2026-07-29 08:29:29 +00:00
const responseHeader = obj.getResponseHeader("Content-Length");
2026-07-20 16:05:17 +00:00
if (null != responseHeader) {
if ("" !== responseHeader) {
const _parseInt = parseInt;
closure_0(parseInt(responseHeader, 10));
2026-07-20 16:05:17 +00:00
}
}
const _Error = Error;
2026-10-03 08:58:59 +00:00
const self = this;
const self2 = this;
const error = new Error("Content-Length header is missing");
2026-10-03 08:58:59 +00:00
closure_1(error);
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
const error1 = new Error("HTTP request failed with status code " + obj.status);
2026-10-03 08:58:59 +00:00
closure_1(error1);
2026-07-20 16:05:17 +00:00
};
xMLHttpRequest.onerror = onerror;
xMLHttpRequest.onabort = onerror;
xMLHttpRequest.ontimeout = onerror;
xMLHttpRequest.send();
});
2026-10-03 08:58:59 +00:00
return promise;
2026-07-20 16:05:17 +00:00
};
export const getFile = function getFile(overrideType) {
2026-10-03 08:58:59 +00:00
let i;
let overrideFilename;
let str10;
let str11;
let str5;
let uri;
2026-07-20 16:05:17 +00:00
({ uri, i, overrideFilename } = overrideType);
2026-07-29 08:29:29 +00:00
let str = overrideType.overrideType;
2026-07-20 16:05:17 +00:00
const parts = uri.split("/");
2026-07-29 08:29:29 +00:00
const parts1 = str2.split("?");
let str3;
2026-07-29 08:29:29 +00:00
if (parts1 != null) {
if (parts1[0] != null) {
str3 = str4.toLowerCase();
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
if (str3 == null) {
str3 = "";
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const found = items.find((reName) => {
2026-07-20 16:05:17 +00:00
reName = reName.reName;
2026-07-29 08:29:29 +00:00
return reName.test(str3);
2026-07-20 16:05:17 +00:00
});
2026-07-29 08:29:29 +00:00
let found1 = found;
2026-10-03 08:58:59 +00:00
const arr2 = items;
const tmp3 = null == found && null != overrideFilename;
2026-07-20 16:05:17 +00:00
if (tmp3) {
2026-10-03 08:58:59 +00:00
found1 = arr2.find((reName) => {
2026-07-20 16:05:17 +00:00
reName = reName.reName;
return reName.test(overrideFilename);
});
}
2026-07-29 08:29:29 +00:00
if (null != found1) {
2026-07-20 16:05:17 +00:00
if (null != overrideFilename) {
2026-10-03 08:58:59 +00:00
let combined;
const str6 = found1.name(i);
const parts2 = str6.split(".");
2026-07-20 16:05:17 +00:00
const arr = parts2.pop();
2026-10-03 08:58:59 +00:00
const lastIndexOfResult = overrideFilename.lastIndexOf(".");
if (-1 !== lastIndexOfResult) {
2026-07-20 16:05:17 +00:00
const _HermesInternal2 = HermesInternal;
2026-10-03 08:58:59 +00:00
combined = "" + overrideFilename.substr(0, lastIndexOfResult) + "." + arr;
2026-07-20 16:05:17 +00:00
} else {
const _HermesInternal = HermesInternal;
2026-07-29 08:29:29 +00:00
combined = "" + overrideFilename + "." + arr;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
str5 = combined;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const obj = { uri, filename: str5, type: str10, isVideo: -1 !== str11.indexOf("video"), isImage: -1 !== str.indexOf("image") };
str10 = str;
if (str == null) {
let type;
if (found1 != null) {
type = found1.type;
}
str10 = type;
}
if (str10 == null) {
str10 = "unknown";
}
str11 = str;
if (str == null) {
let nameResult;
if (found1 != null) {
nameResult = found1.name(i);
}
str11 = nameResult;
}
if (str11 == null) {
str11 = "";
}
if (str == null) {
let nameResult1;
if (found1 != null) {
nameResult1 = found1.name(i);
}
str = nameResult1;
}
if (str == null) {
str = "";
}
return obj;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (null != found1) {
2026-10-03 08:58:59 +00:00
str5 = found1.name(i);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
str5 = overrideFilename;
if (overrideFilename == null) {
str5 = "unknown";
2026-07-20 16:05:17 +00:00
}
}
};