mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Update
This commit is contained in:
92
src/fanbox/creator.rs
Normal file
92
src/fanbox/creator.rs
Normal file
@@ -0,0 +1,92 @@
|
||||
use crate::fanbox_api::FanboxClientInternal;
|
||||
use crate::parser::json::parse_u64;
|
||||
use json::JsonValue;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// To present a creator's info
|
||||
pub struct FanboxCreator {
|
||||
/// Raw data
|
||||
pub data: JsonValue,
|
||||
/// Fanbox api client
|
||||
client: Arc<FanboxClientInternal>,
|
||||
}
|
||||
|
||||
impl FanboxCreator {
|
||||
#[inline]
|
||||
pub fn creator_id(&self) -> Option<&str> {
|
||||
self.data["creatorId"].as_str()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn cover_image_url(&self) -> Option<&str> {
|
||||
self.data["coverImageUrl"].as_str()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn description(&self) -> Option<&str> {
|
||||
self.data["description"].as_str()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn has_adult_content(&self) -> Option<bool> {
|
||||
self.data["hasAdultContent"].as_bool()
|
||||
}
|
||||
|
||||
/// Create a new instance
|
||||
pub fn new(data: &JsonValue, client: Arc<FanboxClientInternal>) -> Self {
|
||||
Self {
|
||||
data: data.clone(),
|
||||
client,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn profile_links(&self) -> Option<Vec<&str>> {
|
||||
let mut links = Vec::new();
|
||||
let pro = &self.data["profileLinks"];
|
||||
if pro.is_array() {
|
||||
for i in pro.members() {
|
||||
match i.as_str() {
|
||||
Some(s) => links.push(s),
|
||||
None => {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(links)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn user_icon_url(&self) -> Option<&str> {
|
||||
self.data["user"]["iconUrl"].as_str()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn user_id(&self) -> Option<u64> {
|
||||
parse_u64(&self.data["user"]["userId"])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn user_name(&self) -> Option<&str> {
|
||||
self.data["user"]["name"].as_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for FanboxCreator {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("FanboxCreator")
|
||||
.field("creator_id", &self.creator_id())
|
||||
.field("cover_image_url", &self.cover_image_url())
|
||||
.field("description", &self.description())
|
||||
.field("has_adult_content", &self.has_adult_content())
|
||||
.field("profile_links", &self.profile_links())
|
||||
.field("user_icon_url", &self.user_icon_url())
|
||||
.field("user_id", &self.user_id())
|
||||
.field("user_name", &self.user_name())
|
||||
.finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod creator;
|
||||
pub mod error;
|
||||
pub mod item;
|
||||
pub mod item_list;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::ext::atomic::AtomicQuick;
|
||||
use crate::ext::replace::ReplaceWith2;
|
||||
use crate::ext::rw_lock::GetRwLock;
|
||||
use crate::fanbox::creator::FanboxCreator;
|
||||
use crate::fanbox::item_list::FanboxItemList;
|
||||
use crate::fanbox::paginated_creator_posts::PaginatedCreatorPosts;
|
||||
use crate::fanbox::plan::FanboxPlanList;
|
||||
@@ -262,6 +263,19 @@ pub struct FanboxClient {
|
||||
}
|
||||
|
||||
impl FanboxClient {
|
||||
#[allow(dead_code)]
|
||||
/// Get creator's info
|
||||
/// * `creator_id` - The id of the creator
|
||||
pub async fn get_creator<S: AsRef<str> + ?Sized>(
|
||||
&self,
|
||||
creator_id: &S,
|
||||
) -> Option<FanboxCreator> {
|
||||
match self.client.get_creator(creator_id).await {
|
||||
Some(s) => Some(FanboxCreator::new(&s["body"], Arc::clone(&self.client))),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create an new instance
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user