From aa9d8c9e6661540aed76f24ee73c0c6fbf114761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=80=E1=B4=8D=E1=B4=9B=E1=B4=8F=E1=B4=80=E1=B4=87?= =?UTF-8?q?=CA=80?= Date: Thu, 25 Apr 2024 23:00:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=B6=E6=9C=AA?= =?UTF-8?q?=E5=A1=AB=E5=85=85=20credential=20=E9=BB=98=E8=AE=A4=E5=80=BC?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#78)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bilibili/credential.rs | 14 ++------------ src/config.rs | 3 ++- 2 files changed, 4 insertions(+), 13 deletions(-) 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(),