1
0
mirror of https://github.com/element-hq/element-web.git synced 2025-11-29 21:23:11 +03:00

Fix types and precompute blob sizes to avoid overflows

This commit is contained in:
Jaiwanth
2021-07-19 13:17:19 +05:30
parent ed93bf4c77
commit f07402d234
5 changed files with 31 additions and 21 deletions

View File

@@ -45,11 +45,13 @@ export default class JSONExporter extends Exporter {
if (this.exportOptions.attachmentsIncluded && this.isAttachment(mxEv)) {
try {
const blob = await this.getMediaBlob(mxEv);
this.totalSize += blob.size;
const filePath = this.getFilePath(mxEv);
this.addFile(filePath, blob);
if (this.totalSize > this.exportOptions.maxSize - 1024 * 1024) {
this.exportOptions.attachmentsIncluded = false;
if (this.totalSize + blob.size < this.exportOptions.maxSize) {
this.totalSize += blob.size;
const filePath = this.getFilePath(mxEv);
if (this.totalSize == this.exportOptions.maxSize) {
this.exportOptions.attachmentsIncluded = false;
}
this.addFile(filePath, blob);
}
} catch (err) {
console.log("Error fetching file: " + err);