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

@ -262,7 +262,7 @@
<script>
import Vue from "vue";
import { TimelineWindow, EventTimeline, AbortError } from "matrix-js-sdk";
import { TimelineWindow, EventTimeline } from "matrix-js-sdk";
import util from "../plugins/utils";
import MessageOperations from "./messages/MessageOperations.vue";
import AvatarOperations from "./messages/AvatarOperations.vue";
@ -936,7 +936,6 @@ export default {
var reader = new FileReader();
reader.onload = (e) => {
const file = event.target.files[0];
this.currentSendShowSendButton = true;
if (file.type.startsWith("image/")) {
this.currentImageInput = {
image: e.target.result,
@ -985,7 +984,15 @@ export default {
}
}
console.log(this.currentImageInput);
this.currentImageInputPath = file;
this.$matrix.matrixClient.getMediaConfig().then((config) => {
this.currentImageInputPath = file;
if (config["m.upload.size"] && file.size > config["m.upload.size"]) {
this.currentSendError = this.$t("message.upload_file_too_large");
this.currentSendShowSendButton = false;
} else {
this.currentSendShowSendButton = true;
}
});
};
reader.readAsDataURL(event.target.files[0]);
}
@ -1034,7 +1041,7 @@ export default {
}
})
.catch((err) => {
if (err instanceof AbortError || err === "Abort") {
if (err.name === "AbortError" || err === "Abort") {
this.currentSendError = null;
} else {
this.currentSendError = err.LocaleString();