Run cargo fmt

This commit is contained in:
Leon Grünewald 2024-01-01 21:50:57 +01:00
parent f950fa5476
commit eac4798620
4 changed files with 36 additions and 33 deletions

View file

@ -1,9 +1,7 @@
use std::io::Write;
use anyhow::Result;
use base64::Engine;
use base64::engine::{GeneralPurpose};
use crate::post::{Post, Posts};
use reqwest::header::{AUTHORIZATION, HeaderMap, HeaderValue, USER_AGENT};
use anyhow::Result;
use base64::{engine::GeneralPurpose, Engine};
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, USER_AGENT};
use reqwest::Response;
#[derive(Clone, Debug)]
@ -11,7 +9,7 @@ pub struct Client<'a> {
auth: Authentication<'a>,
useragent: &'a str,
host: &'static str,
http_client: reqwest::Client
http_client: reqwest::Client,
}
impl<'a> Client<'a> {
@ -31,7 +29,7 @@ impl<'a> Client<'a> {
auth,
useragent,
host: "https://e621.net",
http_client
http_client,
})
}
@ -40,7 +38,12 @@ impl<'a> Client<'a> {
base64_engine.encode(format!("{username}:{apikey}"))
}
async fn list_posts_raw(&mut self, limit: Option<u16>, tags: Option<Vec<String>>, page: Option<u32>) -> Result<Response> {
async fn list_posts_raw(
&mut self,
limit: Option<u16>,
tags: Option<Vec<String>>,
page: Option<u32>,
) -> Result<Response> {
let mut url = url::Url::parse(format!("{}/posts.json", self.host).as_str())?;
let mut query_params = Vec::new();
@ -60,12 +63,15 @@ impl<'a> Client<'a> {
url.set_query(Some(&query_params.join("&")));
Ok(self.http_client.get(url.as_str())
.send()
.await?)
Ok(self.http_client.get(url.as_str()).send().await?)
}
pub async fn list_posts(&mut self, limit: Option<u16>, tags: Option<Vec<String>>, page: Option<u32>) -> Result<Vec<Post>> {
pub async fn list_posts(
&mut self,
limit: Option<u16>,
tags: Option<Vec<String>>,
page: Option<u32>,
) -> Result<Vec<Post>> {
let res = self.list_posts_raw(limit, tags, page).await?;
let text = res.text().await?;
@ -83,6 +89,6 @@ impl<'a> Client<'a> {
#[derive(Clone, Copy, Debug)]
pub enum Authentication<'a> {
Authorized {username: &'a str, apikey: &'a str},
Unauthorized
Authorized { username: &'a str, apikey: &'a str },
Unauthorized,
}

View file

@ -1,3 +1 @@
enum Error {
}
enum Error {}

View file

@ -1,3 +1,3 @@
pub mod client;
pub mod post;
mod errors;
pub mod post;

View file

@ -5,7 +5,7 @@ pub type ImageDimension = u64;
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct Posts {
#[serde(alias = "posts")]
inner: Vec<Post>
inner: Vec<Post>,
}
impl Into<Vec<Post>> for Posts {
@ -14,7 +14,6 @@ impl Into<Vec<Post>> for Posts {
}
}
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub struct Post {
pub id: Id,
@ -32,7 +31,7 @@ pub struct Post {
pub has_notes: bool,
pub is_favorited: bool,
pub change_seq: Option<u128>,
pub relationships: PostRelationships
pub relationships: PostRelationships,
}
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
@ -43,7 +42,7 @@ pub struct PostTags {
pub character: Vec<String>,
pub invalid: Vec<String>,
pub meta: Vec<String>,
pub lore: Vec<String>
pub lore: Vec<String>,
}
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
@ -53,7 +52,7 @@ pub struct PostFile {
pub ext: String,
pub size: FileSize,
pub md5: String,
pub url: String
pub url: String,
}
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]