فهرست منبع

feat: Add detailed logging for file download process to diagnose download issues

Taylor Wilsdon (aider) 4 ماه پیش
والد
کامیت
a865420cb1
1فایلهای تغییر یافته به همراه42 افزوده شده و 9 حذف شده
  1. 42 9
      src/lib/components/chat/Chat.svelte

+ 42 - 9
src/lib/components/chat/Chat.svelte

@@ -391,18 +391,51 @@
 				throw new Error(`Failed to fetch file: ${fileResponse.statusText}`);
 			}
 
+			console.log('Response received, converting to blob...');
 			const fileBlob = await fileResponse.blob();
+			console.log('Blob created:', {
+				size: fileBlob.size,
+				type: fileBlob.type
+			});
+			
 			const file = new File([fileBlob], fileData.name, { type: fileBlob.type });
+			console.log('File object created:', {
+				name: file.name,
+				size: file.size,
+				type: file.type
+			});
 
-			// Create a download link for debugging
-			const downloadUrl = URL.createObjectURL(fileBlob);
-			const downloadLink = document.createElement('a');
-			downloadLink.href = downloadUrl;
-			downloadLink.download = fileData.name;
-			document.body.appendChild(downloadLink);
-			downloadLink.click();
-			document.body.removeChild(downloadLink);
-			URL.revokeObjectURL(downloadUrl);
+			// Create and trigger download
+			try {
+				console.log('Creating download URL...');
+				const downloadUrl = URL.createObjectURL(fileBlob);
+				console.log('Download URL created:', downloadUrl);
+				
+				const downloadLink = document.createElement('a');
+				downloadLink.href = downloadUrl;
+				downloadLink.download = fileData.name;
+				console.log('Download link created with:', {
+					href: downloadLink.href,
+					download: downloadLink.download
+				});
+				
+				// Force the download to happen in the foreground
+				downloadLink.style.display = 'none';
+				document.body.appendChild(downloadLink);
+				console.log('Link added to document');
+				
+				downloadLink.click();
+				console.log('Download triggered');
+				
+				// Cleanup
+				setTimeout(() => {
+					document.body.removeChild(downloadLink);
+					URL.revokeObjectURL(downloadUrl);
+					console.log('Cleanup completed');
+				}, 100);
+			} catch (error) {
+				console.error('Download failed:', error);
+			}
 
 			console.log('File fetched successfully, uploading to server...');
 			const uploadedFile = await uploadFile(localStorage.token, file);