Update get cache message request

This commit is contained in:
2024-05-05 13:57:10 +02:00
parent 8c4cad9bff
commit 8cdd365628
4 changed files with 35 additions and 16 deletions

View File

@@ -84,8 +84,9 @@ async fn send_cached_message(
bot: CacheMe<Throttle<Bot>>,
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

View File

@@ -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<CachedMessage, Box<dyn std::error::Error + Send + Sync>> {
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)

View File

@@ -11,6 +11,7 @@ pub mod register;
pub mod strings;
pub mod utils;
pub async fn message_handler(
message: Message,
bot: CacheMe<Throttle<Bot>>,