From da800674016b72efaf08386ac02373f55a88d5e5 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Thu, 19 Jan 2023 18:05:18 +0100 Subject: [PATCH] Use x-filename-b64 header --- .../approved_bot/services/book_cache/mod.rs | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/bots/approved_bot/services/book_cache/mod.rs b/src/bots/approved_bot/services/book_cache/mod.rs index b179335..c0d1066 100644 --- a/src/bots/approved_bot/services/book_cache/mod.rs +++ b/src/bots/approved_bot/services/book_cache/mod.rs @@ -1,5 +1,5 @@ -use std::fmt; use reqwest::StatusCode; +use std::fmt; use crate::{bots::approved_bot::modules::download::DownloadData, config}; @@ -9,7 +9,7 @@ pub mod types; #[derive(Debug, Clone)] struct DownloadError { - status_code: StatusCode + status_code: StatusCode, } impl fmt::Display for DownloadError { @@ -47,7 +47,7 @@ pub async fn get_cached_message( if response.status() != StatusCode::OK { return Err(Box::new(DownloadError { - status_code: response.status() + status_code: response.status(), })); }; @@ -84,7 +84,7 @@ pub async fn download_file( if response.status() != StatusCode::OK { return Err(Box::new(DownloadError { - status_code: response.status() + status_code: response.status(), })); }; @@ -92,22 +92,14 @@ pub async fn download_file( log::info!("{:?}", headers); - let filename = headers - .get("content-disposition") - .unwrap() - .to_str() - .unwrap() - .replace('"', "") - .split("filename=") - .collect::>() - .get(1) - .unwrap() - .to_string(); - let caption = std::str::from_utf8( - &base64::decode(headers.get("x-caption-b64").unwrap()).unwrap(), - ) - .unwrap() - .to_string(); + let filename = + std::str::from_utf8(&base64::decode(headers.get("x-filename-b64").unwrap()).unwrap()) + .unwrap() + .to_string(); + let caption = + std::str::from_utf8(&base64::decode(headers.get("x-caption-b64").unwrap()).unwrap()) + .unwrap() + .to_string(); Ok(DownloadFile { response,