Skip to content

Commit

Permalink
feat(moonup): support MOONUP_TOOLCHAIN_INDEX configuration
Browse files Browse the repository at this point in the history
to configure the toolchain index url.

Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
  • Loading branch information
chawyehsu committed Oct 18, 2024
1 parent 96b5d93 commit ece4859
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub const MOON_DIR: &str = ".moon";
/// The default MoonUp home directory is `~/.moonup`
pub const MOONUP_DIR: &str = ".moonup";

/// The URL of the MoonBit release index
pub const INDEX_URL: &str = "https://chawyehsu.github.io/moonbit-binaries/index.json";
/// The index URL of MoonBit releases
pub const TOOLCHAIN_INDEX: &str = "https://moonup.csu.moe/index.json";

/// The expiration time for the release index, in hours
pub const INDEX_EXPIRATION: i64 = 2;
Expand Down
10 changes: 8 additions & 2 deletions src/toolchain/index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chrono::{DateTime, Duration, Local};
use miette::IntoDiagnostic;
use miette::{Context, IntoDiagnostic};
use serde::Deserialize;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use url::Url;
Expand Down Expand Up @@ -87,7 +87,13 @@ async fn retrieve_index() -> miette::Result<Index> {
}

let client = build_http_client();
let url = Url::parse(crate::constant::INDEX_URL).into_diagnostic()?;
let url = Url::parse(
std::env::var("MOONUP_TOOLCHAIN_INDEX")
.as_deref()
.unwrap_or(crate::constant::TOOLCHAIN_INDEX),
)
.into_diagnostic()
.wrap_err("Invalid MOONUP_TOOLCHAIN_INDEX string, should be a valid URL")?;

let mut reader = url_to_reader(url, client, None).await?;
let mut content = String::new();
Expand Down

0 comments on commit ece4859

Please sign in to comment.