This commit is contained in:
2023-08-09 03:14:58 +02:00
parent 041ff80313
commit d69dcd95c1
4 changed files with 33 additions and 3 deletions

View File

@@ -47,3 +47,22 @@ pub async fn get_book(
) -> Result<types::BookWithRemote, Box<dyn std::error::Error + Send + Sync>> { ) -> Result<types::BookWithRemote, Box<dyn std::error::Error + Send + Sync>> {
_make_request(format!("/api/v1/books/{book_id}").as_str(), vec![]).await _make_request(format!("/api/v1/books/{book_id}").as_str(), vec![]).await
} }
pub async fn get_books(
page: u32,
page_size: u32,
uploaded_gte: String,
uploaded_lte: String,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let _params: Vec<(&str, String)> = vec![
("page", page.to_string()),
("page_size", page_size.to_string()),
("uploaded_gte", uploaded_gte),
("uploaded_lte", uploaded_lte)
];
// TODO
// _make_request(format!("/api/v1/books/").as_str(), params).await;
Ok(())
}

View File

@@ -1,5 +1,6 @@
use reqwest::Response; use reqwest::Response;
use serde::Deserialize; use serde::Deserialize;
use tracing::log;
use crate::config::CONFIG; use crate::config::CONFIG;
@@ -21,6 +22,8 @@ pub async fn download_from_downloader(
CONFIG.downloader_url CONFIG.downloader_url
); );
log::info!("{url}");
let response = reqwest::Client::new() let response = reqwest::Client::new()
.get(url) .get(url)
.header("Authorization", &CONFIG.downloader_api_key) .header("Authorization", &CONFIG.downloader_api_key)

View File

@@ -131,3 +131,9 @@ pub async fn download_from_cache(
caption caption
}) })
} }
pub async fn start_update_cache(
_db: Database
) {
// TODO
}

View File

@@ -6,7 +6,7 @@ use tracing::Level;
use std::sync::Arc; use std::sync::Arc;
use base64::{engine::general_purpose, Engine}; use base64::{engine::general_purpose, Engine};
use crate::{config::CONFIG, db::get_prisma_client, prisma::{PrismaClient, cached_file::{self}}, services::{get_cached_file_or_cache, download_from_cache, download_utils::get_response_async_read}}; use crate::{config::CONFIG, db::get_prisma_client, prisma::{PrismaClient, cached_file::{self}}, services::{get_cached_file_or_cache, download_from_cache, download_utils::get_response_async_read, start_update_cache}};
pub type Database = Arc<PrismaClient>; pub type Database = Arc<PrismaClient>;
@@ -92,9 +92,11 @@ async fn delete_cached_file(
} }
async fn update_cache( async fn update_cache(
_ext: Extension<Ext> Extension(Ext { db, .. }): Extension<Ext>
) -> impl IntoResponse { ) -> impl IntoResponse {
StatusCode::OK.into_response() // TODO tokio::spawn(start_update_cache(db));
StatusCode::OK.into_response()
} }
// //