rusty_booru/gelbooru/
mod.rs1pub mod client;
2
3use derive_more::From;
4use serde::{Deserialize, Serialize};
5use strum::Display;
6
7use crate::generic::{BooruPost, Rating};
8
9#[derive(Serialize, Deserialize, Debug, Clone)]
11pub struct GelbooruPost {
12 pub id: u32,
14 pub created_at: String,
16 pub score: u32,
18 pub width: u32,
20 pub height: u32,
22 pub md5: String,
24 pub file_url: String,
26 pub tags: String,
28 pub image: String,
30 pub source: String,
32 pub rating: GelbooruRating,
34}
35
36#[derive(Serialize, Deserialize, Debug, Clone)]
38pub struct GelbooruResponse {
39 #[serde(rename = "post")]
40 pub posts: Vec<GelbooruPost>,
41}
42
43#[derive(Serialize, Deserialize, Debug, Clone, Display, From)]
45#[strum(serialize_all = "lowercase")]
46#[serde(rename_all = "lowercase")]
47pub enum GelbooruRating {
48 Explicit,
49 Questionable,
50 Safe,
51 Sensitive,
52 General,
53}
54
55impl From<Rating> for GelbooruRating {
56 fn from(value: Rating) -> Self {
57 match value {
58 Rating::Explicit => Self::Explicit,
59 Rating::Questionable => Self::Questionable,
60 Rating::Safe => Self::Safe,
61 Rating::Sensitive => Self::Sensitive,
62 Rating::General => Self::General,
63 }
64 }
65}
66
67impl From<GelbooruRating> for Rating {
68 fn from(value: GelbooruRating) -> Self {
69 match value {
70 GelbooruRating::Explicit => Rating::Explicit,
71 GelbooruRating::Questionable => Rating::Questionable,
72 GelbooruRating::Safe => Rating::Safe,
73 GelbooruRating::Sensitive => Rating::Sensitive,
74 GelbooruRating::General => Rating::General,
75 }
76 }
77}
78
79impl From<GelbooruPost> for BooruPost {
80 fn from(post: GelbooruPost) -> Self {
81 BooruPost {
82 id: post.id,
83 created_at: post.created_at.into(),
84 score: post.score.into(),
85 width: post.width,
86 height: post.height,
87 md5: post.md5.into(),
88 file_url: post.file_url.into(),
89 tags: post.tags,
90 image: post.image.into(),
91 source: post.source.into(),
92 rating: post.rating.into(),
93 }
94 }
95}