mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-07 08:27:21 +08:00
feat: 复用 client 单例
This commit is contained in:
@@ -7,6 +7,7 @@ use crate::bilibili::Credential;
|
|||||||
use crate::config::CONFIG;
|
use crate::config::CONFIG;
|
||||||
|
|
||||||
// 一个对 reqwest::Client 的简单封装,用于 Bilibili 请求
|
// 一个对 reqwest::Client 的简单封装,用于 Bilibili 请求
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Client(reqwest::Client);
|
pub struct Client(reqwest::Client);
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
@@ -56,7 +57,7 @@ impl Default for Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct BiliClient {
|
pub struct BiliClient {
|
||||||
client: Client,
|
pub client: Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BiliClient {
|
impl BiliClient {
|
||||||
|
|||||||
+1
-1
@@ -153,7 +153,7 @@ pub async fn download_unprocessed_videos(
|
|||||||
let unhandled_videos_pages = unhandled_videos_pages(&favorite_model, connection).await?;
|
let unhandled_videos_pages = unhandled_videos_pages(&favorite_model, connection).await?;
|
||||||
// 对于视频,允许五个同时下载(视频内还有分页、不同分页还有多种下载任务)
|
// 对于视频,允许五个同时下载(视频内还有分页、不同分页还有多种下载任务)
|
||||||
let semaphore = Semaphore::new(5);
|
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();
|
let mut uppers_mutex: HashMap<i64, (Mutex<()>, Mutex<()>)> = HashMap::new();
|
||||||
for (video_model, _) in &unhandled_videos_pages {
|
for (video_model, _) in &unhandled_videos_pages {
|
||||||
uppers_mutex.insert(video_model.upper_id, (Mutex::new(()), Mutex::new(())));
|
uppers_mutex.insert(video_model.upper_id, (Mutex::new(()), Mutex::new(())));
|
||||||
|
|||||||
@@ -55,9 +55,3 @@ impl Downloader {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Downloader {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new(Client::new())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user