Enable option to set maximum file size
This commit is contained in:
parent
30c7017fad
commit
bd75849e73
4 changed files with 20 additions and 3 deletions
|
@ -86,7 +86,11 @@ export default class RoomHeader extends React.Component {
|
||||||
this.props.room,
|
this.props.room,
|
||||||
exportFormats.HTML,
|
exportFormats.HTML,
|
||||||
exportTypes.START_DATE,
|
exportTypes.START_DATE,
|
||||||
{ startDate: parseInt(new Date("2021.05.20").getTime().toFixed(0)), attachmentsIncluded: false },
|
{
|
||||||
|
startDate: parseInt(new Date("2021.05.20").getTime().toFixed(0)),
|
||||||
|
attachmentsIncluded: true,
|
||||||
|
maxSize: 3 * 1024 * 1024, // 3 MB
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -727,6 +727,8 @@
|
||||||
"Invite to %(spaceName)s": "Invite to %(spaceName)s",
|
"Invite to %(spaceName)s": "Invite to %(spaceName)s",
|
||||||
"Share your public space": "Share your public space",
|
"Share your public space": "Share your public space",
|
||||||
"Unknown App": "Unknown App",
|
"Unknown App": "Unknown App",
|
||||||
|
"Media omitted": "Media omitted",
|
||||||
|
"Media omitted - file size limit exceeded": "Media omitted - file size limit exceeded",
|
||||||
"%(creatorName)s created this room.": "%(creatorName)s created this room.",
|
"%(creatorName)s created this room.": "%(creatorName)s created this room.",
|
||||||
"This is the start of export of <roomName/>. Exported by <exporterDetails/> at %(exportDate)s.": "This is the start of export of <roomName/>. Exported by <exporterDetails/> at %(exportDate)s.",
|
"This is the start of export of <roomName/>. Exported by <exporterDetails/> at %(exportDate)s.": "This is the start of export of <roomName/>. Exported by <exporterDetails/> at %(exportDate)s.",
|
||||||
"Topic: %(topic)s": "Topic: %(topic)s",
|
"Topic: %(topic)s": "Topic: %(topic)s",
|
||||||
|
|
|
@ -31,6 +31,8 @@ export default class HTMLExporter extends Exporter {
|
||||||
protected avatars: Map<string, boolean>;
|
protected avatars: Map<string, boolean>;
|
||||||
protected permalinkCreator: RoomPermalinkCreator;
|
protected permalinkCreator: RoomPermalinkCreator;
|
||||||
protected matrixClient: MatrixClient;
|
protected matrixClient: MatrixClient;
|
||||||
|
protected totalSize: number;
|
||||||
|
protected mediaOmitText: string;
|
||||||
|
|
||||||
constructor(room: Room, exportType: exportTypes, exportOptions: exportOptions) {
|
constructor(room: Room, exportType: exportTypes, exportOptions: exportOptions) {
|
||||||
super(room, exportType, exportOptions);
|
super(room, exportType, exportOptions);
|
||||||
|
@ -38,6 +40,10 @@ export default class HTMLExporter extends Exporter {
|
||||||
this.avatars = new Map<string, boolean>();
|
this.avatars = new Map<string, boolean>();
|
||||||
this.matrixClient = MatrixClientPeg.get();
|
this.matrixClient = MatrixClientPeg.get();
|
||||||
this.permalinkCreator = new RoomPermalinkCreator(this.room);
|
this.permalinkCreator = new RoomPermalinkCreator(this.room);
|
||||||
|
this.totalSize = 0;
|
||||||
|
this.mediaOmitText = !this.exportOptions.attachmentsIncluded
|
||||||
|
? _t("Media omitted")
|
||||||
|
: _t("Media omitted - file size limit exceeded");
|
||||||
window.addEventListener("beforeunload", this.onBeforeUnload)
|
window.addEventListener("beforeunload", this.onBeforeUnload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,15 +276,19 @@ export default class HTMLExporter extends Exporter {
|
||||||
if (this.isAttachment(mxEv)) {
|
if (this.isAttachment(mxEv)) {
|
||||||
if (this.exportOptions.attachmentsIncluded) {
|
if (this.exportOptions.attachmentsIncluded) {
|
||||||
const blob = await this.getMediaBlob(mxEv);
|
const blob = await this.getMediaBlob(mxEv);
|
||||||
|
this.totalSize += blob.size;
|
||||||
const filePath = this.getFilePath(mxEv);
|
const filePath = this.getFilePath(mxEv);
|
||||||
eventTile = await this.getEventTile(mxEv, joined, filePath);
|
eventTile = await this.getEventTile(mxEv, joined, filePath);
|
||||||
|
if (this.totalSize > this.exportOptions.maxSize - 1024 * 1024) {
|
||||||
|
this.exportOptions.attachmentsIncluded = false;
|
||||||
|
}
|
||||||
this.zip.file(filePath, blob);
|
this.zip.file(filePath, blob);
|
||||||
} else {
|
} else {
|
||||||
const modifiedContent = {
|
const modifiedContent = {
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
body: "**Media omitted**",
|
body: `**${this.mediaOmitText}**`,
|
||||||
format: "org.matrix.custom.html",
|
format: "org.matrix.custom.html",
|
||||||
formatted_body: "<strong>Media omitted</strong>",
|
formatted_body: `<strong>${this.mediaOmitText}</strong>`,
|
||||||
}
|
}
|
||||||
if (mxEv.isEncrypted()) {
|
if (mxEv.isEncrypted()) {
|
||||||
mxEv._clearEvent.content = modifiedContent;
|
mxEv._clearEvent.content = modifiedContent;
|
||||||
|
|
|
@ -18,6 +18,7 @@ export interface exportOptions {
|
||||||
startDate?: number;
|
startDate?: number;
|
||||||
numberOfMessages?: number;
|
numberOfMessages?: number;
|
||||||
attachmentsIncluded: boolean;
|
attachmentsIncluded: boolean;
|
||||||
|
maxSize: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportConversationalHistory = async (
|
const exportConversationalHistory = async (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue