mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-14 07:20:02 +03:00
Fetch exportCSS during export
This commit is contained in:
parent
b333612dea
commit
e29d9db2e7
3 changed files with 160 additions and 25448 deletions
|
@ -30,12 +30,12 @@ import * as Avatar from "../../Avatar";
|
||||||
import EventTile, { haveTileForEvent } from "../../components/views/rooms/EventTile";
|
import EventTile, { haveTileForEvent } from "../../components/views/rooms/EventTile";
|
||||||
import DateSeparator from "../../components/views/messages/DateSeparator";
|
import DateSeparator from "../../components/views/messages/DateSeparator";
|
||||||
import BaseAvatar from "../../components/views/avatars/BaseAvatar";
|
import BaseAvatar from "../../components/views/avatars/BaseAvatar";
|
||||||
import exportCSS from "./exportCSS";
|
|
||||||
import exportJS from "!!raw-loader!./exportJS";
|
import exportJS from "!!raw-loader!./exportJS";
|
||||||
import exportIcons from "./exportIcons";
|
import exportIcons from "./exportIcons";
|
||||||
import { ExportTypes } from "./exportUtils";
|
import { ExportTypes } from "./exportUtils";
|
||||||
import { IExportOptions } from "./exportUtils";
|
import { IExportOptions } from "./exportUtils";
|
||||||
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
||||||
|
import getExportCSS from "./exportCSS";
|
||||||
|
|
||||||
export default class HTMLExporter extends Exporter {
|
export default class HTMLExporter extends Exporter {
|
||||||
protected avatars: Map<string, boolean>;
|
protected avatars: Map<string, boolean>;
|
||||||
|
@ -253,12 +253,8 @@ export default class HTMLExporter extends Exporter {
|
||||||
return wantsDateSeparator(prevEvent.getDate(), event.getDate());
|
return wantsDateSeparator(prevEvent.getDate(), event.getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getEventTile(mxEv: MatrixEvent, continuation: boolean, filePath?: string) {
|
public getEventTile(mxEv: MatrixEvent, continuation: boolean) {
|
||||||
const hasAvatar = !!this.getAvatarURL(mxEv);
|
return <div className="mx_Export_EventWrapper" id={mxEv.getId()}>
|
||||||
if (hasAvatar) await this.saveAvatarIfNeeded(mxEv);
|
|
||||||
|
|
||||||
const eventTile = (
|
|
||||||
<div className="mx_Export_EventWrapper" id={mxEv.getId()}>
|
|
||||||
<MatrixClientContext.Provider value={this.client}>
|
<MatrixClientContext.Provider value={this.client}>
|
||||||
<EventTile
|
<EventTile
|
||||||
mxEvent={mxEv}
|
mxEvent={mxEv}
|
||||||
|
@ -283,8 +279,14 @@ export default class HTMLExporter extends Exporter {
|
||||||
showReadReceipts={false}
|
showReadReceipts={false}
|
||||||
/>
|
/>
|
||||||
</MatrixClientContext.Provider>
|
</MatrixClientContext.Provider>
|
||||||
</div>
|
</div>;
|
||||||
);
|
}
|
||||||
|
|
||||||
|
protected async getEventTileMarkup(mxEv: MatrixEvent, continuation: boolean, filePath?: string) {
|
||||||
|
const hasAvatar = !!this.getAvatarURL(mxEv);
|
||||||
|
if (hasAvatar) await this.saveAvatarIfNeeded(mxEv);
|
||||||
|
|
||||||
|
const eventTile = this.getEventTile(mxEv, continuation);
|
||||||
|
|
||||||
let eventTileMarkup = renderToStaticMarkup(eventTile);
|
let eventTileMarkup = renderToStaticMarkup(eventTile);
|
||||||
if (filePath) {
|
if (filePath) {
|
||||||
|
@ -323,14 +325,14 @@ export default class HTMLExporter extends Exporter {
|
||||||
try {
|
try {
|
||||||
const blob = await this.getMediaBlob(mxEv);
|
const blob = await this.getMediaBlob(mxEv);
|
||||||
if (this.totalSize + blob.size > this.exportOptions.maxSize) {
|
if (this.totalSize + blob.size > this.exportOptions.maxSize) {
|
||||||
eventTile = await this.getEventTile(
|
eventTile = await this.getEventTileMarkup(
|
||||||
this.createModifiedEvent(this.mediaOmitText, mxEv),
|
this.createModifiedEvent(this.mediaOmitText, mxEv),
|
||||||
joined,
|
joined,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.totalSize += blob.size;
|
this.totalSize += blob.size;
|
||||||
const filePath = this.getFilePath(mxEv);
|
const filePath = this.getFilePath(mxEv);
|
||||||
eventTile = await this.getEventTile(mxEv, joined, filePath);
|
eventTile = await this.getEventTileMarkup(mxEv, joined, filePath);
|
||||||
if (this.totalSize == this.exportOptions.maxSize) {
|
if (this.totalSize == this.exportOptions.maxSize) {
|
||||||
this.exportOptions.attachmentsIncluded = false;
|
this.exportOptions.attachmentsIncluded = false;
|
||||||
}
|
}
|
||||||
|
@ -338,19 +340,19 @@ export default class HTMLExporter extends Exporter {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Error while fetching file" + e);
|
console.log("Error while fetching file" + e);
|
||||||
eventTile = await this.getEventTile(
|
eventTile = await this.getEventTileMarkup(
|
||||||
this.createModifiedEvent(_t("Error fetching file"), mxEv),
|
this.createModifiedEvent(_t("Error fetching file"), mxEv),
|
||||||
joined,
|
joined,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eventTile = await this.getEventTile(this.createModifiedEvent(this.mediaOmitText, mxEv), joined);
|
eventTile = await this.getEventTileMarkup(this.createModifiedEvent(this.mediaOmitText, mxEv), joined);
|
||||||
}
|
}
|
||||||
} else eventTile = await this.getEventTile(mxEv, joined);
|
} else eventTile = await this.getEventTileMarkup(mxEv, joined);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// TODO: Handle callEvent errors
|
// TODO: Handle callEvent errors
|
||||||
console.error(e);
|
console.error(e);
|
||||||
eventTile = await this.getEventTile(this.createModifiedEvent("Error parsing HTML", mxEv), joined);
|
eventTile = await this.getEventTileMarkup(this.createModifiedEvent("Error parsing HTML", mxEv), joined);
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventTile;
|
return eventTile;
|
||||||
|
@ -388,7 +390,7 @@ export default class HTMLExporter extends Exporter {
|
||||||
|
|
||||||
this.updateProgress("Creating HTML...");
|
this.updateProgress("Creating HTML...");
|
||||||
const html = await this.createHTML(res);
|
const html = await this.createHTML(res);
|
||||||
|
const exportCSS = await getExportCSS();
|
||||||
this.addFile("index.html", new Blob([html]));
|
this.addFile("index.html", new Blob([html]));
|
||||||
this.addFile("css/style.css", new Blob([exportCSS]));
|
this.addFile("css/style.css", new Blob([exportCSS]));
|
||||||
this.addFile("js/script.js", new Blob([exportJS]));
|
this.addFile("js/script.js", new Blob([exportJS]));
|
||||||
|
|
|
@ -42,7 +42,7 @@ export default class PlainTextExporter extends Exporter {
|
||||||
: _t("Media omitted - file size limit exceeded");
|
: _t("Media omitted - file size limit exceeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected textForReplyEvent = (ev: MatrixEvent) => {
|
public textForReplyEvent = (ev: MatrixEvent) => {
|
||||||
const REPLY_REGEX = /> <(.*?)>(.*?)\n\n(.*)/;
|
const REPLY_REGEX = /> <(.*?)>(.*?)\n\n(.*)/;
|
||||||
const REPLY_SOURCE_MAX_LENGTH = 32;
|
const REPLY_SOURCE_MAX_LENGTH = 32;
|
||||||
const content = ev.getContent();
|
const content = ev.getContent();
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue