mirror of
https://github.com/flibusta-apps/fb2converter_server.git
synced 2025-12-06 15:05:37 +01:00
Update deps
This commit is contained in:
509
Cargo.lock
generated
509
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
@@ -6,20 +6,20 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.33.0", features = ["full"] }
|
tokio = { version = "1.35.0", features = ["full"] }
|
||||||
tokio-util = { version = "0.7.10", features = ["compat", "io"] }
|
tokio-util = { version = "0.7.10", features = ["compat", "io"] }
|
||||||
futures-util = "0.3.29"
|
futures-util = "0.3.29"
|
||||||
|
|
||||||
axum = { version = "0.6.20", features = ["multipart"] }
|
axum = { version = "0.7.2", features = ["multipart"] }
|
||||||
axum-prometheus = "0.4.0"
|
axum-prometheus = "0.5.0"
|
||||||
|
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"]}
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"]}
|
||||||
tower-http = { version = "0.4.4", features = ["trace"] }
|
tower-http = { version = "0.5.0", features = ["trace"] }
|
||||||
|
|
||||||
async-tempfile = "0.4.0"
|
async-tempfile = "0.5.0"
|
||||||
uuid = "1.5.0"
|
uuid = "1.6.1"
|
||||||
|
|
||||||
sentry = { version = "0.31.7", features = ["debug-images"] }
|
sentry = { version = "0.32.0", features = ["debug-images"] }
|
||||||
|
|
||||||
tokio-cron-scheduler = "0.9.4"
|
tokio-cron-scheduler = "0.9.4"
|
||||||
|
|||||||
24
src/main.rs
24
src/main.rs
@@ -1,7 +1,7 @@
|
|||||||
use async_tempfile::TempFile;
|
use async_tempfile::TempFile;
|
||||||
use axum::{
|
use axum::{
|
||||||
body::StreamBody,
|
body::Body,
|
||||||
extract::{BodyStream, Path},
|
extract::Path,
|
||||||
http::{self, header, Request, StatusCode},
|
http::{self, header, Request, StatusCode},
|
||||||
middleware::{self, Next},
|
middleware::{self, Next},
|
||||||
response::{AppendHeaders, IntoResponse, Response},
|
response::{AppendHeaders, IntoResponse, Response},
|
||||||
@@ -38,10 +38,7 @@ async fn remove_temp_files() -> Result<(), Box<dyn std::error::Error + Send + Sy
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn convert_file(
|
async fn convert_file(Path(file_format): Path<String>, body: Body) -> impl IntoResponse {
|
||||||
Path(file_format): Path<String>,
|
|
||||||
mut stream: BodyStream,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let prefix = uuid::Uuid::new_v4().to_string();
|
let prefix = uuid::Uuid::new_v4().to_string();
|
||||||
|
|
||||||
let tempfile = match TempFile::new_with_name(format!("{prefix}.fb2")).await {
|
let tempfile = match TempFile::new_with_name(format!("{prefix}.fb2")).await {
|
||||||
@@ -60,7 +57,9 @@ async fn convert_file(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
while let Some(chunk) = stream.next().await {
|
let mut data_stream = body.into_data_stream();
|
||||||
|
|
||||||
|
while let Some(chunk) = data_stream.next().await {
|
||||||
let data = match chunk {
|
let data = match chunk {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -118,14 +117,13 @@ async fn convert_file(
|
|||||||
let _ = result_file.seek(SeekFrom::Start(0)).await;
|
let _ = result_file.seek(SeekFrom::Start(0)).await;
|
||||||
|
|
||||||
let stream = ReaderStream::new(result_file);
|
let stream = ReaderStream::new(result_file);
|
||||||
let body = StreamBody::new(stream);
|
|
||||||
|
|
||||||
let headers = AppendHeaders([(header::CONTENT_LENGTH, content_len)]);
|
let headers = AppendHeaders([(header::CONTENT_LENGTH, content_len)]);
|
||||||
|
|
||||||
(headers, body).into_response()
|
(headers, Body::from_stream(stream)).into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn auth<B>(req: Request<B>, next: Next<B>) -> Result<Response, StatusCode> {
|
async fn auth(req: Request<axum::body::Body>, next: Next) -> Result<Response, StatusCode> {
|
||||||
let auth_header = req
|
let auth_header = req
|
||||||
.headers()
|
.headers()
|
||||||
.get(http::header::AUTHORIZATION)
|
.get(http::header::AUTHORIZATION)
|
||||||
@@ -200,10 +198,8 @@ async fn start_app() {
|
|||||||
let app = get_router();
|
let app = get_router();
|
||||||
|
|
||||||
info!("Start webserver...");
|
info!("Start webserver...");
|
||||||
axum::Server::bind(&addr)
|
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
||||||
.serve(app.into_make_service())
|
axum::serve(listener, app).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
info!("Webserver shutdown...");
|
info!("Webserver shutdown...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user