Skip to content

Commit

Permalink
fix: Fix download button
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowRZ committed Sep 9, 2024
1 parent 4dfce32 commit 719f4d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/app/components/Pdf-viewer/PdfViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { AsyncStatus } from '../../hooks/useAsyncCallback';
import { useZoom } from '../../hooks/useZoom';
import { createPage, usePdfDocumentLoader, usePdfJSLoader } from '../../plugins/pdfjs-dist';
import { stopPropagation } from '../../utils/keyboard';
import { getSrcFile } from '../message/content/util';

export type PdfViewerProps = {
name: string;
Expand Down Expand Up @@ -78,7 +79,9 @@ export const PdfViewer = as<'div', PdfViewerProps>(
}, [docState, pageNo, zoom]);

const handleDownload = () => {
FileSaver.saveAs(src, name);
getSrcFile(src).then((blob) => {
FileSaver.saveAs(blob, name);
});
};

const handleJumpSubmit: FormEventHandler<HTMLFormElement> = (evt) => {
Expand Down
5 changes: 4 additions & 1 deletion src/app/components/image-viewer/ImageViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Box, Chip, Header, Icon, IconButton, Icons, Text, as } from 'folds';
import * as css from './ImageViewer.css';
import { useZoom } from '../../hooks/useZoom';
import { usePan } from '../../hooks/usePan';
import { getSrcFile } from '../message/content/util';

export type ImageViewerProps = {
alt: string;
Expand All @@ -19,7 +20,9 @@ export const ImageViewer = as<'div', ImageViewerProps>(
const { pan, cursor, onMouseDown } = usePan(zoom !== 1);

const handleDownload = () => {
FileSaver.saveAs(src, alt);
getSrcFile(src).then((blob) => {
FileSaver.saveAs(blob, alt);
});
};

return (
Expand Down
15 changes: 12 additions & 3 deletions src/app/components/message/content/FileContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ export function ReadPdfFile({ body, mimeType, url, encInfo, renderViewer }: Read

const [pdfState, loadPdf] = useAsyncCallback(
useCallback(async () => {
const httpUrl = await getFileSrcUrl(mxcUrlToHttp(mx, url, useAuthentication) ?? '', mimeType, encInfo);
const httpUrl = await getFileSrcUrl(
mxcUrlToHttp(mx, url, useAuthentication) ?? '',
mimeType,
encInfo
);
setPdfViewer(true);
return httpUrl;
}, [mx, url, useAuthentication, mimeType, encInfo])
Expand Down Expand Up @@ -251,8 +255,13 @@ export function DownloadFile({ body, mimeType, url, info, encInfo }: DownloadFil

const [downloadState, download] = useAsyncCallback(
useCallback(async () => {
const httpUrl = await getFileSrcUrl(mxcUrlToHttp(mx, url, useAuthentication) ?? '', mimeType, encInfo);
FileSaver.saveAs(httpUrl, body);
const httpUrl = await getFileSrcUrl(
mxcUrlToHttp(mx, url, useAuthentication) ?? '',
mimeType,
encInfo
);
const httpSrc = httpUrl.startsWith('blob') ? httpUrl : await getSrcFile(httpUrl);
FileSaver.saveAs(httpSrc, body);
return httpUrl;
}, [mx, url, useAuthentication, mimeType, encInfo, body])
);
Expand Down

0 comments on commit 719f4d7

Please sign in to comment.