diff --git a/Cargo.toml b/Cargo.toml index 42d557d..5d8f7f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,31 +6,45 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +once_cell = "1.19.0" + tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] } +tokio-util = { version = "0.7.10", features = ["compat"] } +tokio-stream = "0.1.15" +futures = "0.3.30" + +axum = "0.7.5" +axum-prometheus = "0.6.1" + +tower = "0.4.13" +tower-http = { version = "0.5.2", features = ["trace"] } + +tracing = "0.1.40" +tracing-subscriber = { version = "0.3.18", features = ["env-filter"]} + reqwest = { version = "0.12.4", features = ["json", "stream"] } + serde = { version = "1.0.198", features = ["derive"] } serde_json = "1.0.116" + teloxide = { version = "0.12.2", features = ["macros", "webhooks-axum", "cache-me", "throttle"] } + url = "2.5.0" + ctrlc = { version = "3.4.4", features = ["termination"] } + strum = "0.26.2" strum_macros = "0.26.2" -futures = "0.3.30" + base64 = "0.22.0" -tokio-util = { version = "0.7.10", features = ["compat"] } textwrap = "0.16.1" regex = "1.10.4" chrono = "0.4.38" dateparser = "0.2.1" -sentry = { version = "0.32.3", features = ["debug-images"] } -moka = { version = "0.12.7", features = ["future"] } -axum = "0.7.5" + smallvec = { version = "1.13.2", features = ["serde"] } smartstring = { version = "1.0.1", features = ["serde"] } -tokio-stream = "0.1.15" -tracing = "0.1.40" -tracing-subscriber = { version = "0.3.18", features = ["env-filter"]} -tower = "0.4.13" -tower-http = { version = "0.5.2", features = ["trace"] } -once_cell = "1.19.0" -axum-prometheus = "0.6.1" + +moka = { version = "0.12.7", features = ["future"] } + +sentry = { version = "0.32.3", features = ["debug-images"] } diff --git a/src/bots/approved_bot/modules/download/mod.rs b/src/bots/approved_bot/modules/download/mod.rs index 0fc1144..95ddd9d 100644 --- a/src/bots/approved_bot/modules/download/mod.rs +++ b/src/bots/approved_bot/modules/download/mod.rs @@ -84,8 +84,9 @@ async fn send_cached_message( bot: CacheMe>, download_data: DownloadQueryData, need_delete_message: bool, + cache: BotCache, ) -> BotHandlerInternal { - if let Ok(v) = get_cached_message(&download_data).await { + if let Ok(v) = get_cached_message(&download_data, cache).await { if _send_cached(&message, &bot, v).await.is_ok() { if need_delete_message { bot.delete_message(message.chat.id, message.id).await?; @@ -206,7 +207,7 @@ async fn download_handler( ) -> BotHandlerInternal { match cache { BotCache::Original => { - send_cached_message(message, bot, download_data, need_delete_message).await + send_cached_message(message, bot, download_data, need_delete_message, cache).await } BotCache::NoCache => { send_with_download_from_channel(message, bot, download_data, need_delete_message).await diff --git a/src/bots/approved_bot/services/book_cache/mod.rs b/src/bots/approved_bot/services/book_cache/mod.rs index a065912..e8d1393 100644 --- a/src/bots/approved_bot/services/book_cache/mod.rs +++ b/src/bots/approved_bot/services/book_cache/mod.rs @@ -2,7 +2,7 @@ use base64::{engine::general_purpose, Engine}; use reqwest::StatusCode; use std::fmt; -use crate::{bots::approved_bot::modules::download::callback_data::DownloadQueryData, config}; +use crate::{bots::approved_bot::modules::download::callback_data::DownloadQueryData, bots_manager::BotCache, config}; use self::types::{CachedMessage, DownloadFile, DownloadLink}; @@ -23,16 +23,19 @@ impl std::error::Error for DownloadError {} pub async fn get_cached_message( download_data: &DownloadQueryData, + bot_cache: BotCache, ) -> Result> { let DownloadQueryData::DownloadData { book_id: id, file_type: format, } = download_data; + let is_need_copy = bot_cache != BotCache::Original; + let client = reqwest::Client::new(); let response = client .get(format!( - "{}/api/v1/{id}/{format}/", + "{}/api/v1/{id}/{format}/?copy={is_need_copy}", &config::CONFIG.cache_server_url )) .header("Authorization", &config::CONFIG.cache_server_api_key) diff --git a/src/bots/bots_manager/mod.rs b/src/bots/bots_manager/mod.rs index 0068ffe..a540b00 100644 --- a/src/bots/bots_manager/mod.rs +++ b/src/bots/bots_manager/mod.rs @@ -11,6 +11,7 @@ pub mod register; pub mod strings; pub mod utils; + pub async fn message_handler( message: Message, bot: CacheMe>,