122 lines
4.0 KiB
TypeScript
122 lines
4.0 KiB
TypeScript
// Metro module 4729 (f4730).
|
|
import { UploadPlatform } from "./Upload";
|
|
import { HTTP } from "../../_bundle/sendRequest";
|
|
import { fileIsInAppDir } from "../../utils/AttachmentFile.native";
|
|
import { isLibdiscoreInitialized, getHttpClientAPI } from "../../_bundle/Module1869";
|
|
export function doesImageMatchUpload(a0, a1) {
|
|
L12: {
|
|
if (a1.id !== a0.uri) {
|
|
if (a1.id != null && a1.id === a0.id) {
|
|
break L12;
|
|
}
|
|
if (a1.item.platform === UploadPlatform.REACT_NATIVE) {
|
|
const item = a1.item;
|
|
const filename = a0.filename;
|
|
let r24 = item.originalUri === a0.uri;
|
|
if (!r24) {
|
|
let r1 = filename == null;
|
|
if (!r1) {
|
|
const originalUri = item.originalUri;
|
|
r1 = !(originalUri == null ? void 0 : originalUri.includes(filename));
|
|
}
|
|
r24 = !r1;
|
|
}
|
|
return r24;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
export function calculateProgress(a0, a1) {
|
|
return a1 !== 0 ? Math.min(Math.floor(a0 / a1 * 100), 100) : 0;
|
|
}
|
|
export class DefaultHttpClient {
|
|
constructor() {
|
|
return {
|
|
__proto__: new.target.prototype
|
|
};
|
|
}
|
|
sliceBody(a0, a1) {
|
|
return a0 instanceof File ? a0.slice(a1) : a0;
|
|
}
|
|
doUpload(a0, a1) {
|
|
if (a1?.fileByteRange != null) {
|
|
a0.body = this.sliceBody(a0.body, a1.fileByteRange.start);
|
|
}
|
|
return HTTP.put(a0);
|
|
}
|
|
}
|
|
export function canUploadNatively(a0) {
|
|
return a0.platform === UploadPlatform.REACT_NATIVE && a0.uri != null && fileIsInAppDir(a0.uri) && isLibdiscoreInitialized();
|
|
}
|
|
export class LibdiscoreHttpClient {
|
|
constructor() {
|
|
const prototype = new.target.prototype;
|
|
if (isLibdiscoreInitialized()) {
|
|
return {
|
|
__proto__: prototype
|
|
};
|
|
}
|
|
throw new Error("Libdiscore is not loaded");
|
|
}
|
|
doUpload(a0, a1) {
|
|
let c14413_2;
|
|
const httpClientAPI = getHttpClientAPI();
|
|
if (httpClientAPI == null) {
|
|
throw new Error("Libdiscore client is not available");
|
|
}
|
|
const r21 = a0.body?.uri !== void 0 && typeof a0.body.uri === "string";
|
|
let path = void 0;
|
|
if (r21) {
|
|
const r27 = a0.body.uri.startsWith("file://");
|
|
const uri = a0.body.uri;
|
|
path = r27 ? uri.slice(7) : uri;
|
|
}
|
|
if (path !== void 0 && path !== "") {
|
|
c14413_2 = httpClientAPI.httpRequest(a0.url, {
|
|
method: "PUT",
|
|
body: {
|
|
path,
|
|
byteRangeStart: a1 == null ? void 0 : a1.fileByteRange?.start,
|
|
byteRangeEnd: a1 == null ? void 0 : a1.fileByteRange?.end
|
|
},
|
|
headers: a0.headers
|
|
});
|
|
return new Promise((c25268_0, c25268_1) => {
|
|
const pollStatus2 = function pollStatus() {
|
|
if (httpClientAPI != null) {
|
|
if (a0.signal?.aborted) {
|
|
c25268_1(new Error("Request cancelled"));
|
|
httpClientAPI.cancelHttpRequest(c14413_2);
|
|
return void 0;
|
|
}
|
|
const httpRequestStatus = httpClientAPI.getHttpRequestStatus(c14413_2);
|
|
if (httpRequestStatus?.status === "success") {
|
|
c25268_0({
|
|
status: httpRequestStatus.response?.status,
|
|
headers: httpRequestStatus.response?.headers,
|
|
text: httpRequestStatus.response?.body
|
|
});
|
|
} else if (httpRequestStatus?.status === "error") {
|
|
c25268_1(new Error(httpRequestStatus.error));
|
|
} else if (httpRequestStatus?.status === "progressing") {
|
|
if (a0.onRequestProgress !== void 0 && httpRequestStatus.uploaded_bytes != null && httpRequestStatus.uploaded_bytes > 0) {
|
|
a0.onRequestProgress({
|
|
loaded: httpRequestStatus.uploaded_bytes,
|
|
total: httpRequestStatus.total_bytes
|
|
});
|
|
}
|
|
setTimeout(pollStatus2, 50);
|
|
} else {
|
|
c25268_1(new Error("Unknown upload status"));
|
|
}
|
|
}
|
|
};
|
|
pollStatus2();
|
|
});
|
|
}
|
|
throw new Error("No file path found in request body");
|
|
}
|
|
}
|