/* Copyright 2024 New Vector Ltd. Copyright 2019-2021 The Matrix.org Foundation C.I.C. Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE files in the repository root for full details. */ import React, { type JSX } from "react"; import { FilesIcon } from "@vector-im/compound-design-tokens/assets/web/icons"; import { _t } from "../../../languageHandler"; import BaseDialog from "./BaseDialog"; import DialogButtons from "../elements/DialogButtons"; import { fileSize } from "../../../utils/FileUtils"; interface IProps { file: File; currentIndex: number; totalFiles: number; onFinished: (uploadConfirmed: boolean, uploadAll?: boolean) => void; } interface IState { objectUrl?: string; } export default class UploadConfirmDialog extends React.Component { public static defaultProps: Partial = { totalFiles: 1, currentIndex: 0, }; public constructor(props: IProps) { super(props); this.state = {}; } public componentDidMount(): void { if (this.props.file.type.startsWith("image/") || this.props.file.type.startsWith("video/")) { this.setState({ // We do not filter the mimetype using getBlobSafeMimeType here as if the user is uploading the file // themselves they should be trusting it enough to open/load it, and it will be rendered into a hidden // canvas for thumbnail generation anyway objectUrl: URL.createObjectURL(this.props.file), }); } } public componentWillUnmount(): void { if (this.state.objectUrl) URL.revokeObjectURL(this.state.objectUrl); } private onCancelClick = (): void => { this.props.onFinished(false); }; private onUploadClick = (): void => { this.props.onFinished(true); }; private onUploadAllClick = (): void => { this.props.onFinished(true, true); }; public render(): React.ReactNode { let title: string; if (this.props.totalFiles > 1 && this.props.currentIndex !== undefined) { title = _t("upload_file|title_progress", { current: this.props.currentIndex + 1, total: this.props.totalFiles, }); } else { title = _t("upload_file|title"); } const fileId = `mx-uploadconfirmdialog-${this.props.file.name}`; const mimeType = this.props.file.type; let preview: JSX.Element | undefined; let placeholder: JSX.Element | undefined; if (mimeType.startsWith("image/")) { preview = ( ); } else if (mimeType.startsWith("video/")) { preview = (