-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::api::fav::Fav; | ||
use crate::infra::http::{body_or_err, RequestBuilderExt, VecExt as HttpVecExt}; | ||
use crate::infra::iter::IntoIteratorExt; | ||
use crate::infra::json; | ||
use crate::infra::result::IntoResult; | ||
use crate::infra::vec::VecExt; | ||
use crate::openapi; | ||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
use std::ops::ControlFlow; | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct FavEntry { | ||
#[serde(rename = "Title")] | ||
pub title: String, | ||
#[serde(rename = "LinkUrl")] | ||
pub url: String, | ||
#[serde(rename = "Summary")] | ||
pub summary: String, | ||
#[serde(rename = "Tags")] | ||
pub tags: Vec<String>, | ||
#[serde(rename = "DateAdded")] | ||
pub create_time: String, | ||
} | ||
|
||
impl Fav { | ||
pub async fn get_list(&self, skip: usize, take: usize) -> Result<Vec<FavEntry>> { | ||
let client = &reqwest::Client::new(); | ||
|
||
let range = (skip + 1)..=(skip + take); | ||
let cf = range | ||
.map(|i| async move { | ||
let req = { | ||
let query = vec![("pageIndex", i), ("pageSize", 1)].into_query_string(); | ||
let url = openapi!("/Bookmarks?{}", query); | ||
client.get(url).pat_auth(&self.pat) | ||
}; | ||
|
||
let resp = req.send().await?; | ||
|
||
let body = body_or_err(resp).await?; | ||
|
||
json::deserialize::<Vec<FavEntry>>(&body)? | ||
.pop() | ||
.into_ok::<anyhow::Error>() | ||
}) | ||
.join_all() | ||
.await | ||
.into_iter() | ||
.try_fold(vec![], |acc, it| match it { | ||
Ok(maybe) => match maybe { | ||
Some(entry) => ControlFlow::Continue(acc.chain_push(entry)), | ||
None => ControlFlow::Break(Ok(acc)), | ||
}, | ||
Err(e) => ControlFlow::Break(Err(e)), | ||
}); | ||
|
||
match cf { | ||
ControlFlow::Continue(vec) => Ok(vec), | ||
ControlFlow::Break(result) => result, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pub mod get_list; | ||
|
||
// Aka cnblogs wz | ||
pub struct Fav { | ||
pat: String, | ||
} | ||
|
||
impl Fav { | ||
pub const fn new(pat: String) -> Self { | ||
Self { pat } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod auth; | ||
pub mod fav; | ||
pub mod ing; | ||
pub mod news; | ||
pub mod post; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use clap::Parser; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct Opt { | ||
#[arg(verbatim_doc_comment)] | ||
/// Show favorite list, order by time in DESC | ||
/// Example: cnb fav --list | ||
#[arg(long)] | ||
#[arg(short = 'l')] | ||
pub list: bool, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters