mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-05 23:49:53 +08:00
fix: 修复配置文件初始化时未填充 credential 默认值的问题 (#78)
This commit is contained in:
@@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use super::error::BiliError;
|
use super::error::BiliError;
|
||||||
use crate::bilibili::Client;
|
use crate::bilibili::Client;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Credential {
|
pub struct Credential {
|
||||||
pub sessdata: String,
|
pub sessdata: String,
|
||||||
pub bili_jct: String,
|
pub bili_jct: String,
|
||||||
@@ -22,16 +22,6 @@ pub struct Credential {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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> {
|
pub async fn need_refresh(&self, client: &Client) -> Result<bool> {
|
||||||
let res = client
|
let res = client
|
||||||
@@ -126,7 +116,7 @@ JNrRuoEUXpabUzGB8QIDAQAB
|
|||||||
let set_cookies = headers.get_all(header::SET_COOKIE);
|
let set_cookies = headers.get_all(header::SET_COOKIE);
|
||||||
let mut credential = Self {
|
let mut credential = Self {
|
||||||
buvid3: self.buvid3.clone(),
|
buvid3: self.buvid3.clone(),
|
||||||
..Self::empty()
|
..Self::default()
|
||||||
};
|
};
|
||||||
let required_cookies = HashSet::from(["SESSDATA", "bili_jct", "DedeUserID"]);
|
let required_cookies = HashSet::from(["SESSDATA", "bili_jct", "DedeUserID"]);
|
||||||
let cookies: Vec<Cookie> = set_cookies
|
let cookies: Vec<Cookie> = set_cookies
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use arc_swap::ArcSwapOption;
|
use arc_swap::ArcSwapOption;
|
||||||
@@ -54,7 +55,7 @@ impl Default for Config {
|
|||||||
impl Config {
|
impl Config {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
credential: ArcSwapOption::empty(),
|
credential: ArcSwapOption::from(Some(Arc::new(Credential::default()))),
|
||||||
filter_option: FilterOption::default(),
|
filter_option: FilterOption::default(),
|
||||||
danmaku_option: DanmakuOption::default(),
|
danmaku_option: DanmakuOption::default(),
|
||||||
favorite_list: HashMap::new(),
|
favorite_list: HashMap::new(),
|
||||||
|
|||||||
Reference in New Issue
Block a user