Skip to content

Commit

Permalink
ignore dmains
Browse files Browse the repository at this point in the history
  • Loading branch information
tikitko committed Nov 27, 2023
1 parent cd41543 commit d3a667a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/handle_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ pub async fn handle_image(
Ok(_) => HttpResponse::MovedPermanently()
.append_header(("Location", extern_path))
.finish(),
Err(_) => HttpResponse::InternalServerError().finish()
Err(_) => HttpResponse::InternalServerError().finish(),
}
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub const LOCAL_IMAGES_STORAGE_PATH: &'static str = env!("LOCAL_IMAGES_STORAGE_P
pub const THUMBNAIL_SMALL_WIDTH: u32 = parse_u32(env!("THUMBNAIL_SMALL_WIDTH")); // 250
pub const THUMBNAIL_MEDIUM_WIDTH: u32 = parse_u32(env!("THUMBNAIL_MEDIUM_WIDTH")); // 750
pub const THUMBNAIL_HEIGHT_MULTIPLIER: u32 = parse_u32(env!("THUMBNAIL_HEIGHT_MULTIPLIER")); // 3
pub const IGNORE_INVALID_CERTS_URLS_PREFIXES_LIST: &'static str =
env!("IGNORE_INVALID_CERTS_URLS_PREFIXES_LIST"); // https://site.com,https://site.ru

// ------------------------------

Expand Down
13 changes: 12 additions & 1 deletion src/process_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,18 @@ pub fn process_images(rx: mpsc::Receiver<(ImageType, String, flume::Sender<Proce
fn download_and_process_image(image_type: &ImageType, base64_url: &String) -> ProcessResult {
let url_vec = general_purpose::URL_SAFE.decode(base64_url)?;
let url = String::from_utf8(url_vec)?;
let res = reqwest::blocking::get(url)?;
let res = {
let urls_prefixes_list: Vec<&str> =
IGNORE_INVALID_CERTS_URLS_PREFIXES_LIST.split(',').collect();
let mut client_builder = reqwest::blocking::Client::builder();
if urls_prefixes_list
.iter()
.any(|&url_prefix| !url_prefix.is_empty() && url.starts_with(url_prefix))
{
client_builder = client_builder.danger_accept_invalid_certs(true);
}
client_builder.build()?.get(url).send()?
};
let bytes = res.bytes()?;
let image = image::load_from_memory(&bytes)?;
let image = image_type.process_image(image);
Expand Down

0 comments on commit d3a667a

Please sign in to comment.