Fix cancel of file uploads again (after upstream changes)

Also, check server max upload size and fail early for large files!
This commit is contained in:
N-Pex 2023-05-11 10:11:34 +02:00
parent 3119601ef6
commit 1f1f9bbb86
3 changed files with 19 additions and 8 deletions

View file

@ -28,11 +28,12 @@ var _browserCanRecordAudioF = function () {
}
var _browserCanRecordAudio = _browserCanRecordAudioF();
class AbortablePromise extends Promise {
class UploadPromise extends Promise {
constructor(executor) {
const aborter = {
aborted: false,
abortablePromise: undefined,
matrixClient: undefined,
}
const normalExecutor = function (resolve, reject) {
@ -42,8 +43,9 @@ class AbortablePromise extends Promise {
super(normalExecutor);
this.abort = () => {
aborter.aborted = true;
if (aborter.abortablePromise) {
aborter.abortablePromise.abort();
if (aborter.abortablePromise && aborter.matrixClient) {
aborter.matrixClient.cancelUpload(aborter.abortablePromise);
aborter.matrixClient = undefined;
aborter.abortablePromise = undefined;
}
};
@ -320,7 +322,7 @@ class Util {
}
sendImage(matrixClient, roomId, file, onUploadProgress) {
return new AbortablePromise((resolve, reject, aborter) => {
return new UploadPromise((resolve, reject, aborter) => {
const abortionController = aborter;
var reader = new FileReader();
reader.onload = (e) => {
@ -366,6 +368,7 @@ class Util {
if (!matrixClient.isRoomEncrypted(roomId)) {
// Not encrypted.
abortionController.matrixClient = matrixClient;
abortionController.abortablePromise = matrixClient.uploadContent(data, opts);
abortionController.abortablePromise
.then((response) => {