Apply PR Suggestions
This commit is contained in:
parent
d32f945e24
commit
edfc8af6cf
8 changed files with 143 additions and 144 deletions
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
||||
import { IExportOptions, ExportTypes } from "./exportUtils";
|
||||
import { IExportOptions, ExportType } from "./exportUtils";
|
||||
import { decryptFile } from "../DecryptFile";
|
||||
import { mediaFromContent } from "../../customisations/Media";
|
||||
import { formatFullDateNoDay } from "../../DateUtils";
|
||||
|
@ -38,13 +38,14 @@ export default abstract class Exporter {
|
|||
|
||||
protected constructor(
|
||||
protected room: Room,
|
||||
protected exportType: ExportTypes,
|
||||
protected exportType: ExportType,
|
||||
protected exportOptions: IExportOptions,
|
||||
protected exportProgressRef: MutableRefObject<HTMLParagraphElement>,
|
||||
) {
|
||||
if (exportOptions.maxSize < 1 * 1024 * 1024||
|
||||
exportOptions.maxSize > 2000 * 1024 * 1024||
|
||||
exportOptions.numberOfMessages > 10**8) {
|
||||
if (exportOptions.maxSize < 1 * 1024 * 1024|| // Less than 1 MB
|
||||
exportOptions.maxSize > 2000 * 1024 * 1024|| // More than ~ 2 GB
|
||||
exportOptions.numberOfMessages > 10**8
|
||||
) {
|
||||
throw new Error("Invalid export options");
|
||||
}
|
||||
this.cancelled = false;
|
||||
|
@ -118,10 +119,10 @@ export default abstract class Exporter {
|
|||
public getLimit(): number {
|
||||
let limit: number;
|
||||
switch (this.exportType) {
|
||||
case ExportTypes.LAST_N_MESSAGES:
|
||||
case ExportType.LastNMessages:
|
||||
limit = this.exportOptions.numberOfMessages;
|
||||
break;
|
||||
case ExportTypes.TIMELINE:
|
||||
case ExportType.Timeline:
|
||||
limit = 40;
|
||||
break;
|
||||
default:
|
||||
|
@ -166,7 +167,7 @@ export default abstract class Exporter {
|
|||
events.push(mxEv);
|
||||
}
|
||||
this.updateProgress(
|
||||
("Fetched " + events.length + " events ") + (this.exportType === ExportTypes.LAST_N_MESSAGES
|
||||
("Fetched " + events.length + " events ") + (this.exportType === ExportType.LastNMessages
|
||||
? `out of ${this.exportOptions.numberOfMessages}`
|
||||
: "so far"),
|
||||
);
|
||||
|
|
|
@ -32,7 +32,7 @@ import DateSeparator from "../../components/views/messages/DateSeparator";
|
|||
import BaseAvatar from "../../components/views/avatars/BaseAvatar";
|
||||
import exportJS from "!!raw-loader!./exportJS";
|
||||
import exportIcons from "./exportIcons";
|
||||
import { ExportTypes } from "./exportUtils";
|
||||
import { ExportType } from "./exportUtils";
|
||||
import { IExportOptions } from "./exportUtils";
|
||||
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
||||
import getExportCSS from "./exportCSS";
|
||||
|
@ -46,7 +46,7 @@ export default class HTMLExporter extends Exporter {
|
|||
|
||||
constructor(
|
||||
room: Room,
|
||||
exportType: ExportTypes,
|
||||
exportType: ExportType,
|
||||
exportOptions: IExportOptions,
|
||||
exportProgressRef: MutableRefObject<HTMLParagraphElement>,
|
||||
) {
|
||||
|
|
|
@ -19,24 +19,22 @@ import { Room } from "matrix-js-sdk/src/models/room";
|
|||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { formatFullDateNoDay, formatFullDateNoDayNoTime } from "../../DateUtils";
|
||||
import { haveTileForEvent } from "../../components/views/rooms/EventTile";
|
||||
import { ExportTypes } from "./exportUtils";
|
||||
import { ExportType } from "./exportUtils";
|
||||
import { IExportOptions } from "./exportUtils";
|
||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||
import { MutableRefObject } from "react";
|
||||
|
||||
export default class JSONExporter extends Exporter {
|
||||
protected totalSize: number;
|
||||
protected messages: any[];
|
||||
protected totalSize = 0;
|
||||
protected messages: any[] = [];
|
||||
|
||||
constructor(
|
||||
room: Room,
|
||||
exportType: ExportTypes,
|
||||
exportType: ExportType,
|
||||
exportOptions: IExportOptions,
|
||||
exportProgressRef: MutableRefObject<HTMLParagraphElement>,
|
||||
) {
|
||||
super(room, exportType, exportOptions, exportProgressRef);
|
||||
this.totalSize = 0;
|
||||
this.messages = [];
|
||||
}
|
||||
|
||||
protected createJSONString(): string {
|
||||
|
|
|
@ -20,7 +20,7 @@ import { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event";
|
|||
import { formatFullDateNoDay } from "../../DateUtils";
|
||||
import { _t } from "../../languageHandler";
|
||||
import { haveTileForEvent } from "../../components/views/rooms/EventTile";
|
||||
import { ExportTypes } from "./exportUtils";
|
||||
import { ExportType } from "./exportUtils";
|
||||
import { IExportOptions } from "./exportUtils";
|
||||
import { textForEvent } from "../../TextForEvent";
|
||||
import { MutableRefObject } from "react";
|
||||
|
@ -31,7 +31,7 @@ export default class PlainTextExporter extends Exporter {
|
|||
|
||||
constructor(
|
||||
room: Room,
|
||||
exportType: ExportTypes,
|
||||
exportType: ExportType,
|
||||
exportOptions: IExportOptions,
|
||||
exportProgressRef: MutableRefObject<HTMLParagraphElement>,
|
||||
) {
|
||||
|
|
|
@ -16,26 +16,26 @@ limitations under the License.
|
|||
|
||||
import { _t } from "../../languageHandler";
|
||||
|
||||
export enum ExportFormats {
|
||||
HTML = "HTML",
|
||||
PLAIN_TEXT = "PLAIN_TEXT",
|
||||
JSON = "JSON",
|
||||
export enum ExportFormat {
|
||||
Html = "HTML",
|
||||
PlainText = "PLAIN_TEXT",
|
||||
Json = "JSON",
|
||||
}
|
||||
|
||||
export enum ExportTypes {
|
||||
TIMELINE = "TIMELINE",
|
||||
BEGINNING = "BEGINNING",
|
||||
LAST_N_MESSAGES = "LAST_N_MESSAGES",
|
||||
export enum ExportType {
|
||||
Timeline = "TIMELINE",
|
||||
Beginning = "BEGINNING",
|
||||
LastNMessages = "LAST_N_MESSAGES",
|
||||
// START_DATE = "START_DATE",
|
||||
}
|
||||
|
||||
export const textForFormat = (format: string): string => {
|
||||
switch (format) {
|
||||
case ExportFormats.HTML:
|
||||
case ExportFormat.Html:
|
||||
return _t("HTML");
|
||||
case ExportFormats.JSON:
|
||||
case ExportFormat.Json:
|
||||
return _t("JSON");
|
||||
case ExportFormats.PLAIN_TEXT:
|
||||
case ExportFormat.PlainText:
|
||||
return _t("Plain Text");
|
||||
default:
|
||||
throw new Error("Unknown format");
|
||||
|
@ -44,11 +44,11 @@ export const textForFormat = (format: string): string => {
|
|||
|
||||
export const textForType = (type: string): string => {
|
||||
switch (type) {
|
||||
case ExportTypes.BEGINNING:
|
||||
case ExportType.Beginning:
|
||||
return _t("From the beginning");
|
||||
case ExportTypes.LAST_N_MESSAGES:
|
||||
case ExportType.LastNMessages:
|
||||
return _t("Specify a number of messages");
|
||||
case ExportTypes.TIMELINE:
|
||||
case ExportType.Timeline:
|
||||
return _t("Current Timeline");
|
||||
default:
|
||||
throw new Error("Unknown type: " + type);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue