diff --git a/crates/cli/src/update.rs b/crates/cli/src/update.rs index 9205c899..5b1dce53 100644 --- a/crates/cli/src/update.rs +++ b/crates/cli/src/update.rs @@ -15,8 +15,12 @@ const CHECKSUM_MANIFEST_ASSET: &str = "codewhale-artifacts-sha256.txt"; const LATEST_RELEASE_URL: &str = "https://api.github.com/repos/Hmbown/CodeWhale/releases/latest"; const RELEASES_URL: &str = "https://api.github.com/repos/Hmbown/CodeWhale/releases?per_page=100"; const CNB_REPO_URL: &str = "https://cnb.cool/codewhale.net/codewhale"; -const RELEASE_BASE_URL_ENV: &str = "DEEPSEEK_TUI_RELEASE_BASE_URL"; -const LEGACY_RELEASE_BASE_URL_ENV: &str = "DEEPSEEK_RELEASE_BASE_URL"; +const RELEASE_BASE_URL_ENV: &str = "CODEWHALE_RELEASE_BASE_URL"; +const LEGACY_RELEASE_BASE_URL_ENV: &str = "DEEPSEEK_TUI_RELEASE_BASE_URL"; +const DEEPSEEK_RELEASE_BASE_URL_ENV: &str = "DEEPSEEK_RELEASE_BASE_URL"; +const CNB_MIRROR_ENV: &str = "CODEWHALE_USE_CNB_MIRROR"; +/// Base URL for CNB binary release asset downloads (China-friendly mirror). +const CNB_RELEASE_ASSET_BASE: &str = "https://cnb.cool/Hmbown/CodeWhale/-/releases"; const UPDATE_VERSION_ENV: &str = "DEEPSEEK_TUI_VERSION"; const LEGACY_UPDATE_VERSION_ENV: &str = "DEEPSEEK_VERSION"; const UPDATE_USER_AGENT: &str = "codewhale-updater"; @@ -370,11 +374,24 @@ fn fetch_latest_release(channel: ReleaseChannel) -> Result { } fn release_base_url_from_env() -> Option { - std::env::var(RELEASE_BASE_URL_ENV) - .ok() - .or_else(|| std::env::var(LEGACY_RELEASE_BASE_URL_ENV).ok()) - .map(|value| value.trim().to_string()) - .filter(|value| !value.is_empty()) + // Check canonical env first, then legacy envs + for env_name in [ + RELEASE_BASE_URL_ENV, + LEGACY_RELEASE_BASE_URL_ENV, + DEEPSEEK_RELEASE_BASE_URL_ENV, + ] { + if let Ok(value) = std::env::var(env_name) { + let trimmed = value.trim().to_string(); + if !trimmed.is_empty() { + return Some(trimmed); + } + } + } + // Auto-detect CNB mirror when CODEWHALE_USE_CNB_MIRROR is set + if std::env::var(CNB_MIRROR_ENV).is_ok() { + return Some(CNB_RELEASE_ASSET_BASE.to_string()); + } + None } fn update_version_from_env() -> Option { diff --git a/npm/codewhale/scripts/artifacts.js b/npm/codewhale/scripts/artifacts.js index 27117b0c..10645404 100644 --- a/npm/codewhale/scripts/artifacts.js +++ b/npm/codewhale/scripts/artifacts.js @@ -78,12 +78,21 @@ function executableName(base, platform) { } function releaseBaseUrl(version, repo = "Hmbown/CodeWhale") { + // CODEWHALE_RELEASE_BASE_URL is the canonical override. + // DEEPSEEK_TUI_RELEASE_BASE_URL / DEEPSEEK_RELEASE_BASE_URL are legacy aliases. const override = - process.env.DEEPSEEK_TUI_RELEASE_BASE_URL || process.env.DEEPSEEK_RELEASE_BASE_URL; + process.env.CODEWHALE_RELEASE_BASE_URL || + process.env.DEEPSEEK_TUI_RELEASE_BASE_URL || + process.env.DEEPSEEK_RELEASE_BASE_URL; if (override) { const trimmed = String(override).trim(); return trimmed.endsWith("/") ? trimmed : `${trimmed}/`; } + // When CODEWHALE_USE_CNB_MIRROR is set, use the CNB (China-friendly) + // mirror that already builds and publishes binary release assets. + if (process.env.CODEWHALE_USE_CNB_MIRROR) { + return `https://cnb.cool/Hmbown/CodeWhale/-/releases/v${version}/`; + } return `https://github.com/${repo}/releases/download/v${version}/`; }