v0.15-WORKINGV3

This commit is contained in:
2022-12-04 12:26:02 +05:30
parent 32fb36623b
commit c8fba74480
4 changed files with 103 additions and 57 deletions

View File

@@ -160,20 +160,22 @@ impl Books {
impl BookUI {
async fn set_descriptions(&mut self) {
let query = format!("https://openlibrary.org/{}.json", self.open_library_key.as_ref().unwrap().clone());
let res = reqwest::get(query).await.expect("Unable to request");
let resjson = res.json::<BookPageOL>().await.expect("Unable to return value");
let description = resjson.description;
if self.open_library_key.is_some() {
let query = format!("https://openlibrary.org/{}.json", self.open_library_key.as_ref().unwrap().clone());
let res = reqwest::get(query).await.expect("Unable to request");
let resjson = res.json::<BookPageOL>().await.expect("Unable to return value");
let description = resjson.description;
if !description.is_none() {
if let DescriptionOL::DescriptionString(desc_string) = description.clone().unwrap() {
self.description = Some(desc_string);
if !description.is_none() {
if let DescriptionOL::DescriptionString(desc_string) = description.clone().unwrap() {
self.description = Some(desc_string);
}
if let DescriptionOL::DescriptionValueString(desc_val) = description.clone().unwrap() {
self.description = Some(desc_val.value);
}
}
if let DescriptionOL::DescriptionValueString(desc_val) = description.clone().unwrap() {
self.description = Some(desc_val.value);
}
}
}
}
@@ -666,12 +668,14 @@ async fn create_book(
}
if !doc_sent.cover.is_none() {
let img_bytes = reqwest::get(cover.unwrap()).await.unwrap().bytes().await.unwrap();
let image = image::load_from_memory(&img_bytes).unwrap();
let temp_cover = doc_sent.cover.clone().unwrap();
let img_id = format!("{}{}",temp_cover.split("/").last().unwrap(),Local::now().format("%Y-%m-%d-%H-%M-%S"));
image.save(format!("{}/{}",images_dir,img_id)).expect("Failed to save image");
cover = Some(img_id.to_string());
if !doc_sent.cover.clone().unwrap().is_empty() {
let img_bytes = reqwest::get(cover.unwrap()).await.unwrap().bytes().await.unwrap();
let image = image::load_from_memory(&img_bytes).unwrap();
let temp_cover = doc_sent.cover.clone().unwrap();
let img_id = format!("{}{}",Local::now().format("%Y-%m-%d-%H-%M-%S"),temp_cover.split("/").last().unwrap());
image.save(format!("{}/{}",images_dir,img_id)).expect("Failed to save image");
cover = Some(img_id.to_string());
}
}
let book: book::Model = book::Model{
@@ -800,17 +804,18 @@ println!("Updating book");
let mut cover = doc_sent.cover.clone();
if !doc_sent.cover.is_none() {
if doc_sent.cover.clone().unwrap().contains(&backend_url) {
cover = Some(doc_sent.cover.clone().unwrap().split("/").last().unwrap().to_string());
} else {
let img_bytes = reqwest::get(cover.unwrap()).await.unwrap().bytes().await.unwrap();
//.expect("Could not fetch image");
//let img_bytes = img_resp.unwrap().bytes();
let image = image::load_from_memory(&img_bytes).unwrap();
let temp_cover = doc_sent.cover.clone().unwrap();
let img_id = format!("{}{}",temp_cover.split("/").last().unwrap(),Local::now().format("%Y-%m-%d-%H-%M-%S"));
image.save(format!("{}/{}",images_dir,img_id)).expect("Failed to save image");
cover = Some(img_id.to_string());
if !doc_sent.cover.clone().unwrap().is_empty() {
if doc_sent.cover.clone().unwrap().contains(&backend_url) {
cover = Some(doc_sent.cover.clone().unwrap().split("/").last().unwrap().to_string());
}
else {
let img_bytes = reqwest::get(cover.unwrap()).await.unwrap().bytes().await.unwrap();
let image = image::load_from_memory(&img_bytes).unwrap();
let temp_cover = doc_sent.cover.clone().unwrap();
let img_id = format!("{}{}",Local::now().format("%Y-%m-%d-%H-%M-%S"),temp_cover.split("/").last().unwrap());
image.save(format!("{}/{}",images_dir,img_id)).expect("Failed to save image");
cover = Some(img_id.to_string());
}
}
}
let book: book::Model = book::Model{