mirror of
https://github.com/lanyeeee/bilibili-video-downloader.git
synced 2026-09-08 00:56:51 +08:00
fix: 修复二维码登录失效的问题
This commit is contained in:
@@ -120,6 +120,15 @@ impl BiliClient {
|
|||||||
let http_resp = request.send().await?;
|
let http_resp = request.send().await?;
|
||||||
// 检查http响应状态码
|
// 检查http响应状态码
|
||||||
let status = http_resp.status();
|
let status = http_resp.status();
|
||||||
|
// 尝试从headers中拿SESSDATA
|
||||||
|
let sessdata = http_resp
|
||||||
|
.headers()
|
||||||
|
.get_all("set-cookie")
|
||||||
|
.iter()
|
||||||
|
.filter_map(|header| header.to_str().ok())
|
||||||
|
.filter_map(|header| header.split(';').next())
|
||||||
|
.filter_map(|cookie| cookie.split_once('='))
|
||||||
|
.find_map(|(key, value)| (key.trim() == "SESSDATA").then(|| value.to_owned()));
|
||||||
let body = http_resp.text().await?;
|
let body = http_resp.text().await?;
|
||||||
if status != StatusCode::OK {
|
if status != StatusCode::OK {
|
||||||
return Err(eyre!("预料之外的状态码({status}): {body}"));
|
return Err(eyre!("预料之外的状态码({status}): {body}"));
|
||||||
@@ -137,11 +146,14 @@ impl BiliClient {
|
|||||||
};
|
};
|
||||||
// 尝试将data解析为二维码状态
|
// 尝试将data解析为二维码状态
|
||||||
let data_str = data.to_string();
|
let data_str = data.to_string();
|
||||||
let qrcode_status: QrcodeStatus = serde_json::from_str(&data_str)
|
let mut qrcode_status: QrcodeStatus = serde_json::from_str(&data_str)
|
||||||
.wrap_err(format!("将data解析为QrcodeStatus失败: {data_str}"))?;
|
.wrap_err(format!("将data解析为QrcodeStatus失败: {data_str}"))?;
|
||||||
if ![0, 86101, 86090, 86038].contains(&qrcode_status.code) {
|
if ![0, 86101, 86090, 86038].contains(&qrcode_status.code) {
|
||||||
return Err(eyre!("预料之外的二维码code: {qrcode_status:?}"));
|
return Err(eyre!("预料之外的二维码code: {qrcode_status:?}"));
|
||||||
}
|
}
|
||||||
|
if qrcode_status.code == 0 {
|
||||||
|
qrcode_status.sessdata = sessdata.ok_or_eyre("扫码成功,但没有解析到SESSDATA")?;
|
||||||
|
}
|
||||||
Ok(qrcode_status)
|
Ok(qrcode_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use specta::Type;
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct QrcodeStatus {
|
pub struct QrcodeStatus {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
|
pub sessdata: String,
|
||||||
pub refresh_token: String,
|
pub refresh_token: String,
|
||||||
pub timestamp: i64,
|
pub timestamp: i64,
|
||||||
pub code: i64,
|
pub code: i64,
|
||||||
|
|||||||
+1
-1
@@ -424,7 +424,7 @@ export type PurchaseFormatNote = { content_list: ContentList[]; link: string; ti
|
|||||||
export type PurchaseNote = { content: string; link: string; title: string }
|
export type PurchaseNote = { content: string; link: string; title: string }
|
||||||
export type PurchaseProtocol = { link: string; title: string }
|
export type PurchaseProtocol = { link: string; title: string }
|
||||||
export type QrcodeData = { url: string; qrcode_key: string }
|
export type QrcodeData = { url: string; qrcode_key: string }
|
||||||
export type QrcodeStatus = { url: string; refresh_token: string; timestamp: number; code: number; message: string }
|
export type QrcodeStatus = { url: string; sessdata: string; refresh_token: string; timestamp: number; code: number; message: string }
|
||||||
export type RatingInBangumi = { count: number; score: number }
|
export type RatingInBangumi = { count: number; score: number }
|
||||||
export type RatingInBangumiFollow = { score: number; count: number }
|
export type RatingInBangumiFollow = { score: number; count: number }
|
||||||
export type RecommendSeason = { cover: string; ep_count: string; id: number; season_url: string; subtitle: string; title: string; view: number }
|
export type RecommendSeason = { cover: string; ep_count: string; id: number; season_url: string; subtitle: string; title: string; view: number }
|
||||||
|
|||||||
@@ -93,8 +93,7 @@ function handleQrcodeStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (qrcodeStatus.value.code === 0) {
|
if (qrcodeStatus.value.code === 0) {
|
||||||
const sessdata = qrcodeStatus.value.url.split('SESSDATA=')[1].split('&')[0]
|
store.config.sessdata = qrcodeStatus.value.sessdata
|
||||||
store.config.sessdata = encodeURIComponent(sessdata)
|
|
||||||
showing.value = false
|
showing.value = false
|
||||||
message.success('登录成功')
|
message.success('登录成功')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user