use crate::UrlScanClient;
use crate::error::UrlScanError;
use crate::http::get_plain;
use crate::http::get_as_bytes;
use reqwest::header::HeaderMap;
use image::{DynamicImage, ImageError};
use std::io::{Error, ErrorKind};
impl UrlScanClient {
pub fn get_result(&self, uuid: &str) -> Result<String, UrlScanError> {
let request_url = format!("{}{}result/{}", &self.domain, &self.endpoint, uuid);
get_plain(&request_url, HeaderMap::new())
}
pub fn get_screenshot(&self, uuid: &str) -> Result<DynamicImage, ImageError> {
let request_url = format!("{}screenshots/{}.png", &self.domain, uuid);
let response = get_as_bytes(&request_url, HeaderMap::new());
match response {
Ok(response) => image::load_from_memory(&response),
_ => Err(ImageError::IoError(Error::new(ErrorKind::Other, "oh no!"))),
}
}
pub fn save_screenshot(&self, image: DynamicImage, path: &str) -> Result<(), ImageError> {
image.save(path)
}
pub fn get_dom(&self, uuid: &str) -> Result<String, UrlScanError> {
let request_url = format!("{}dom/{}", &self.domain, uuid);
println!("Request: {request_url}");
get_plain(&request_url, HeaderMap::new())
}
}