From 04ff892e86d447a005278e797d35a192710f9b74 Mon Sep 17 00:00:00 2001 From: smanylov Date: Tue, 10 Mar 2026 10:59:25 +0700 Subject: [PATCH] fix file download for search list --- src/app/ui/search/searched-user-files-list.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/app/ui/search/searched-user-files-list.tsx b/src/app/ui/search/searched-user-files-list.tsx index 0dda379..47165a1 100644 --- a/src/app/ui/search/searched-user-files-list.tsx +++ b/src/app/ui/search/searched-user-files-list.tsx @@ -9,6 +9,7 @@ import { AllowedExtensions } from '@/app/ui/search/section-search-file'; import { FileTypeIcon } from '@/app/components/FileTypeIcon'; import { formatDate, formatDateTime } from '@/app/lib/formatDate'; import { FileInfo } from './file-search-panel'; +import { downloadFile } from '@/app/actions/fileEntity'; export function SearchedUserFilesList({ list, allowedExtensions }: { list: FileInfo[], allowedExtensions: AllowedExtensions }) { const [isFileLoading, setIsFileLoading] = useState(false); @@ -20,17 +21,23 @@ export function SearchedUserFilesList({ list, allowedExtensions }: { list: FileI setIsFileLoading(true); try { - const response = await fetch(`/api/download/${fileId}`); + const result = await downloadFile( + fileId, + fileName || `file-${fileId}` + ); - if (!response.ok) { - throw new Error(`error: ${response.status}`); + const byteCharacters = atob(result.data); + const byteNumbers = new Array(byteCharacters.length); + for (let i = 0; i < byteCharacters.length; i++) { + byteNumbers[i] = byteCharacters.charCodeAt(i) } - const blob = await response.blob(); + const byteArray = new Uint8Array(byteNumbers); + const blob = new Blob([byteArray], { type: result.contentType }); const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; - a.download = fileName || `file-${fileId}`; + a.download = result.fileName; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url);