Compare commits

...

2 Commits

Author SHA1 Message Date
Simon
1f99eec5a3 fix 2 electric boogaloo 2026-03-16 00:16:07 +00:00
Simon
448efeff1e hanime thumbnail fix 2026-03-15 23:47:32 +00:00

View File

@@ -6,12 +6,24 @@ use ntex::{
use crate::util::requester::Requester;
fn normalize_image_url(endpoint: &str) -> String {
let endpoint = endpoint.trim_start_matches('/');
println!("Normalizing image URL: {endpoint}");
if endpoint.starts_with("http://") || endpoint.starts_with("https://") {
endpoint.to_string()
} else if endpoint.starts_with("hanime-cdn.com/") || endpoint == "hanime-cdn.com" {
format!("https://{endpoint}")
} else {
format!("https://{endpoint}")
}
}
pub async fn get_image(
req: HttpRequest,
requester: web::types::State<Requester>,
) -> Result<impl web::Responder, web::Error> {
let endpoint = req.match_info().query("endpoint").to_string();
let image_url = format!("https://hanime-cdn.com/{}", endpoint);
let image_url = normalize_image_url(&endpoint);
let upstream = match requester
.get_ref()
@@ -52,3 +64,24 @@ pub async fn get_image(
// ...or simple & compatible:
Ok(resp.body(bytes.to_vec()))
}
#[cfg(test)]
mod tests {
use super::normalize_image_url;
#[test]
fn keeps_full_hanime_cdn_host_path_without_duplication() {
assert_eq!(
normalize_image_url("hanime-cdn.com/images/covers/natsu-zuma-2-cv1.png"),
"https://hanime-cdn.com/images/covers/natsu-zuma-2-cv1.png"
);
}
#[test]
fn prefixes_relative_paths_with_hanime_cdn_host() {
assert_eq!(
normalize_image_url("/images/covers/natsu-zuma-2-cv1.png"),
"https://hanime-cdn.com/images/covers/natsu-zuma-2-cv1.png"
);
}
}