(url: string)
| 5 | * Returns null if not a recognized cloud storage URL. |
| 6 | */ |
| 7 | export function detectCloudProvider(url: string): CloudProvider | null { |
| 8 | // Check URI schemes first |
| 9 | if (url.startsWith('s3://')) return 's3'; |
| 10 | if (url.startsWith('gs://')) return 'gcs'; |
| 11 | |
| 12 | try { |
| 13 | const parsed = new URL(url); |
| 14 | const hostname = parsed.hostname.toLowerCase(); |
| 15 | |
| 16 | // AWS S3 patterns |
| 17 | if (hostname.endsWith('.s3.amazonaws.com') || |
| 18 | hostname.includes('.s3.') && hostname.endsWith('.amazonaws.com') || |
| 19 | hostname === 's3.amazonaws.com') { |
| 20 | return 's3'; |
| 21 | } |
| 22 | |
| 23 | // Google Cloud Storage patterns |
| 24 | if (hostname === 'storage.googleapis.com' || |
| 25 | hostname === 'storage.cloud.google.com' || |
| 26 | hostname.endsWith('.storage.googleapis.com')) { |
| 27 | return 'gcs'; |
| 28 | } |
| 29 | |
| 30 | // Cloudflare R2 patterns (*.r2.cloudflarestorage.com or custom domains with r2) |
| 31 | if (hostname.endsWith('.r2.cloudflarestorage.com') || |
| 32 | hostname.endsWith('.r2.dev')) { |
| 33 | return 'r2'; |
| 34 | } |
| 35 | |
| 36 | // Dropbox patterns |
| 37 | if (hostname === 'www.dropbox.com' || |
| 38 | hostname === 'dropbox.com' || |
| 39 | hostname === 'dl.dropboxusercontent.com') { |
| 40 | return 'dropbox'; |
| 41 | } |
| 42 | |
| 43 | return null; |
| 44 | } catch { |
| 45 | return null; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Check if URL appears to be a pre-signed URL (has signature parameters). |
no outgoing calls
no test coverage detected