Use x-filename-b64 header

This commit is contained in:
2023-01-19 18:05:18 +01:00
parent 4417deff43
commit da80067401

View File

@@ -1,5 +1,5 @@
use std::fmt;
use reqwest::StatusCode; use reqwest::StatusCode;
use std::fmt;
use crate::{bots::approved_bot::modules::download::DownloadData, config}; use crate::{bots::approved_bot::modules::download::DownloadData, config};
@@ -9,7 +9,7 @@ pub mod types;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct DownloadError { struct DownloadError {
status_code: StatusCode status_code: StatusCode,
} }
impl fmt::Display for DownloadError { impl fmt::Display for DownloadError {
@@ -47,7 +47,7 @@ pub async fn get_cached_message(
if response.status() != StatusCode::OK { if response.status() != StatusCode::OK {
return Err(Box::new(DownloadError { 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 { if response.status() != StatusCode::OK {
return Err(Box::new(DownloadError { return Err(Box::new(DownloadError {
status_code: response.status() status_code: response.status(),
})); }));
}; };
@@ -92,20 +92,12 @@ pub async fn download_file(
log::info!("{:?}", headers); log::info!("{:?}", headers);
let filename = headers let filename =
.get("content-disposition") std::str::from_utf8(&base64::decode(headers.get("x-filename-b64").unwrap()).unwrap())
.unwrap()
.to_str()
.unwrap()
.replace('"', "")
.split("filename=")
.collect::<Vec<&str>>()
.get(1)
.unwrap() .unwrap()
.to_string(); .to_string();
let caption = std::str::from_utf8( let caption =
&base64::decode(headers.get("x-caption-b64").unwrap()).unwrap(), std::str::from_utf8(&base64::decode(headers.get("x-caption-b64").unwrap()).unwrap())
)
.unwrap() .unwrap()
.to_string(); .to_string();