fix download and download name for tracking document

This commit is contained in:
smanylov
2026-05-05 16:01:08 +07:00
parent ae0526a58a
commit e97dd392c0
2 changed files with 10 additions and 6 deletions
+2 -1
View File
@@ -57,7 +57,7 @@ export default async function Page({ searchParams }: PageProps) {
error = 'Не удалось загрузить информацию о документе';
}
const documentTitle = title || 'FileName';
const documentTitle = response?.fileName || 'FileName';
if (error || !response) {
return (
@@ -132,6 +132,7 @@ export default async function Page({ searchParams }: PageProps) {
<PdfViewer
fileId={docid}
fileName={documentTitle}
showDownload={response.permissions?.DOWNLOAD}
/>
</div>
</div>
+8 -5
View File
@@ -2,13 +2,15 @@
import { useEffect, useRef, useState } from 'react';
import { usePdf } from '@/app/contexts/PdfContext';
import { requestFileAsBuffer } from '@/app/actions/trackingActions';
interface PdfViewerProps {
fileId: string;
fileName?: string;
showDownload?: boolean;
}
export default function PdfViewer({ fileId, fileName = 'document.pdf' }: PdfViewerProps) {
export default function PdfViewer({ fileId, fileName = 'document.pdf', showDownload }: PdfViewerProps) {
const canvasRef = useRef<HTMLCanvasElement>(null);
const [currentPage, setCurrentPage] = useState(1);
const [totalPages, setTotalPages] = useState(0);
@@ -26,16 +28,17 @@ export default function PdfViewer({ fileId, fileName = 'document.pdf' }: PdfView
const loadAndDisplayPdf = async () => {
try {
setLoading(true);
// 1. Получаем данные документа как ArrayBuffer (а не blob URL)
const { requestFileAsBuffer } = await import('@/app/actions/trackingActions');
const pdfData = await requestFileAsBuffer(fileId);
if (!pdfData) {
throw new Error('Failed to load document');
}
setPdfData(pdfData, fileName);
//это нужно для скачивания так-как иначе pdfData теряется для скачивания
if (showDownload) {
const pdfDataForDownload = pdfData.slice(0);
setPdfData(pdfDataForDownload, fileName);
}
if (!isMounted) return;