try catch for plain text

This commit is contained in:
Jaiwanth 2021-06-25 14:49:01 +05:30
parent 02f15d573a
commit abbe047bfd
2 changed files with 19 additions and 10 deletions

View file

@ -118,7 +118,7 @@ export default abstract class Exporter {
limit = 40;
break;
default:
limit = Number.MAX_VALUE;
limit = 10**8;
}
return limit;
}

View file

@ -56,16 +56,25 @@ export default class PlainTextExporter extends Exporter {
protected _textForEvent = async (mxEv: MatrixEvent) => {
const senderDisplayName = mxEv.sender && mxEv.sender.name ? mxEv.sender.name : mxEv.getSender();
if (this.exportOptions.attachmentsIncluded && this.isAttachment(mxEv)) {
let mediaText = "";
if (this.isAttachment(mxEv)) {
if (this.exportOptions.attachmentsIncluded) {
try {
const blob = await this.getMediaBlob(mxEv);
this.totalSize += blob.size;
const filePath = this.getFilePath(mxEv);
mediaText = " (" + _t("File Attached") + ")";
this.addFile(filePath, blob);
if (this.totalSize > this.exportOptions.maxSize - 1024 * 1024) {
this.exportOptions.attachmentsIncluded = false;
}
} catch (error) {
mediaText = " (" + _t("Error fetching file") + ")";
console.log("Error fetching file" + error);
}
if (this.isReply(mxEv)) return senderDisplayName + ": " + this.textForReplyEvent(mxEv);
} else mediaText = ` (${this.mediaOmitText})`;
}
if (this.isReply(mxEv)) return senderDisplayName + ": " + this.textForReplyEvent(mxEv) + mediaText;
else return textForEvent(mxEv);
}