Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: sequential bulk download with progress to prevent browser blocking
Cursor Agent317cebd4c345
diff --git a/components/datarooms/download-progress-modal.tsx b/components/datarooms/download-progress-modal.tsxindex e21f51db..ef17192b 100644--- a/components/datarooms/download-progress-modal.tsx+++ b/components/datarooms/download-progress-modal.tsx@@ -71,6 +71,11 @@ export function DownloadProgressModal({const [expandedDownloadId, setExpandedDownloadId] = useState<string | null>(null,);+ const [downloadProgress, setDownloadProgress] = useState<{+ downloadId: string;+ current: number;+ total: number;+ } | null>(null);const pollIntervalRef = useRef<NodeJS.Timeout | null>(null);// Cleanup interval on component unmount@@ -252,17 +257,16 @@ export function DownloadProgressModal({}, 100);};- const handleDownloadAll = async (urls: string[]) => {- // Download files sequentially with longer delays to avoid browser blocking- // Browsers typically block rapid automatic downloads as a security measure- console.log("Downloading all files:", urls);+ const handleDownloadAll = async (downloadId: string, urls: string[]) => {+ setDownloadProgress({ downloadId, current: 0, total: urls.length });for (let i = 0; i < urls.length; i++) {+ setDownloadProgress({ downloadId, current: i + 1, total: urls.length });handleDownload(urls[i]);- // Wait 1.5 seconds between downloads to avoid browser blockingif (i < urls.length - 1) {- await new Promise((resolve) => setTimeout(resolve, 1500));+ await new Promise((resolve) => setTimeout(resolve, 2000));}}+ setDownloadProgress(null);};const handleClose = () => {@@ -276,6 +280,7 @@ export function DownloadProgressModal({setShowNewDownload(false);setExistingDownloads([]);setExpandedDownloadId(null);+ setDownloadProgress(null);setLoading(true);onClose();};@@ -421,36 +426,35 @@ export function DownloadProgressModal({</Button>) : (<>- {status.downloadUrls.length <= 3 ? (- <Button- className="w-full"- onClick={() => handleDownloadAll(status.downloadUrls!)}- >- <Download className="mr-2 h-4 w-4" />- Download All ({status.downloadUrls.length} files)- </Button>- ) : (- <p className="text-center text-xs text-muted-foreground">- Your download has been split into{" "}- {status.downloadUrls.length} parts. Download each part- below:- </p>- )}- <div className="space-y-2">- {status.downloadUrls.length <= 3 && (- <p className="text-xs text-muted-foreground">- Or download individually:- </p>+ <Button+ className="w-full"+ disabled={downloadProgress?.downloadId === status.id}+ onClick={() =>+ handleDownloadAll(status.id, status.downloadUrls!)+ }+ >+ {downloadProgress?.downloadId === status.id ? (+ <>+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Downloading {downloadProgress.current} of{" "}+ {downloadProgress.total}...+ </>+ ) : (+ <>+ <Download className="mr-2 h-4 w-4" />+ Download All ({status.downloadUrls.length} parts)+ </>)}+ </Button>+ <div className="space-y-2">+ <p className="text-xs text-muted-foreground">+ Or download individually:+ </p><div className="max-h-48 space-y-1 overflow-y-auto">{status.downloadUrls.map((url, index) => (<Buttonkey={index}- variant={- status.downloadUrls!.length > 3- ? "default"- : "outline"- }+ variant="outline"size="sm"className="w-full justify-start"onClick={() => handleDownload(url)}@@ -603,13 +607,29 @@ export function DownloadProgressModal({<Buttonsize="sm"className="w-full"+ disabled={+ downloadProgress?.downloadId === download.id+ }onClick={() =>- handleDownloadAll(download.downloadUrls!)+ handleDownloadAll(+ download.id,+ download.downloadUrls!,+ )}>- <Download className="mr-2 h-3 w-3" />- Download All ({download.downloadUrls.length}{" "}- parts)+ {downloadProgress?.downloadId === download.id ? (+ <>+ <Loader2 className="mr-2 h-3 w-3 animate-spin" />+ Downloading {downloadProgress.current} of{" "}+ {downloadProgress.total}...+ </>+ ) : (+ <>+ <Download className="mr-2 h-3 w-3" />+ Download All ({download.downloadUrls.length}{" "}+ parts)+ </>+ )}</Button><p className="text-xs text-muted-foreground">Or download individually:diff --git a/components/view/dataroom/downloads-panel.tsx b/components/view/dataroom/downloads-panel.tsxindex c78c8fb8..53575cf5 100644--- a/components/view/dataroom/downloads-panel.tsx+++ b/components/view/dataroom/downloads-panel.tsx@@ -43,6 +43,11 @@ export function DownloadsPanel({ linkId }: { linkId: string }) {const [error, setError] = useState<string | null>(null);const [expandedJobId, setExpandedJobId] = useState<string | null>(null);const [emailSubmitting, setEmailSubmitting] = useState(false);+ const [downloadProgress, setDownloadProgress] = useState<{+ jobId: string;+ current: number;+ total: number;+ } | null>(null);// ── Session check ──────────────────────────────────────────────────const checkSession = useCallback(async () => {@@ -202,10 +207,16 @@ export function DownloadsPanel({ linkId }: { linkId: string }) {setTimeout(() => document.body.removeChild(a), 100);};- const handleDownloadAll = (urls: string[]) => {- urls.forEach((url, i) => {- setTimeout(() => handleDownload(url), i * 300);- });+ const handleDownloadAll = async (jobId: string, urls: string[]) => {+ setDownloadProgress({ jobId, current: 0, total: urls.length });+ for (let i = 0; i < urls.length; i++) {+ setDownloadProgress({ jobId, current: i + 1, total: urls.length });+ handleDownload(urls[i]);+ if (i < urls.length - 1) {+ await new Promise((resolve) => setTimeout(resolve, 2000));+ }+ }+ setDownloadProgress(null);};// ── Formatters ─────────────────────────────────────────────────────@@ -381,12 +392,23 @@ export function DownloadsPanel({ linkId }: { linkId: string }) {<Buttonsize="sm"className="w-full"+ disabled={downloadProgress?.jobId === job.id}onClick={() =>- handleDownloadAll(job.downloadUrls!)+ handleDownloadAll(job.id, job.downloadUrls!)}>- <Download className="mr-2 h-3 w-3" />- Download all ({job.downloadUrls!.length} parts)+ {downloadProgress?.jobId === job.id ? (+ <>+ <Loader2 className="mr-2 h-3 w-3 animate-spin" />+ Downloading {downloadProgress.current} of{" "}+ {downloadProgress.total}...+ </>+ ) : (+ <>+ <Download className="mr-2 h-3 w-3" />+ Download all ({job.downloadUrls!.length} parts)+ </>+ )}</Button><p className="text-xs text-muted-foreground">Or download individually:diff --git a/components/view/dataroom/viewer-download-progress-modal.tsx b/components/view/dataroom/viewer-download-progress-modal.tsxindex 21d971b5..6e1766cb 100644--- a/components/view/dataroom/viewer-download-progress-modal.tsx+++ b/components/view/dataroom/viewer-download-progress-modal.tsx@@ -78,6 +78,10 @@ export function ViewerDownloadProgressModal({const [error, setError] = useState<string | null>(null);const [isStarting, setIsStarting] = useState(false);const [isPolling, setIsPolling] = useState(false);+ const [downloadProgress, setDownloadProgress] = useState<{+ current: number;+ total: number;+ } | null>(null);const pollRef = useRef<NodeJS.Timeout | null>(null);const fetchVerified = useCallback(async () => {@@ -224,10 +228,16 @@ export function ViewerDownloadProgressModal({setTimeout(() => document.body.removeChild(a), 100);};- const handleDownloadAll = (urls: string[]) => {- urls.forEach((url, i) => {- setTimeout(() => handleDownload(url), i * 1500);- });+ const handleDownloadAll = async (urls: string[]) => {+ setDownloadProgress({ current: 0, total: urls.length });+ for (let i = 0; i < urls.length; i++) {+ setDownloadProgress({ current: i + 1, total: urls.length });+ handleDownload(urls[i]);+ if (i < urls.length - 1) {+ await new Promise((resolve) => setTimeout(resolve, 2000));+ }+ }+ setDownloadProgress(null);};const handleClose = () => {@@ -240,6 +250,7 @@ export function ViewerDownloadProgressModal({setStatus(null);setError(null);setIsPolling(false);+ setDownloadProgress(null);onClose();};@@ -364,10 +375,21 @@ export function ViewerDownloadProgressModal({<><ButtonclassName="w-full"+ disabled={!!downloadProgress}onClick={() => handleDownloadAll(status.downloadUrls!)}>- <Download className="mr-2 h-4 w-4" />- Download all ({status.downloadUrls.length} parts)+ {downloadProgress ? (+ <>+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Downloading {downloadProgress.current} of{" "}+ {downloadProgress.total}...+ </>+ ) : (+ <>+ <Download className="mr-2 h-4 w-4" />+ Download all ({status.downloadUrls.length} parts)+ </>+ )}</Button><div className="max-h-32 space-y-1 overflow-y-auto">{status.downloadUrls.map((url, i) => (