Skip to content

Commit 523f19d

Browse files
committed
inc ver; fav auth check
1 parent 1c390f1 commit 523f19d

7 files changed

Lines changed: 72 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
99
-->
1010

1111
## [Unreleased]
12+
## [1.0.5] - 2025-06-01
13+
14+
- `fav auth check` to check cookies usablity.
15+
1216
## [1.0.4] - 2025-06-01
1317

1418
- fix missing alias `c` for `collecion` for `deactivate` sub command

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ SELECT u.up_id, u.name, COUNT(u.up_id) count FROM up u LEFT JOIN media_up mu ON
158158
fav like
159159
# or like all medias faved
160160
fav ls v | sed '1d;$d' | awk '{print $2;}' | xargs fav like
161+
# check cookies usability
162+
fav auth check -a
161163
```
162164

163165
Service example:

fav_bili/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fav_bili"
3-
version = "1.0.4"
3+
version = "1.0.5"
44
authors.workspace = true
55
license.workspace = true
66
edition.workspace = true

fav_bili/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ SELECT u.up_id, u.name, COUNT(u.up_id) count FROM up u LEFT JOIN media_up mu ON
6060
fav like
6161
# or like all medias faved
6262
fav ls v | sed '1d;$d' | awk '{print $2;}' | xargs fav like
63+
# check cookies usability
64+
fav auth check -a
6365
```
6466

6567
Service example:

fav_bili/src/action/auth.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::time::Duration;
22

33
use anyhow::{Context as _, Result, anyhow};
4-
use api_req::{ApiCaller as _, COOKIE_JAR, CookieStore as _};
4+
use api_req::{ApiCaller as _, COOKIE_JAR, CookieStore as _, error::ApiErr};
55
use futures::StreamExt as _;
66
use qrcode::{QrCode, render::unicode};
77
use tokio::time::sleep;
@@ -138,3 +138,40 @@ async fn logout_account(account_id: i64, cookies: String) -> Result<()> {
138138
_ => Err(anyhow!("Failed to logout: {}", message.unwrap_or_default())),
139139
}
140140
}
141+
142+
pub async fn check(account_id: i64) -> Result<()> {
143+
let db = db().await;
144+
let account = db.get_account(account_id).await?;
145+
check_account(account).await?;
146+
Ok(())
147+
}
148+
149+
pub async fn check_all() -> Result<()> {
150+
let db = db().await;
151+
let accounts = db.all_accounts().await?;
152+
for account in accounts {
153+
check_account(account).await?;
154+
}
155+
Ok(())
156+
}
157+
158+
async fn check_account(account: account::Model) -> Result<()> {
159+
set_cookie_jar(parse_cookies(&account.cookies));
160+
match BiliApi::request(WbiPayload).await {
161+
Ok(WbiResp {
162+
data: WbiData { mid, .. },
163+
}) => {
164+
if mid == account.account_id {
165+
info!("Check passed. Hello😊, {}.", account.name);
166+
} else {
167+
error!("Bilibili returned unmatched user id")
168+
}
169+
}
170+
Err(ApiErr::UnDeserializeable(_)) => error!(
171+
"Bilibili returned unexpected json, cookies expired: account<{} {}>",
172+
account.name, account.account_id
173+
),
174+
Err(e) => return Err(e.into()),
175+
}
176+
Ok(())
177+
}

fav_bili/src/command.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl FavCommand {
3030
).action(ArgAction::Append)
3131
]),
3232
Command::new("logout")
33-
.about("Logout")
33+
.about("Logout accounts")
3434
.arg_required_else_help(true)
3535
.args([
3636
Arg::new("all")
@@ -44,6 +44,21 @@ impl FavCommand {
4444
.value_parser(value_parser!(i64))
4545
.action(ArgAction::Append),
4646
]),
47+
Command::new("check")
48+
.about("Check accounts cookies usability")
49+
.arg_required_else_help(true)
50+
.args([
51+
Arg::new("all")
52+
.help("Check all accounts cookies usability")
53+
.long("all")
54+
.short('a')
55+
.action(ArgAction::SetTrue)
56+
.conflicts_with("account_id"),
57+
Arg::new("account_id")
58+
.help("The account to check cookies usability")
59+
.value_parser(value_parser!(i64))
60+
.action(ArgAction::Append),
61+
]),
4762
]),
4863
Command::new("list")
4964
.about("List accounts/sets/ups/medias [alias: ls, l]")
@@ -261,6 +276,14 @@ impl FavCommand {
261276
logout(*account_id).await?;
262277
}
263278
}
279+
Some(("check", sub_matches)) if sub_matches.get_flag("all") => {
280+
check_all().await?;
281+
}
282+
Some(("check", sub_matches)) => {
283+
for account_id in sub_matches.get_many::<i64>("account_id").unwrap() {
284+
check(*account_id).await?;
285+
}
286+
}
264287
_ => unreachable!(),
265288
},
266289
Some(("list", sub_matches)) => match sub_matches.subcommand() {

0 commit comments

Comments
 (0)