feat: 复用 client 单例

This commit is contained in:
amtoaer
2024-04-11 21:56:42 +08:00
parent 5db49c3e24
commit 2ef18ee5c8
3 changed files with 3 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ use crate::bilibili::Credential;
use crate::config::CONFIG;
// 一个对 reqwest::Client 的简单封装,用于 Bilibili 请求
#[derive(Clone)]
pub struct Client(reqwest::Client);
impl Client {
@@ -56,7 +57,7 @@ impl Default for Client {
}
pub struct BiliClient {
client: Client,
pub client: Client,
}
impl BiliClient {

View File

@@ -153,7 +153,7 @@ pub async fn download_unprocessed_videos(
let unhandled_videos_pages = unhandled_videos_pages(&favorite_model, connection).await?;
// 对于视频,允许五个同时下载(视频内还有分页、不同分页还有多种下载任务)
let semaphore = Semaphore::new(5);
let downloader = Downloader::default();
let downloader = Downloader::new(bili_client.client.clone());
let mut uppers_mutex: HashMap<i64, (Mutex<()>, Mutex<()>)> = HashMap::new();
for (video_model, _) in &unhandled_videos_pages {
uppers_mutex.insert(video_model.upper_id, (Mutex::new(()), Mutex::new(())));

View File

@@ -55,9 +55,3 @@ impl Downloader {
Ok(())
}
}
impl Default for Downloader {
fn default() -> Self {
Self::new(Client::new())
}
}