summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cfg/config.rs2
-rw-r--r--src/main.rs2
-rw-r--r--src/net/http_package.rs21
-rw-r--r--tests/http_funcs.rs7
4 files changed, 18 insertions, 14 deletions
diff --git a/src/cfg/config.rs b/src/cfg/config.rs
index af0def3..521ffcc 100644
--- a/src/cfg/config.rs
+++ b/src/cfg/config.rs
@@ -71,7 +71,7 @@ impl Config {
repo_url: format!("https://mesk.anthrill.i2p/repo/{}/", std::env::consts::ARCH),
auto_update: true,
destination: (String::from("mesk"), String::from("mesk")),
- repo_http_url: None,
+ repo_http_url: format!("http://github.com/Anthrill/repo-mirror/{}", std::env::consts::ARCH).into(),
// Its a hurt place, you need to generate destinations by i2pd and paste here (to mesk.toml)
// Better to leave it empty or set it to (mesk, mesk), now destination conn not implemented
},
diff --git a/src/main.rs b/src/main.rs
index 7010d0b..2cff8d4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -57,7 +57,7 @@ struct RemoteInstallArgs {
#[arg(help = "Install binary package")]
bin: bool,
- #[arg(short = 'h', long = "http")]
+ #[arg(short = 't', long = "http")]
#[arg(help = "Use non-i2p mirror")]
http: bool,
diff --git a/src/net/http_package.rs b/src/net/http_package.rs
index aeff588..92b5ffc 100644
--- a/src/net/http_package.rs
+++ b/src/net/http_package.rs
@@ -40,17 +40,24 @@ impl HTTPPackage {
///
/// Returns an error if the request fails, if the response status is not successful, or if there's an issue while reading or writing the file.
pub async fn fetch_index_http(&mut self) -> Result<bool, Box<dyn std::error::Error>> {
- let repo_url_str = &self.config.repo.repo_url;
+ let repo_url_opt = &self.config.repo.repo_http_url;
let cache_dir = &self.config.paths.cache_dir;
log::debug!("Cache directory: {:?}", cache_dir);
- let index_url = if repo_url_str.ends_with(".tar.gz") {
- repo_url_str.clone()
- } else {
- format!("{}/INDEX.tar.gz", repo_url_str.trim_end_matches('/'))
- };
-
+ let index_url = repo_url_opt.as_deref().map_or_else(
+ || {
+ log::warn!("Repository URL is None, please specify it in /etc/mesk/mesk.toml and restart.");
+ String::new()
+ },
+ |repo_url_str| {
+ if repo_url_str.ends_with(".tar.gz") {
+ repo_url_str.to_string()
+ } else {
+ format!("{}/INDEX.tar.gz", repo_url_str.trim_end_matches('/'))
+ }
+ },
+ );
let client = reqwest::Client::new();
// Make a HEAD request to get the content length for the progress bar
diff --git a/tests/http_funcs.rs b/tests/http_funcs.rs
index 232d3b8..b5b0e5e 100644
--- a/tests/http_funcs.rs
+++ b/tests/http_funcs.rs
@@ -9,16 +9,13 @@ use std::collections::HashMap;
use tempfile::TempDir;
use tokio;
-// Add these imports for logging
-use log::{debug, error, info};
+
+use log::{debug, info};
#[cfg(test)]
mod http_package_tests {
use super::*;
- // Helper function to initialize the logger for each test.
- // This uses `call_once` to ensure it's only initialized once,
- // even if called multiple times, preventing panics.
fn init_logger() {
let _ = env_logger::builder().is_test(true).try_init();
}