diff --git a/src/bilibili/credential.rs b/src/bilibili/credential.rs index a1c8fbb..e8cbba4 100644 --- a/src/bilibili/credential.rs +++ b/src/bilibili/credential.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; use super::error::BiliError; use crate::bilibili::Client; -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct Credential { pub sessdata: String, pub bili_jct: String, @@ -22,16 +22,6 @@ pub struct Credential { } impl Credential { - const fn empty() -> Self { - Self { - sessdata: String::new(), - bili_jct: String::new(), - buvid3: String::new(), - dedeuserid: String::new(), - ac_time_value: String::new(), - } - } - /// 检查凭据是否有效 pub async fn need_refresh(&self, client: &Client) -> Result { let res = client @@ -126,7 +116,7 @@ JNrRuoEUXpabUzGB8QIDAQAB let set_cookies = headers.get_all(header::SET_COOKIE); let mut credential = Self { buvid3: self.buvid3.clone(), - ..Self::empty() + ..Self::default() }; let required_cookies = HashSet::from(["SESSDATA", "bili_jct", "DedeUserID"]); let cookies: Vec = set_cookies diff --git a/src/config.rs b/src/config.rs index d2421ba..ca43fe2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,7 @@ use std::borrow::Cow; use std::collections::HashMap; use std::path::PathBuf; +use std::sync::Arc; use anyhow::Result; use arc_swap::ArcSwapOption; @@ -54,7 +55,7 @@ impl Default for Config { impl Config { fn new() -> Self { Self { - credential: ArcSwapOption::empty(), + credential: ArcSwapOption::from(Some(Arc::new(Credential::default()))), filter_option: FilterOption::default(), danmaku_option: DanmakuOption::default(), favorite_list: HashMap::new(),