use crate::{error::Error, Result};
use reqwest::{Client, Response};
use serde::Serialize;
use url::Url;
#[derive(Serialize, Clone)]
#[non_exhaustive]
pub struct AtHomeReport {
pub url: Url,
pub success: bool,
pub cached: bool,
pub bytes: usize,
pub duration: u128,
}
impl AtHomeReport {
pub async fn send(&self, client: &Client) -> Result<Response> {
if !self.url.as_str().contains("mangadex.org") {
match client
.post("https://api.mangadex.network/report")
.json(self)
.timeout(std::time::Duration::from_secs(2))
.send()
.await
{
Ok(d) => Result::Ok(d),
Err(e) => Result::Err(Error::RequestError(e)),
}
} else {
Result::Err(Error::unknow("the mangadex.org pattern found!"))
}
}
}