Verified Commit 2563878b authored by meskio's avatar meskio 🏔️
Browse files

Provide windows7 downloads

It does it in a hacky way trying if there is a 13.5.x download url.

* Closes: #64
parent a538d839
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ platforms = {
    "macos": "macOS",
    "windows-i686": "Windows 32-bit",
    "windows-x86_64": "Windows 64-bit",
    "windows7-i686": "Windows7 32-bit",
    "windows7-x86_64": "Windows7 64-bit",
}


@@ -40,9 +42,29 @@ def latest_onion_browser_urls() -> Tuple[str, str, None, None]:
    raise RuntimeError("The latest release of Onion Browser could not be found.")


def latest_windows7_browser_urls(platform: str) -> Tuple[str, str, str, str]:
    url_base = "https://dist.torproject.org/torbrowser"
    # let's find the latest version the hacky way
    version = None
    for i in range(9, 50):
        if session.get(f"{url_base}/13.5.{i}").status_code == 200:
            version = f"13.5.{i}"
    if version == None:
        raise RuntimeError("The latest release for windows7 could not be found.")

    arch = platform.removeprefix("windows7-")
    file_name = f"tor-browser-windows-{arch}-portable-{version}.exe"
    url = f"{url_base}/{version}/{file_name}"

    return url, file_name, f"{url}.asc", f"{file_name}.asc"


def latest_download_urls(platform: str) -> Tuple[str, str, Optional[str], Optional[str]]:
    if platform == "ios":
        return latest_onion_browser_urls()
    if platform.startswith("windows7-"):
        return latest_windows7_browser_urls(platform)
    
    download = session.get(f"{data['tor']['endpoint']}/download-{platform}.json").json()
    bin_url, sig_url = download["binary"], download["sig"]
    bin_name, sig_name = bin_url.rsplit("/", 1)[-1], sig_url.rsplit("/")[-1]