use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value;
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Comment {
pub id: i64,
pub comment: String,
pub date: String,
pub user: User,
pub has_replies: bool,
pub stamp: Option<Stamp>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Stamp {
pub stamp_id: i64,
pub stamp_url: String,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Novel {
pub id: i64,
pub title: String,
pub caption: String,
pub restrict: i64,
pub x_restrict: i64,
pub is_original: bool,
pub image_urls: IllustrationURLs,
pub create_date: String,
pub tags: Vec<Tag>,
pub page_count: i64,
pub text_length: i64,
pub user: User,
#[serde(deserialize_with = "Novel::deserialize_series")]
pub series: Option<Series>,
pub is_bookmarked: bool,
pub total_bookmarks: i64,
pub total_view: i64,
pub visible: bool,
pub total_comments: i64,
pub is_muted: bool,
pub is_mypixiv_only: bool,
pub is_x_restricted: bool,
pub novel_ai_type: i64,
pub request: Value,
}
impl Novel {
fn deserialize_series<'de, D>(d: D) -> Result<Option<Series>, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
enum Helper {
R(Series),
#[allow(dead_code)] S(Value),
}
match Helper::deserialize(d) {
Ok(Helper::S(_)) => Ok(None),
Ok(Helper::R(s)) => Ok(Some(s)),
Err(e) => Err(e),
}
}
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PixivUser {
pub id: i64,
pub name: String,
pub account: String,
pub profile_image_urls: ProfileImageUrls,
pub comment: Option<String>,
pub is_followed: bool,
pub is_access_blocking_user: Option<bool>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ProfileImageUrls {
pub medium: String,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Profile {
pub webpage: Value,
pub gender: String,
pub birth: String,
pub birth_day: String,
pub birth_year: i64,
pub region: String,
pub address_id: i64,
pub country_code: String,
pub job: String,
pub job_id: i64,
pub total_follow_users: i64,
pub total_mypixiv_users: i64,
pub total_illusts: i64,
pub total_manga: i64,
pub total_novels: i64,
pub total_illust_bookmarks_public: i64,
pub total_illust_series: i64,
pub total_novel_series: i64,
pub background_image_url: String,
pub twitter_account: String,
pub twitter_url: String,
pub pawoo_url: Value,
pub is_premium: bool,
pub is_using_custom_profile_image: bool,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ProfilePublicity {
pub gender: String,
pub region: String,
pub birth_day: String,
pub birth_year: String,
pub job: String,
pub pawoo: bool,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Workspace {
pub pc: String,
pub monitor: String,
pub tool: String,
pub scanner: String,
pub tablet: String,
pub mouse: String,
pub printer: String,
pub desktop: String,
pub music: String,
pub desk: String,
pub chair: String,
pub comment: String,
pub workspace_image_url: Value,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UgoiraMetadata {
pub zip_urls: ZipUrls,
pub frames: Vec<Frame>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ZipUrls {
pub medium: String,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Frame {
pub file: String,
pub delay: i64,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Illustration {
pub id: u32,
pub tags: Vec<Tag>,
pub visible: bool,
pub title: String,
pub caption: String,
pub height: u32,
pub width: u32,
pub page_count: i32,
pub user: User,
pub tools: Vec<String>,
pub series: Option<Series>,
pub restrict: i32,
pub x_restrict: i32,
pub image_urls: IllustrationURLs,
pub meta_single_page: Option<IllustrationMetaURL>,
pub meta_pages: Vec<IllustrationURLsWrapper>,
pub total_view: u32,
pub total_bookmarks: u32,
pub is_bookmarked: bool,
pub is_muted: bool,
pub total_comments: Option<u32>,
pub illust_ai_type: u32,
pub illust_book_style: u32,
pub comment_access_control: Option<u32>,
pub create_date: String,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Series {
pub id: u32,
pub title: String,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct User {
pub id: i32,
pub name: String,
pub account: String,
pub profile_image_urls: UserProfileImages,
pub is_followed: Option<bool>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UserProfileImages {
pub medium: String,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct IllustrationURLsWrapper {
pub image_urls: IllustrationURLs,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct IllustrationMetaURL {
pub original_image_url: Option<String>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct IllustrationURLs {
pub square_medium: String,
pub medium: String,
pub large: String,
pub original: Option<String>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Tag {
pub name: String,
pub translated_name: Option<String>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PixivUserResult {
pub user: PixivUser,
pub profile: Option<Profile>,
pub profile_publicity: Option<ProfilePublicity>,
pub workspace: Option<Workspace>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PixivUserStateResult {
pub user_state: UserState,
pub profile: StateProfile,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UserState {
pub is_mail_authorized: bool,
pub has_mail_address: bool,
pub has_changed_pixiv_id: bool,
pub can_change_pixiv_id: bool,
pub has_password: bool,
pub require_policy_agreement: bool,
pub no_login_method: bool,
pub is_user_restricted: bool,
pub is_official_event_notifications_enabled: bool,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StateProfile {
pub user_id: i32,
pub pixiv_id: String,
pub name: String,
pub profile_image_urls: ProfileImageUrls,
pub is_premium: bool,
pub x_restrict: i64,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PixivResult {
pub comments: Option<Vec<Comment>>,
pub illust: Option<Illustration>,
pub illusts: Option<Vec<Illustration>>,
pub error: Option<PixivError>,
pub ugoira_metadata: Option<UgoiraMetadata>,
pub user_previews: Option<Vec<PixivUserResult>>,
pub tags: Option<Vec<Tag>>,
pub novels: Option<Vec<Novel>>,
pub users: Option<Vec<Value>>,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PixivError {
user_message: String,
message: String,
reason: String,
}
impl std::error::Error for PixivError {}
impl std::fmt::Display for PixivError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}: {}", self.user_message, self.reason)
}
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionResponseWrapper {
pub response: SessionResponse,
}
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionResponse {
pub access_token: String,
pub refresh_token: String,
pub expires_in: i64,
}