mirror of
https://github.com/flibusta-apps/telegram_files_server.git
synced 2025-12-06 12:35:39 +01:00
Ignore teloxide::ApiError::MessageToForwardNotFound
This commit is contained in:
@@ -69,7 +69,7 @@ pub async fn upload_file(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn download_file(chat_id: i64, message_id: i32) -> Result<File, Box<dyn Error>> {
|
||||
pub async fn download_file(chat_id: i64, message_id: i32) -> Result<Option<File>, Box<dyn Error>> {
|
||||
let bot = ROUND_ROBIN_BOT.get_bot();
|
||||
|
||||
let forwarded_message = match bot
|
||||
@@ -82,6 +82,12 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result<File, Box<dy
|
||||
{
|
||||
Ok(v) => v,
|
||||
Err(err) => {
|
||||
if let teloxide::RequestError::Api(ref err) = err {
|
||||
if let teloxide::ApiError::MessageToForwardNotFound = err {
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
|
||||
log::error!("Error: {}", err);
|
||||
return Err(Box::new(err));
|
||||
}
|
||||
@@ -99,5 +105,5 @@ pub async fn download_file(chat_id: i64, message_id: i32) -> Result<File, Box<dy
|
||||
}
|
||||
};
|
||||
|
||||
Ok(File::open(path).await?)
|
||||
Ok(Some(File::open(path).await?))
|
||||
}
|
||||
@@ -91,12 +91,17 @@ async fn upload(data: TypedMultipart<UploadFileRequest>) -> impl IntoResponse {
|
||||
|
||||
async fn download(Path((chat_id, message_id)): Path<(i64, i32)>) -> impl IntoResponse {
|
||||
let file = match download_file(chat_id, message_id).await {
|
||||
Ok(v) => v,
|
||||
Ok(v) => {
|
||||
match v {
|
||||
Some(v) => v,
|
||||
None => return StatusCode::BAD_REQUEST.into_response(),
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
log::error!("{}", err);
|
||||
return StatusCode::BAD_REQUEST.into_response()
|
||||
}
|
||||
} ;
|
||||
};
|
||||
|
||||
let reader = ReaderStream::new(file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user