From b15bfca8d1a0b75c229cd5bd7db3ea488e871ded Mon Sep 17 00:00:00 2001 From: james58899 Date: Tue, 17 Dec 2024 08:41:22 +0000 Subject: [PATCH] Format --- rustfmt.toml | 1 + src/cache_manager.rs | 25 ++++-------------------- src/main.rs | 39 +++++++++++-------------------------- src/route/server_command.rs | 18 +++-------------- src/rpc.rs | 11 ++--------- 5 files changed, 21 insertions(+), 73 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 863bf10..6bfd72d 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,6 +1,7 @@ group_imports = "StdExternalCrate" imports_granularity = "Crate" max_width = 140 +fn_call_width = 140 overflow_delimited_expr = true reorder_impl_items = true use_field_init_shorthand = true diff --git a/src/cache_manager.rs b/src/cache_manager.rs index 1c53781..da35036 100644 --- a/src/cache_manager.rs +++ b/src/cache_manager.rs @@ -123,11 +123,7 @@ impl CacheManager { // Check file exists if !metadata.is_file() || metadata.len() != info.size() as u64 { - warn!( - "Unexcepted cache file metadata: type={:?}, size={}", - metadata.file_type(), - metadata.len() - ); + warn!("Unexcepted cache file metadata: type={:?}, size={}", metadata.file_type(), metadata.len()); return None; } @@ -169,12 +165,7 @@ impl CacheManager { let hash: [u8; 20] = hasher.finalize().into(); if hash != info.hash() { - warn!( - "Delete corrupt cache file: path={:?}, hash={:x?}, actual={:x?}", - &path, - info.hash(), - hash - ); + warn!("Delete corrupt cache file: path={:?}, hash={:x?}, actual={:x?}", &path, info.hash(), hash); cache_manager.remove_cache(&info).await; } }); @@ -339,12 +330,7 @@ impl CacheManager { let size = metadata.len(); if size != info.size() as u64 { - warn!( - "Delete corrupt cache file: path={:?}, size={:x?}, actual={:x?}", - &path, - &info.size(), - size - ); + warn!("Delete corrupt cache file: path={:?}, size={:x?}, actual={:x?}", &path, &info.size(), size); if let Err(err) = remove_file(&path).await { error!("Delete corrupt cache file error: path={:?}, err={}", &path, err); @@ -409,10 +395,7 @@ impl CacheManager { } let actual_hash: [u8; 20] = hasher.finalize().into(); if actual_hash != info.hash { - warn!( - "Delete corrupt cache file: path={:?}, hash={:x?}, actual={:x?}", - path, &info.hash, &actual_hash - ); + warn!("Delete corrupt cache file: path={:?}, hash={:x?}, actual={:x?}", path, &info.hash, &actual_hash); if let Err(err) = remove_file(&path).await { error!("Delete corrupt cache file error: path={:?}, err={}", path, err); } diff --git a/src/main.rs b/src/main.rs index da57e64..d385e1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,14 +163,7 @@ async fn main() -> Result<(), Box> { } let args = args.unwrap(); - create_dirs(vec![ - &args.data_dir, - &args.cache_dir, - &args.log_dir, - &args.temp_dir, - &args.download_dir, - ]) - .await?; + create_dirs(vec![&args.data_dir, &args.cache_dir, &args.log_dir, &args.temp_dir, &args.download_dir]).await?; // Init logger let mut logger = Logger::init(args.log_dir).unwrap(); @@ -186,13 +179,7 @@ async fn main() -> Result<(), Box> { Some(i) => i, None => setup(&args.data_dir).await?, }; - let client = Arc::new(RPCClient::new( - id, - &key, - args.disable_ip_origin_check, - args.max_connection, - args.rpc_server_ip.as_deref(), - )); + let client = Arc::new(RPCClient::new(id, &key, args.disable_ip_origin_check, args.max_connection, args.rpc_server_ip.as_deref())); let init_settings = client.login().await?; let (shutdown_send, shutdown_recv) = mpsc::unbounded_channel::<()>(); @@ -226,19 +213,15 @@ async fn main() -> Result<(), Box> { let (tx, mut rx) = mpsc::channel::(1); info!("Starting HTTP server..."); - let server = Server::new( - args.port.unwrap_or_else(|| init_settings.client_port()), - client.get_cert().await.unwrap(), - AppState { - runtime: Handle::current(), - reqwest: create_http_client(Duration::from_secs(30), proxy.clone()), - rpc: client.clone(), - download_state: Default::default(), - cache_manager: cache_manager.clone(), - command_channel: tx.clone(), - has_proxy, - }, - ); + let server = Server::new(args.port.unwrap_or_else(|| init_settings.client_port()), client.get_cert().await.unwrap(), AppState { + runtime: Handle::current(), + reqwest: create_http_client(Duration::from_secs(30), proxy.clone()), + rpc: client.clone(), + download_state: Default::default(), + cache_manager: cache_manager.clone(), + command_channel: tx.clone(), + has_proxy, + }); let server_handle = server.handle(); info!("Notifying the server that we have finished starting up the client..."); diff --git a/src/route/server_command.rs b/src/route/server_command.rs index 6cb894b..edb2ec3 100644 --- a/src/route/server_command.rs +++ b/src/route/server_command.rs @@ -69,23 +69,11 @@ pub(super) async fn servercmd( // Switch to MT tokio runtime let runtime = data.runtime.enter(); - let mut rand = SmallRng::from_entropy(); + let mut rng = SmallRng::from_entropy(); let mut requests = Vec::new(); for _ in 1..=count { - let url = Url::parse( - format!( - "{}://{}:{}/t/{}/{}/{}/{}", - protocol, - host, - port, - size, - time, - token, - rand.gen::() - ) - .as_str(), - ) - .unwrap(); + let random: u32 = rng.gen(); + let url = Url::parse(&format!("{protocol}://{host}:{port}/t/{size}/{time}/{token}/{random}")).unwrap(); debug!("Speedtest thread start: {}", url); let reqwest = create_http_client(Duration::from_secs(60), None); // No proxy http client requests.push(tokio::spawn(async move { diff --git a/src/rpc.rs b/src/rpc.rs index 5735958..811cda2 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -325,11 +325,7 @@ The program will now terminate. let srv_res = self.send_action("dlfails", Some(&list.join(";"))).await; - debug!( - "Reported {} download failures with response {}.", - list.len(), - if srv_res.is_ok() { "OK" } else { "Fail" } - ); + debug!("Reported {} download failures with response {}.", list.len(), if srv_res.is_ok() { "OK" } else { "Fail" }); } pub async fn fetch_queue(&self, gallery: Option<&GalleryMeta>) -> Option> { @@ -482,10 +478,7 @@ The program will now terminate. fn build_url(&self, action: &str, additional: &str, endpoint: Option<&str>) -> Url { let mut url = self.api_base.read().clone(); let timestamp = &self.get_timestemp().to_string(); - let hash = string_to_hash(format!( - "hentai@home-{}-{}-{}-{}-{}", - action, additional, self.id, timestamp, self.key - )); + let hash = string_to_hash(format!("hentai@home-{}-{}-{}-{}-{}", action, additional, self.id, timestamp, self.key)); if let Some(endpoint) = endpoint { url.path_segments_mut().unwrap().pop().push(endpoint);