mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Use x-filename-b64 header
This commit is contained in:
@@ -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,22 +92,14 @@ 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()
|
.unwrap()
|
||||||
.to_str()
|
.to_string();
|
||||||
.unwrap()
|
let caption =
|
||||||
.replace('"', "")
|
std::str::from_utf8(&base64::decode(headers.get("x-caption-b64").unwrap()).unwrap())
|
||||||
.split("filename=")
|
.unwrap()
|
||||||
.collect::<Vec<&str>>()
|
.to_string();
|
||||||
.get(1)
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
let caption = std::str::from_utf8(
|
|
||||||
&base64::decode(headers.get("x-caption-b64").unwrap()).unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
Ok(DownloadFile {
|
Ok(DownloadFile {
|
||||||
response,
|
response,
|
||||||
|
|||||||
Reference in New Issue
Block a user