Fix hanime-cdn relative path prefixing and stale vidara test

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MUYdCh2nCVsQYgJAT7gwSi
This commit is contained in:
Simon
2026-10-10 09:36:13 +00:00
parent 5a0fb649ee
commit 40eab41b2b
2 changed files with 17 additions and 4 deletions

View File

@@ -12,8 +12,16 @@ fn normalize_image_url(endpoint: &str) -> String {
endpoint.to_string()
} else if endpoint.starts_with("hanime-cdn.com/") || endpoint == "hanime-cdn.com" {
format!("https://{endpoint}")
} else {
} else if endpoint
.split('/')
.next()
.is_some_and(|first| first.contains('.'))
{
// `other-host.tld/path`: the caller already supplied a host.
format!("https://{endpoint}")
} else {
// Site-relative path such as `images/covers/x.png`.
format!("https://hanime-cdn.com/{endpoint}")
}
}

View File

@@ -116,9 +116,14 @@ mod tests {
#[test]
fn normalizes_detail_request_with_path_only() {
let (url, video_id) = VidaraProxy::normalize_detail_request("video/1000/demo")
let (url, video_id) = VidaraProxy::normalize_detail_request("v/eJ9O4QqG1Ln2")
.expect("detail request should parse");
assert_eq!(url, "https://vidara.so/video/1000/demo");
assert_eq!(video_id, "1000");
assert_eq!(url, "https://vidara.so/v/eJ9O4QqG1Ln2");
assert_eq!(video_id, "eJ9O4QqG1Ln2");
}
#[test]
fn rejects_paths_outside_the_embed_route() {
assert!(VidaraProxy::normalize_detail_request("video/1000/demo").is_none());
}
}