From c8f2cd8b665e82be9dc2e6a2daca9d192e55a415 Mon Sep 17 00:00:00 2001 From: p11 Date: Thu, 29 May 2025 21:15:30 +0200 Subject: [PATCH] Underscore fix for images --- src/main.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 88dcced..85d8094 100644 --- a/src/main.rs +++ b/src/main.rs @@ -330,11 +330,19 @@ fn handle_connection( let mut audio_path = path.clone(); let path = percent_decode_str(relative_path).decode_utf8_lossy(); - if path.contains('_') { - let path = path.replace('_', " "); - let _ = write!(stream, "HTTP/1.1 308 Permanent Redirect\r\n"); - let _ = write!(stream, "Location: /{path}\r\n\r\n"); - return; + if let Some((path, mut file)) = path.rsplit_once('/') { + println!("{path} -> {file}"); + if path.contains('_') { + let path = path.replace('_', " "); + let replaced_file; + if !file.contains('.') { + replaced_file = file.replace('_', " "); + file = &replaced_file; + } + let _ = write!(stream, "HTTP/1.1 308 Permanent Redirect\r\n"); + let _ = write!(stream, "Location: /{path}/{file}\r\n\r\n"); + return; + } } pk_path.push(format!("{path}.pk"));