|
524 | 524 |
|
525 | 525 | // Google Drive: convert /view to direct download |
526 | 526 | // Format: https://drive.google.com/file/d/FILE_ID/view?usp=sharing |
527 | | - // Convert to: https://drive.google.com/uc?export=download&id=FILE_ID |
| 527 | + // Convert to: https://drive.usercontent.google.com/download?id=FILE_ID&export=download&confirm=t |
| 528 | + // Note: drive.usercontent.google.com is Google's dedicated download domain |
| 529 | + // The confirm=t parameter bypasses the virus scan warning for large files |
528 | 530 | if (urlObj.hostname === 'drive.google.com') { |
529 | 531 | const match = url.match(/\/file\/d\/([^/]+)/); |
530 | 532 | if (match && match[1]) { |
531 | 533 | const fileId = match[1]; |
532 | | - return `https://drive.google.com/uc?export=download&id=${fileId}`; |
| 534 | + return `https://drive.usercontent.google.com/download?id=${fileId}&export=download&confirm=t`; |
533 | 535 | } |
534 | 536 | } |
535 | 537 |
|
|
662 | 664 | const downloadUrl = convertToDirectDownloadUrl(url.trim()); |
663 | 665 | console.log('[App] Downloading from:', downloadUrl); |
664 | 666 |
|
| 667 | + // Check if this is a Google Drive URL |
| 668 | + // Google Drive blocks CORS and public proxies, so we only try direct fetch |
| 669 | + const isGoogleDrive = url.includes('drive.google.com') || url.includes('drive.usercontent.google.com'); |
| 670 | + |
665 | 671 | let response; |
666 | 672 | let usedProxy = false; |
667 | 673 |
|
668 | | - // Try direct fetch first, then fallback to CORS proxy |
| 674 | + // Try direct fetch first, then fallback to CORS proxy (except for Google Drive) |
669 | 675 | try { |
670 | 676 | response = await fetchWithCorsProxy(downloadUrl, false); |
671 | 677 | if (!response.ok) { |
672 | 678 | throw new Error('Direct fetch failed'); |
673 | 679 | } |
674 | 680 | } catch (directError) { |
| 681 | + // For Google Drive, don't try proxies - they are blocked |
| 682 | + // Show specific error message immediately |
| 683 | + if (isGoogleDrive) { |
| 684 | + throw new Error('GOOGLE_DRIVE_BLOCKED'); |
| 685 | + } |
| 686 | + |
675 | 687 | console.log('[App] Direct fetch failed, trying CORS proxy...'); |
676 | 688 | usedProxy = true; |
677 | 689 | response = await fetchWithCorsProxy(downloadUrl, true); |
|
758 | 770 | } catch (error) { |
759 | 771 | console.error('[App] Error downloading from URL:', error); |
760 | 772 |
|
761 | | - // Handle network errors |
762 | | - if (error.name === 'TypeError' && error.message.includes('fetch')) { |
| 773 | + if (error.message === 'GOOGLE_DRIVE_BLOCKED') { |
| 774 | + // Google Drive blocks CORS and public proxies, suggest manual download |
| 775 | + showError(i18n.t('errors.googleDriveBlocked')); |
| 776 | + } else if (error.name === 'TypeError' && error.message.includes('fetch')) { |
| 777 | + // Handle network errors |
763 | 778 | showError(i18n.t('errors.networkError')); |
764 | 779 | } else { |
765 | 780 | showError(error.message || i18n.t('errors.downloadFailed')); |
|
0 commit comments