mirror of
https://github.com/flibusta-apps/books_downloader.git
synced 2025-12-06 06:55:37 +01:00
Fix
This commit is contained in:
18
src/views.rs
18
src/views.rs
@@ -13,6 +13,7 @@ use axum::{
|
|||||||
};
|
};
|
||||||
use axum_prometheus::PrometheusMetricLayer;
|
use axum_prometheus::PrometheusMetricLayer;
|
||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{engine::general_purpose, Engine};
|
||||||
|
use serde_json::json;
|
||||||
use tokio_util::io::ReaderStream;
|
use tokio_util::io::ReaderStream;
|
||||||
use tower_http::trace::{self, TraceLayer};
|
use tower_http::trace::{self, TraceLayer};
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
@@ -70,13 +71,22 @@ pub async fn download(
|
|||||||
Ok((headers, body))
|
Ok((headers, body))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_filename(Path((book_id, file_type)): Path<(u32, String)>) -> (StatusCode, String) {
|
pub async fn get_filename(Path((book_id, file_type)): Path<(u32, String)>) -> impl IntoResponse {
|
||||||
let filename = match get_book(book_id).await {
|
let (filename, filename_ascii) = match get_book(book_id).await {
|
||||||
Ok(book) => get_filename_by_book(&book, file_type.as_str(), false, false),
|
Ok(book) => (
|
||||||
|
get_filename_by_book(&book, file_type.as_str(), false, false),
|
||||||
|
get_filename_by_book(&book, file_type.as_str(), false, true),
|
||||||
|
),
|
||||||
Err(_) => return (StatusCode::BAD_REQUEST, "Book not found!".to_string()),
|
Err(_) => return (StatusCode::BAD_REQUEST, "Book not found!".to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
(StatusCode::OK, filename)
|
(
|
||||||
|
StatusCode::OK,
|
||||||
|
json!({
|
||||||
|
"filename": filename,
|
||||||
|
"filename_ascii": filename_ascii
|
||||||
|
}).to_string()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn auth<B>(req: Request<B>, next: Next<B>) -> Result<Response, StatusCode> {
|
async fn auth<B>(req: Request<B>, next: Next<B>) -> Result<Response, StatusCode> {
|
||||||
|
|||||||
Reference in New Issue
Block a user