11use std:: collections:: { HashMap , HashSet } ;
22use std:: io:: ErrorKind ;
33use std:: path:: { Path , PathBuf } ;
4- use std:: sync:: { Arc , Mutex , OnceLock } ;
4+ use std:: sync:: { Arc , Mutex } ;
55use std:: time:: { Duration , SystemTime , UNIX_EPOCH } ;
66
77use sea_orm:: { DatabaseConnection , EntityTrait } ;
88use tauri:: Manager ;
99use tauri:: command;
1010use tauri:: http:: { Response , StatusCode } ;
11- use tauri_plugin_http:: reqwest:: Client ;
1211use tokio:: sync:: { RwLock , Semaphore , watch} ;
1312
1413use crate :: entity:: prelude:: Games ;
@@ -17,18 +16,9 @@ use reina_path::get_base_data_dir;
1716const DEFAULT_COVER_EXTENSION : & str = "jpg" ;
1817const DEFAULT_CLOUD_COVER_FILE_NAME : & str = "cloud_cover" ;
1918const MAX_CONCURRENT_COVER_DOWNLOADS : usize = 100 ;
20- const COVER_DOWNLOAD_CONNECT_TIMEOUT_SECS : u64 = 10 ;
21- const COVER_DOWNLOAD_TIMEOUT_SECS : u64 = 60 ;
2219/// 最多重试次数(不含首次),退避延迟为 500ms * 2^attempt
2320const COVER_MAX_RETRIES : u32 = 2 ;
2421const COVER_RETRY_BASE_DELAY_MS : u64 = 500 ;
25- const COVER_USER_AGENT : & str = concat ! (
26- "huoshen80/ReinaManager/" ,
27- env!( "CARGO_PKG_VERSION" ) ,
28- " (https://github.com/huoshen80/ReinaManager)"
29- ) ;
30-
31- static COVER_HTTP_CLIENT : OnceLock < Client > = OnceLock :: new ( ) ;
3222
3323#[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
3424struct DownloadKey {
@@ -105,17 +95,6 @@ impl Drop for DownloadCleanupGuard {
10595 }
10696}
10797
108- fn cover_http_client ( ) -> & ' static Client {
109- COVER_HTTP_CLIENT . get_or_init ( || {
110- Client :: builder ( )
111- . connect_timeout ( Duration :: from_secs ( COVER_DOWNLOAD_CONNECT_TIMEOUT_SECS ) )
112- . timeout ( Duration :: from_secs ( COVER_DOWNLOAD_TIMEOUT_SECS ) )
113- . user_agent ( COVER_USER_AGENT )
114- . build ( )
115- . expect ( "failed to build game cover http client" )
116- } )
117- }
118-
11998fn infer_cache_extension ( cloud_url : & str ) -> String {
12099 let url_without_suffix = cloud_url. split ( [ '?' , '#' ] ) . next ( ) . unwrap_or ( cloud_url) ;
121100 let file_name = url_without_suffix
@@ -344,7 +323,7 @@ async fn try_download_once(
344323 let cache_path = build_cache_path ( game_cover_dir, game_id, & extension) ;
345324 let temp_path = build_temp_cache_path ( game_cover_dir, game_id, & extension) ;
346325
347- let response = cover_http_client ( )
326+ let response = crate :: utils :: http :: get_client ( )
348327 . get ( url)
349328 . send ( )
350329 . await
0 commit comments