mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 12:03:46 +00:00 
			
		
		
		
	Leave the Intel build as the prominent default, since it will run on both platforms. (I would have liked to detect the appropriate platform, but Apple seems to have put significant effort into making that impossible for anti-fingerprinting reasons, which is probably an overall good.) Signed-off-by: Anders Kaseorg <anders@zulip.com>
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| import json
 | |
| import logging
 | |
| 
 | |
| import requests
 | |
| 
 | |
| from zerver.lib.cache import cache_with_key
 | |
| 
 | |
| logger = logging.getLogger(__name__)
 | |
| 
 | |
| 
 | |
| def get_latest_github_release_version_for_repo(repo: str) -> str:
 | |
|     api_url = f"https://api.github.com/repos/zulip/{repo}/releases/latest"
 | |
|     try:
 | |
|         return requests.get(api_url).json()["tag_name"]
 | |
|     except (requests.RequestException, json.JSONDecodeError, KeyError):
 | |
|         logger.error("Unable to fetch the latest release version from GitHub %s", api_url)
 | |
|         return ""
 | |
| 
 | |
| 
 | |
| def verify_release_download_link(link: str) -> bool:
 | |
|     try:
 | |
|         requests.head(link).raise_for_status()
 | |
|         return True
 | |
|     except requests.RequestException:
 | |
|         logger.error("App download link is broken %s", link)
 | |
|         return False
 | |
| 
 | |
| 
 | |
| PLATFORM_TO_SETUP_FILE = {
 | |
|     "linux": "Zulip-{version}-x86_64.AppImage",
 | |
|     "mac": "Zulip-{version}.dmg",
 | |
|     "mac-arm64": "Zulip-{version}-arm64.dmg",
 | |
|     "windows": "Zulip-Web-Setup-{version}.exe",
 | |
| }
 | |
| 
 | |
| 
 | |
| class InvalidPlatform(Exception):
 | |
|     pass
 | |
| 
 | |
| 
 | |
| @cache_with_key(lambda platform: f"download_link:{platform}", timeout=60 * 30)
 | |
| def get_latest_github_release_download_link_for_platform(platform: str) -> str:
 | |
|     if platform not in PLATFORM_TO_SETUP_FILE:
 | |
|         raise InvalidPlatform()
 | |
| 
 | |
|     latest_version = get_latest_github_release_version_for_repo("zulip-desktop")
 | |
|     if latest_version:
 | |
|         if latest_version[0] in ["v", "V"]:
 | |
|             latest_version = latest_version[1:]
 | |
|         setup_file = PLATFORM_TO_SETUP_FILE[platform].format(version=latest_version)
 | |
|         link = f"https://github.com/zulip/zulip-desktop/releases/download/v{latest_version}/{setup_file}"
 | |
|         if verify_release_download_link(link):
 | |
|             return link
 | |
|     return "https://github.com/zulip/zulip-desktop/releases/latest"
 |