v0.14-popupV1
This commit is contained in:
@@ -154,25 +154,6 @@ impl Books {
|
||||
}
|
||||
}
|
||||
|
||||
async fn set_all_descriptions(&mut self) {
|
||||
for book in self.docs.iter_mut() {
|
||||
let query = format!("https://openlibrary.org/{}.json", book.key);
|
||||
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() {
|
||||
book.description = Some(desc_string);
|
||||
}
|
||||
if let DescriptionOL::DescriptionValueString(desc_val) = description.clone().unwrap() {
|
||||
book.description = Some(desc_val.value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl BookUI {
|
||||
@@ -503,7 +484,7 @@ async fn search_openlibrary(
|
||||
let mut resjson = res.json::<Books>().await.expect("Unable to return value");
|
||||
resjson.docs.truncate(12);
|
||||
resjson.set_all_cover_urls();
|
||||
resjson.set_all_descriptions().await;
|
||||
//resjson.set_all_descriptions().await;
|
||||
print!("Search token {:?}\n", search);
|
||||
let mut vec = Vec::with_capacity(12);
|
||||
for i in 0..12 as usize {
|
||||
@@ -571,7 +552,7 @@ let mut resbooks: Vec<BookUI> = Vec::with_capacity(5);
|
||||
for bookandmeta in books.0.into_iter() {
|
||||
let mut cover = bookandmeta.clone().book.cover;
|
||||
if !cover.is_none() {
|
||||
cover = Some(format!("{}/images/{}",backend_url,cover.unwrap()));
|
||||
cover = Some(format!("{}/images/{}",backend_url, cover.unwrap()));
|
||||
} else {
|
||||
cover = Some(format!("{}/images/placeholder.jpg",backend_url));
|
||||
}
|
||||
@@ -667,24 +648,31 @@ return Json(res);
|
||||
async fn create_book(
|
||||
Extension(ref conn): Extension<DatabaseConnection>,
|
||||
Extension(ref meili_client): Extension<Client>,
|
||||
Json(doc_sent): Json<BookUI>,
|
||||
Json(doc_sent_orig): Json<BookUI>,
|
||||
) -> impl IntoResponse {
|
||||
println!("Creating book");
|
||||
|
||||
dotenvy::dotenv().ok();
|
||||
let images_dir = env::var("IMAGES_DIR").expect("IMAGES_DIR is not set in .env file");
|
||||
|
||||
let mut doc_sent = doc_sent_orig.clone();
|
||||
let mut cover = doc_sent.cover.clone();
|
||||
if doc_sent_orig.description.is_none() {
|
||||
doc_sent.set_descriptions().await;
|
||||
} else {
|
||||
if doc_sent_orig.description.unwrap() == "".to_string() {
|
||||
doc_sent.set_descriptions().await;
|
||||
}
|
||||
}
|
||||
|
||||
if !doc_sent.cover.is_none() {
|
||||
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 = 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{
|
||||
open_library_key: doc_sent.open_library_key.to_owned(),
|
||||
title: (doc_sent.title.to_owned()),
|
||||
|
||||
Reference in New Issue
Block a user