fix download and download name for tracking document
This commit is contained in:
@@ -57,7 +57,7 @@ export default async function Page({ searchParams }: PageProps) {
|
|||||||
error = 'Не удалось загрузить информацию о документе';
|
error = 'Не удалось загрузить информацию о документе';
|
||||||
}
|
}
|
||||||
|
|
||||||
const documentTitle = title || 'FileName';
|
const documentTitle = response?.fileName || 'FileName';
|
||||||
|
|
||||||
if (error || !response) {
|
if (error || !response) {
|
||||||
return (
|
return (
|
||||||
@@ -132,6 +132,7 @@ export default async function Page({ searchParams }: PageProps) {
|
|||||||
<PdfViewer
|
<PdfViewer
|
||||||
fileId={docid}
|
fileId={docid}
|
||||||
fileName={documentTitle}
|
fileName={documentTitle}
|
||||||
|
showDownload={response.permissions?.DOWNLOAD}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { usePdf } from '@/app/contexts/PdfContext';
|
import { usePdf } from '@/app/contexts/PdfContext';
|
||||||
|
import { requestFileAsBuffer } from '@/app/actions/trackingActions';
|
||||||
|
|
||||||
interface PdfViewerProps {
|
interface PdfViewerProps {
|
||||||
fileId: string;
|
fileId: string;
|
||||||
fileName?: 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 canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [totalPages, setTotalPages] = useState(0);
|
const [totalPages, setTotalPages] = useState(0);
|
||||||
@@ -26,16 +28,17 @@ export default function PdfViewer({ fileId, fileName = 'document.pdf' }: PdfView
|
|||||||
const loadAndDisplayPdf = async () => {
|
const loadAndDisplayPdf = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// 1. Получаем данные документа как ArrayBuffer (а не blob URL)
|
|
||||||
const { requestFileAsBuffer } = await import('@/app/actions/trackingActions');
|
|
||||||
const pdfData = await requestFileAsBuffer(fileId);
|
const pdfData = await requestFileAsBuffer(fileId);
|
||||||
|
|
||||||
if (!pdfData) {
|
if (!pdfData) {
|
||||||
throw new Error('Failed to load document');
|
throw new Error('Failed to load document');
|
||||||
}
|
}
|
||||||
|
|
||||||
setPdfData(pdfData, fileName);
|
//это нужно для скачивания так-как иначе pdfData теряется для скачивания
|
||||||
|
if (showDownload) {
|
||||||
|
const pdfDataForDownload = pdfData.slice(0);
|
||||||
|
setPdfData(pdfDataForDownload, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isMounted) return;
|
if (!isMounted) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user