mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Update get cache message request
This commit is contained in:
38
Cargo.toml
38
Cargo.toml
@@ -6,31 +6,45 @@ 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]
|
||||||
|
once_cell = "1.19.0"
|
||||||
|
|
||||||
tokio = { version = "1.37.0", features = ["rt-multi-thread", "macros"] }
|
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"] }
|
reqwest = { version = "0.12.4", features = ["json", "stream"] }
|
||||||
|
|
||||||
serde = { version = "1.0.198", features = ["derive"] }
|
serde = { version = "1.0.198", features = ["derive"] }
|
||||||
serde_json = "1.0.116"
|
serde_json = "1.0.116"
|
||||||
|
|
||||||
teloxide = { version = "0.12.2", features = ["macros", "webhooks-axum", "cache-me", "throttle"] }
|
teloxide = { version = "0.12.2", features = ["macros", "webhooks-axum", "cache-me", "throttle"] }
|
||||||
|
|
||||||
url = "2.5.0"
|
url = "2.5.0"
|
||||||
|
|
||||||
ctrlc = { version = "3.4.4", features = ["termination"] }
|
ctrlc = { version = "3.4.4", features = ["termination"] }
|
||||||
|
|
||||||
strum = "0.26.2"
|
strum = "0.26.2"
|
||||||
strum_macros = "0.26.2"
|
strum_macros = "0.26.2"
|
||||||
futures = "0.3.30"
|
|
||||||
base64 = "0.22.0"
|
base64 = "0.22.0"
|
||||||
tokio-util = { version = "0.7.10", features = ["compat"] }
|
|
||||||
textwrap = "0.16.1"
|
textwrap = "0.16.1"
|
||||||
regex = "1.10.4"
|
regex = "1.10.4"
|
||||||
chrono = "0.4.38"
|
chrono = "0.4.38"
|
||||||
dateparser = "0.2.1"
|
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"] }
|
smallvec = { version = "1.13.2", features = ["serde"] }
|
||||||
smartstring = { version = "1.0.1", features = ["serde"] }
|
smartstring = { version = "1.0.1", features = ["serde"] }
|
||||||
tokio-stream = "0.1.15"
|
|
||||||
tracing = "0.1.40"
|
moka = { version = "0.12.7", features = ["future"] }
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"]}
|
|
||||||
tower = "0.4.13"
|
sentry = { version = "0.32.3", features = ["debug-images"] }
|
||||||
tower-http = { version = "0.5.2", features = ["trace"] }
|
|
||||||
once_cell = "1.19.0"
|
|
||||||
axum-prometheus = "0.6.1"
|
|
||||||
|
|||||||
@@ -84,8 +84,9 @@ async fn send_cached_message(
|
|||||||
bot: CacheMe<Throttle<Bot>>,
|
bot: CacheMe<Throttle<Bot>>,
|
||||||
download_data: DownloadQueryData,
|
download_data: DownloadQueryData,
|
||||||
need_delete_message: bool,
|
need_delete_message: bool,
|
||||||
|
cache: BotCache,
|
||||||
) -> BotHandlerInternal {
|
) -> 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 _send_cached(&message, &bot, v).await.is_ok() {
|
||||||
if need_delete_message {
|
if need_delete_message {
|
||||||
bot.delete_message(message.chat.id, message.id).await?;
|
bot.delete_message(message.chat.id, message.id).await?;
|
||||||
@@ -206,7 +207,7 @@ async fn download_handler(
|
|||||||
) -> BotHandlerInternal {
|
) -> BotHandlerInternal {
|
||||||
match cache {
|
match cache {
|
||||||
BotCache::Original => {
|
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 => {
|
BotCache::NoCache => {
|
||||||
send_with_download_from_channel(message, bot, download_data, need_delete_message).await
|
send_with_download_from_channel(message, bot, download_data, need_delete_message).await
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use base64::{engine::general_purpose, Engine};
|
|||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
use std::fmt;
|
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};
|
use self::types::{CachedMessage, DownloadFile, DownloadLink};
|
||||||
|
|
||||||
@@ -23,16 +23,19 @@ impl std::error::Error for DownloadError {}
|
|||||||
|
|
||||||
pub async fn get_cached_message(
|
pub async fn get_cached_message(
|
||||||
download_data: &DownloadQueryData,
|
download_data: &DownloadQueryData,
|
||||||
|
bot_cache: BotCache,
|
||||||
) -> Result<CachedMessage, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<CachedMessage, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let DownloadQueryData::DownloadData {
|
let DownloadQueryData::DownloadData {
|
||||||
book_id: id,
|
book_id: id,
|
||||||
file_type: format,
|
file_type: format,
|
||||||
} = download_data;
|
} = download_data;
|
||||||
|
|
||||||
|
let is_need_copy = bot_cache != BotCache::Original;
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let response = client
|
let response = client
|
||||||
.get(format!(
|
.get(format!(
|
||||||
"{}/api/v1/{id}/{format}/",
|
"{}/api/v1/{id}/{format}/?copy={is_need_copy}",
|
||||||
&config::CONFIG.cache_server_url
|
&config::CONFIG.cache_server_url
|
||||||
))
|
))
|
||||||
.header("Authorization", &config::CONFIG.cache_server_api_key)
|
.header("Authorization", &config::CONFIG.cache_server_api_key)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ pub mod register;
|
|||||||
pub mod strings;
|
pub mod strings;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
|
|
||||||
pub async fn message_handler(
|
pub async fn message_handler(
|
||||||
message: Message,
|
message: Message,
|
||||||
bot: CacheMe<Throttle<Bot>>,
|
bot: CacheMe<Throttle<Bot>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user