decord/source/utils/UploadUtils.tsx

326 lines
7.9 KiB
TypeScript
Raw Normal View History

2026-07-29 08:29:29 +00:00
// Module ID: 4723
// Function ID: 4724
2026-07-20 16:05:17 +00:00
// Name: items
2026-07-29 08:29:29 +00:00
// Dependencies: [4724, 4722, 2]
2026-07-20 16:05:17 +00:00
// Exports: getAttachmentPayload, getFile, getFileContentLength, getFileData
2026-07-29 08:29:29 +00:00
// Module 4723 (items)
2026-07-20 16:05:17 +00:00
const items = [
{
2026-07-29 08:29:29 +00:00
reName: /\.jpe?g$/i,
2026-07-20 16:05:17 +00:00
name(arg0) {
return "image" + arg0 + ".jpg";
},
type: "image/jpeg"
},
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"
}
];
2026-07-23 10:11:24 +00:00
const result = require("set").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_MB = 500;
2026-07-29 08:29:29 +00:00
export const getAttachmentPayload = function getAttachmentPayload(closure_0, closure_1, name) {
let tmp = closure_1;
if (closure_1 === undefined) {
2026-07-20 16:05:17 +00:00
tmp = null;
}
let str;
2026-07-29 08:29:29 +00:00
if (tmp != null) {
2026-07-20 16:05:17 +00:00
str = tmp.toString();
}
2026-07-29 08:29:29 +00:00
if (str == null) {
str = closure_0.id;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const obj = { id: str };
if (null != closure_0.description) {
obj.description = closure_0.description;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let filename = name;
if (name == null) {
filename = closure_0.filename;
2026-07-20 16:05:17 +00:00
}
obj.filename = filename;
2026-07-29 08:29:29 +00:00
obj.uploaded_filename = closure_0.uploadedFilename;
if (closure_0.spoiler) {
2026-07-20 16:05:17 +00:00
obj.is_spoiler = true;
}
if (tmp3) {
2026-07-29 08:29:29 +00:00
obj.duration_secs = closure_0.durationSecs;
2026-07-20 16:05:17 +00:00
}
if (tmp4) {
2026-07-29 08:29:29 +00:00
obj.waveform = closure_0.waveform;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let tmp5 = "isThumbnail" in closure_0;
2026-07-20 16:05:17 +00:00
if (tmp5) {
2026-07-29 08:29:29 +00:00
tmp5 = true === closure_0.isThumbnail;
2026-07-20 16:05:17 +00:00
}
if (tmp5) {
2026-07-29 08:29:29 +00:00
obj.is_thumbnail = closure_0.isThumbnail;
2026-07-20 16:05:17 +00:00
}
if (tmp6) {
obj.is_clip = true;
2026-07-29 08:29:29 +00:00
obj.title = closure_0.clip.name;
obj.application_id = closure_0.clip.applicationId;
obj.clip_created_at = require(4724) /* getClipCreatedAt */.getClipCreatedAt(closure_0.clip.createdAt);
const obj2 = require(4724) /* getClipCreatedAt */;
obj.clip_participant_ids = require(4724) /* getClipCreatedAt */.getClipParticipantIds(closure_0.clip.users);
obj.clip_remote_id = closure_0.clip.remoteClipId;
const obj3 = require(4724) /* getClipCreatedAt */;
obj.clip_events_timeline = require(4724) /* getClipCreatedAt */.getClipEventsTimeline(closure_0.clip);
const obj4 = require(4724) /* getClipCreatedAt */;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let tmp9 = "item" in closure_0 && null != closure_0.item;
2026-07-20 16:05:17 +00:00
if (tmp9) {
2026-07-29 08:29:29 +00:00
tmp9 = closure_0.item.platform === require(4722) /* cancel */.UploadPlatform.WEB;
2026-07-20 16:05:17 +00:00
}
if (tmp9) {
str = "mimeType";
2026-07-29 08:29:29 +00:00
tmp9 = "mimeType" in closure_0;
2026-07-20 16:05:17 +00:00
}
if (tmp9) {
2026-07-29 08:29:29 +00:00
tmp9 = null != closure_0.mimeType;
2026-07-20 16:05:17 +00:00
}
if (tmp9) {
2026-07-29 08:29:29 +00:00
obj.original_content_type = closure_0.mimeType;
2026-07-20 16:05:17 +00:00
}
return obj;
};
export const getFileData = function getFileData(arg0) {
2026-07-23 10:11:24 +00:00
let closure_0 = arg0;
let xMLHttpRequest = new XMLHttpRequest();
2026-07-20 16:05:17 +00:00
return new Promise((arg0, arg1) => {
2026-07-23 10:11:24 +00:00
let closure_0 = arg0;
2026-07-20 16:05:17 +00:00
const 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";
2026-07-23 10:11:24 +00:00
xMLHttpRequest.onabort = (arg0) => lib(arg0);
xMLHttpRequest.onerror = (arg0) => lib(arg0);
xMLHttpRequest.ontimeout = (arg0) => lib(arg0);
2026-07-20 16:05:17 +00:00
xMLHttpRequest.onload = () => {
let data;
2026-07-29 08:29:29 +00:00
if (lib != null) {
2026-07-23 10:11:24 +00:00
const response = lib.response;
2026-07-29 08:29:29 +00:00
if (response != null) {
2026-07-20 16:05:17 +00:00
data = response.data;
}
}
2026-07-23 10:11:24 +00:00
return closure_0(data);
2026-07-20 16:05:17 +00:00
};
xMLHttpRequest.send();
});
};
export const getFileContentLength = function getFileContentLength(arg0) {
2026-07-23 10:11:24 +00:00
let closure_0 = arg0;
2026-07-20 16:05:17 +00:00
return new Promise((arg0, onerror) => {
2026-07-23 10:11:24 +00:00
let closure_0 = arg0;
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-07-20 16:05:17 +00:00
xMLHttpRequest.onload = () => {
if (xMLHttpRequest.status >= 200) {
2026-07-29 08:29:29 +00:00
if (obj.status < 300) {
const responseHeader = obj.getResponseHeader("Content-Length");
2026-07-20 16:05:17 +00:00
if (null != responseHeader) {
if ("" !== responseHeader) {
const _parseInt = parseInt;
2026-07-23 10:11:24 +00:00
callback(parseInt(responseHeader, 10));
2026-07-20 16:05:17 +00:00
}
}
const _Error = Error;
const error = new Error("Content-Length header is missing");
2026-07-23 10:11:24 +00:00
onerror(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-07-23 10:11:24 +00:00
onerror(error1);
2026-07-20 16:05:17 +00:00
};
xMLHttpRequest.onerror = onerror;
xMLHttpRequest.onabort = onerror;
xMLHttpRequest.ontimeout = onerror;
xMLHttpRequest.send();
});
};
export const getFile = function getFile(overrideType) {
let i;
let overrideFilename;
let uri;
({ uri, i, overrideFilename } = overrideType);
2026-07-29 08:29:29 +00:00
let str = overrideType.overrideType;
let str3;
2026-07-20 16:05:17 +00:00
const parts = uri.split("/");
2026-07-29 08:29:29 +00:00
str3 = str2;
const parts1 = str2.split("?");
str3 = undefined;
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-07-20 16:05:17 +00:00
if (tmp3) {
2026-07-29 08:29:29 +00:00
found1 = items.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-07-29 08:29:29 +00:00
const parts2 = found1.name(i).split(".");
2026-07-20 16:05:17 +00:00
const arr = parts2.pop();
2026-07-29 08:29:29 +00:00
let concat = overrideFilename.lastIndexOf(".");
if (-1 !== concat) {
overrideFilename = overrideFilename.substr(0, concat);
2026-07-20 16:05:17 +00:00
const _HermesInternal2 = HermesInternal;
2026-07-29 08:29:29 +00:00
concat = HermesInternal.concat;
let combined = concat(overrideFilename, ".", 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-07-29 08:29:29 +00:00
const str6 = found1.name(i);
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
if (null != found1) {
let 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
}
}
2026-07-29 08:29:29 +00:00
const obj = { uri, filename: str5, type: null, isVideo: null, isImage: null };
let str10 = str;
if (str == null) {
2026-07-20 16:05:17 +00:00
let type;
2026-07-29 08:29:29 +00:00
if (found1 != null) {
type = found1.type;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
str10 = type;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (str10 == null) {
str10 = "unknown";
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[2] = str10;
let str11 = str;
if (str == null) {
2026-07-20 16:05:17 +00:00
let nameResult;
2026-07-29 08:29:29 +00:00
if (found1 != null) {
nameResult = found1.name(i);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
str11 = nameResult;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (str11 == null) {
str11 = "";
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[3] = -1 !== str11.indexOf("video");
if (str == null) {
2026-07-20 16:05:17 +00:00
let nameResult1;
2026-07-29 08:29:29 +00:00
if (found1 != null) {
nameResult1 = found1.name(i);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
str = nameResult1;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (str == null) {
str = "";
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
obj[4] = -1 !== str.indexOf("image");
2026-07-20 16:05:17 +00:00
return obj;
};