* Fetch latest download URL for a platform
(platform: string)
| 108 | * Fetch latest download URL for a platform |
| 109 | */ |
| 110 | async function fetchLatestDownloadUrl(platform: string): Promise<string | null> { |
| 111 | try { |
| 112 | let apiPlatform = platform; |
| 113 | let isSystemVersion = false; |
| 114 | |
| 115 | // Handle system version URLs |
| 116 | if (platform.endsWith('-system')) { |
| 117 | apiPlatform = platform.replace('-system', ''); |
| 118 | isSystemVersion = true; |
| 119 | } |
| 120 | |
| 121 | // Simple fetch without complex retry logic |
| 122 | const response = await fetch(`https://www.cursor.com/api/download?platform=${apiPlatform}&releaseTrack=latest`, { |
| 123 | headers: { |
| 124 | 'User-Agent': 'Cursor-Version-Checker', |
| 125 | 'Cache-Control': 'no-cache', |
| 126 | }, |
| 127 | // Keep a reasonable timeout |
| 128 | // timeout: 10000, |
| 129 | }); |
| 130 | |
| 131 | if (!response.ok) { |
| 132 | throw new Error(`HTTP error! status: ${response.status}`); |
| 133 | } |
| 134 | |
| 135 | const data = await response.json() as DownloadResponse; |
| 136 | let downloadUrl = data.downloadUrl; |
| 137 | |
| 138 | if (isSystemVersion) { |
| 139 | downloadUrl = downloadUrl.replace('user-setup/CursorUserSetup', 'system-setup/CursorSetup'); |
| 140 | } |
| 141 | |
| 142 | return downloadUrl; |
| 143 | } catch (error) { |
| 144 | console.error(`Error fetching download URL for platform ${platform}:`, error instanceof Error ? error.message : 'Unknown error'); |
| 145 | return null; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Read version history from JSON file |