Skip to content

Commit

Permalink
fix: 修复配置文件初始化时未填充 credential 默认值的问题 (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoaer authored Apr 25, 2024
1 parent 1ad82e5 commit aa9d8c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
14 changes: 2 additions & 12 deletions src/bilibili/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<bool> {
let res = client
Expand Down Expand Up @@ -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<Cookie> = set_cookies
Expand Down
3 changes: 2 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit aa9d8c9

Please sign in to comment.