mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 20:38:55 +03:00
Fix types and precompute blob sizes to avoid overflows
This commit is contained in:
parent
ed93bf4c77
commit
f07402d234
5 changed files with 31 additions and 21 deletions
|
@ -179,7 +179,7 @@ export default class MImageBody extends React.Component<IProps, IState> {
|
|||
};
|
||||
|
||||
protected getContentUrl(): string {
|
||||
const content = this.props.mxEvent.getContent();
|
||||
const content: IMediaEventContent= this.props.mxEvent.getContent();
|
||||
if (this.props.forExport) return content.url || content.file.url;
|
||||
const media = mediaFromContent(content);
|
||||
if (media.isEncrypted) {
|
||||
|
|
|
@ -306,13 +306,17 @@ export default class HTMLExporter extends Exporter {
|
|||
if (this.exportOptions.attachmentsIncluded) {
|
||||
try {
|
||||
const blob = await this.getMediaBlob(mxEv);
|
||||
this.totalSize += blob.size;
|
||||
const filePath = this.getFilePath(mxEv);
|
||||
eventTile = await this.getEventTile(mxEv, joined, filePath);
|
||||
if (this.totalSize > this.exportOptions.maxSize - 1024 * 512) {
|
||||
this.exportOptions.attachmentsIncluded = false;
|
||||
if (this.totalSize + blob.size > this.exportOptions.maxSize) {
|
||||
eventTile = await this.getEventTile(this.createModifiedEvent(this.mediaOmitText, mxEv), joined);
|
||||
} else {
|
||||
this.totalSize += blob.size;
|
||||
const filePath = this.getFilePath(mxEv);
|
||||
eventTile = await this.getEventTile(mxEv, joined, filePath);
|
||||
if (this.totalSize == this.exportOptions.maxSize) {
|
||||
this.exportOptions.attachmentsIncluded = false;
|
||||
}
|
||||
this.addFile(filePath, blob);
|
||||
}
|
||||
this.addFile(filePath, blob);
|
||||
} catch (e) {
|
||||
console.log("Error while fetching file" + e);
|
||||
eventTile = await this.getEventTile(
|
||||
|
@ -339,7 +343,7 @@ export default class HTMLExporter extends Exporter {
|
|||
|
||||
content += this._wantsDateSeparator(event, prevEvent) ? this.getDateSeparator(event) : "";
|
||||
const shouldBeJoined = !this._wantsDateSeparator(event, prevEvent)
|
||||
&& shouldFormContinuation(prevEvent, event);
|
||||
&& shouldFormContinuation(prevEvent, event, false);
|
||||
const body = await this.createMessageBody(event, shouldBeJoined);
|
||||
this.totalSize += Buffer.byteLength(body);
|
||||
content += body;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -66,12 +66,16 @@ export default class PlainTextExporter extends Exporter {
|
|||
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;
|
||||
if (this.totalSize + blob.size > this.exportOptions.maxSize) {
|
||||
mediaText = ` (${this.mediaOmitText})`;
|
||||
} else {
|
||||
this.totalSize += blob.size;
|
||||
const filePath = this.getFilePath(mxEv);
|
||||
mediaText = " (" + _t("File Attached") + ")";
|
||||
this.addFile(filePath, blob);
|
||||
if (this.totalSize == this.exportOptions.maxSize) {
|
||||
this.exportOptions.attachmentsIncluded = false;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
mediaText = " (" + _t("Error fetching file") + ")";
|
||||
|
|
|
@ -223,8 +223,8 @@ export default function streamToZIP(underlyingSource: UnderlyingSource) {
|
|||
function closeZip() {
|
||||
let length = 0;
|
||||
let index = 0;
|
||||
let indexFilename;
|
||||
let file;
|
||||
let indexFilename: number;
|
||||
let file: any;
|
||||
|
||||
for (indexFilename = 0; indexFilename < filenames.length; indexFilename++) {
|
||||
file = files[filenames[indexFilename]];
|
||||
|
|
Loading…
Reference in a new issue